Skip to content

#944: Fixed auth. sessions not persistent #992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class AuthenticationClientService
this.service
.session()
.then((session) => this.notifySessionDidChange(session));

this.setOptions();
this.service.initAuthSession()
Copy link
Contributor

@kittaakos kittaakos May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, above this initAuthSession call, the setOptions is a void, hence notification. It's a "fire and forget" event, so by the time you call initAutSession it is not ensured that the options were set or arrived at all.

In the long run, we have to change all similar calls from foo(arg: any): void to foo(arg: any): Promise<void>, and change the code from this

this.setOptions();
this.service.initAuthSession()

to this:

await this.setOptions();
this.service.initAuthSession()

//CC @fstasi, @AlbyIanna, @davegarthsimpson, and @francescospissu


this.arduinoPreferences.onPreferenceChanged((event) => {
if (event.preferenceName.startsWith('arduino.auth.')) {
this.setOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface AuthenticationService
session(): Promise<AuthenticationSession | undefined>;
disposeClient(client: AuthenticationServiceClient): void;
setOptions(authOptions: AuthOptions): void;
initAuthSession(): Promise<void>;
}

export interface AuthenticationServiceClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class AuthenticationServiceImpl
protected readonly delegate = new ArduinoAuthenticationProvider();
protected readonly clients: AuthenticationServiceClient[] = [];
protected readonly toDispose = new DisposableCollection();

private initialized = false;

async onStart(): Promise<void> {
this.toDispose.pushAll([
Expand All @@ -42,7 +44,13 @@ export class AuthenticationServiceImpl
this.clients.forEach((client) => this.disposeClient(client))
),
]);
await this.delegate.init();
}

async initAuthSession(): Promise<void> {
if (!this.initialized) {
await this.delegate.init();
this.initialized = true
}
}

setOptions(authOptions: AuthOptions) {
Expand Down