Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eaf14aa

Browse files
Follow up 944: authentication sessions are not persistent (#1003)
* #944: Fixed auth. sessions not persistent * 944: Prevent race conditions setting authOptions * typo correction, duplicate identifier * prevent block of auth client service on setOptions * consider windows cred. mgr. password len limit
1 parent a59e0da commit eaf14aa

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

‎arduino-ide-extension/src/browser/auth/authentication-client-service.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ export class AuthenticationClientService
4343

4444
readonly onSessionDidChange = this.onSessionDidChangeEmitter.event;
4545

46-
onStart(): void {
46+
asynconStart(): 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+
this.setOptions().then(() => this.service.initAuthSession());
5554

5655
this.arduinoPreferences.onPreferenceChanged((event) => {
5756
if (event.preferenceName.startsWith('arduino.auth.')) {
@@ -60,8 +59,8 @@ export class AuthenticationClientService
6059
});
6160
}
6261

63-
setOptions(): void {
64-
this.service.setOptions({
62+
setOptions(): Promise<void> {
63+
returnthis.service.setOptions({
6564
redirectUri: `http://localhost:${serverPort}/callback`,
6665
responseType: 'code',
6766
clientID: this.arduinoPreferences['arduino.auth.clientID'],

‎arduino-ide-extension/src/common/protocol/authentication-service.ts‎

Lines changed: 1 addition & 1 deletion
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

‎arduino-ide-extension/src/node/auth/arduino-auth-provider.ts‎

Lines changed: 1 addition & 1 deletion
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 asyncsetOptions(authOptions: AuthOptions): Promise<void> {
9393
this.authOptions = authOptions;
9494
}
9595

‎arduino-ide-extension/src/node/auth/authentication-service-impl.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class AuthenticationServiceImpl
2020
protected readonly clients: AuthenticationServiceClient[] = [];
2121
protected readonly toDispose = new DisposableCollection();
2222

23-
private initialized = false;
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+
returnthis.delegate.setOptions(authOptions);
5858
}
5959

6060
async login(): Promise<AuthenticationSession> {

‎arduino-ide-extension/src/node/auth/keychain.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export class Keychain {
4747
return false;
4848
}
4949
try {
50+
const stringifiedTokenLength = stringifiedToken.length;
51+
const tokenLengthNotSupported =
52+
stringifiedTokenLength > 2500 && process.platform === 'win32';
53+
54+
if (tokenLengthNotSupported) {
55+
// TODO manage this specific error appropriately
56+
return false;
57+
}
58+
5059
await keytar.setPassword(
5160
this.credentialsSection,
5261
this.account,

‎arduino-ide-extension/src/node/auth/utils.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ export function token2IToken(token: Token): IToken {
4444
(token.id_token && jwt_decode(token.id_token)) || {};
4545

4646
return {
47-
idToken: token.id_token,
47+
/*
48+
* ".id_token" is already decoded for account details above
49+
* so we probably don't need to keep it around as "idToken".
50+
* If we do, and subsequently try to store it with
51+
* Windows Credential Manager (WCM) it's probable we'll
52+
* exceed WCMs' 2500 password character limit breaking
53+
* our auth functionality
54+
*/
55+
// ! idToken: token.id_token,
4856
expiresIn: token.expires_in,
4957
expiresAt: token.expires_in
5058
? Date.now() + token.expires_in * 1000

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /