Skip to content

Commit 0a7dbcc

Browse files
944: Prevent race conditions setting authOptions
1 parent ff13922 commit 0a7dbcc

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

Diff for: arduino-ide-extension/src/browser/auth/authentication-client-service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ export class AuthenticationClientService
4343

4444
readonly onSessionDidChange = this.onSessionDidChangeEmitter.event;
4545

46-
onStart(): void {
46+
async onStart(): Promise<void> {
4747
this.toDispose.push(this.onSessionDidChangeEmitter);
4848
this.service.setClient(this);
4949
this.service
5050
.session()
5151
.then((session) => this.notifySessionDidChange(session));
5252

53-
this.setOptions();
54-
this.service.initAuthSession()
53+
await this.setOptions();
54+
this.service.initAuthSession();
5555

5656
this.arduinoPreferences.onPreferenceChanged((event) => {
5757
if (event.preferenceName.startsWith('arduino.auth.')) {
@@ -60,8 +60,8 @@ export class AuthenticationClientService
6060
});
6161
}
6262

63-
setOptions(): void {
64-
this.service.setOptions({
63+
setOptions(): Promise<void> {
64+
return this.service.setOptions({
6565
redirectUri: `http://localhost:${serverPort}/callback`,
6666
responseType: 'code',
6767
clientID: this.arduinoPreferences['arduino.auth.clientID'],

Diff for: arduino-ide-extension/src/common/protocol/authentication-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface AuthenticationService
2222
logout(): Promise<void>;
2323
session(): Promise<AuthenticationSession | undefined>;
2424
disposeClient(client: AuthenticationServiceClient): void;
25-
setOptions(authOptions: AuthOptions): void;
25+
setOptions(authOptions: AuthOptions): Promise<void>;
2626
initAuthSession(): Promise<void>;
2727
}
2828

Diff for: arduino-ide-extension/src/node/auth/arduino-auth-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ArduinoAuthenticationProvider implements AuthenticationProvider {
8989
setInterval(checkToken, REFRESH_INTERVAL);
9090
}
9191

92-
public setOptions(authOptions: AuthOptions) {
92+
public async setOptions(authOptions: AuthOptions): Promise<void> {
9393
this.authOptions = authOptions;
9494
}
9595

Diff for: arduino-ide-extension/src/node/auth/authentication-service-impl.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class AuthenticationServiceImpl
1919
protected readonly delegate = new ArduinoAuthenticationProvider();
2020
protected readonly clients: AuthenticationServiceClient[] = [];
2121
protected readonly toDispose = new DisposableCollection();
22-
23-
private initialized = false;
22+
23+
private initialized = false;
2424

2525
async onStart(): Promise<void> {
2626
this.toDispose.pushAll([
@@ -49,12 +49,12 @@ export class AuthenticationServiceImpl
4949
async initAuthSession(): Promise<void> {
5050
if (!this.initialized) {
5151
await this.delegate.init();
52-
this.initialized = true
52+
this.initialized = true;
5353
}
5454
}
5555

56-
setOptions(authOptions: AuthOptions) {
57-
this.delegate.setOptions(authOptions);
56+
setOptions(authOptions: AuthOptions): Promise<void> {
57+
return this.delegate.setOptions(authOptions);
5858
}
5959

6060
async login(): Promise<AuthenticationSession> {

0 commit comments

Comments
 (0)