From 5ea92ff53559fe771885a80c568aaf1911af3df2 Mon Sep 17 00:00:00 2001 From: Yash Goel <58719389+Yash621@users.noreply.github.com> Date: Wed, 9 Feb 2022 01:44:52 +0530 Subject: [PATCH] fixed settings sync has duplicate logins (#142340) * added check and swaped logic * improved label for usename * fixed eslint issues * updated text --- .../microsoft-authentication/src/AADHelper.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extensions/microsoft-authentication/src/AADHelper.ts b/extensions/microsoft-authentication/src/AADHelper.ts index 6b7d1a85131..4a6f296cc10 100644 --- a/extensions/microsoft-authentication/src/AADHelper.ts +++ b/extensions/microsoft-authentication/src/AADHelper.ts @@ -204,6 +204,12 @@ export class AzureActiveDirectoryService { } public createSession(scopes: string[]): Promise { + if (!scopes.includes('openid')) { + scopes.push('openid'); + } + if (!scopes.includes('email')) { + scopes.push('email'); + } const scopeData: IScopeData = { scopes, scopeStr: scopes.join(' '), @@ -390,14 +396,14 @@ export class AzureActiveDirectoryService { let claims = undefined; try { - claims = JSON.parse(Buffer.from(json.access_token.split('.')[1], 'base64').toString()); - } catch (e) { if (json.id_token) { Logger.info('Attempting to parse id_token instead since access_token was not parsable'); claims = JSON.parse(Buffer.from(json.id_token.split('.')[1], 'base64').toString()); } else { - throw e; + claims = JSON.parse(Buffer.from(json.access_token.split('.')[1], 'base64').toString()); } + } catch (e) { + throw e; } return { @@ -409,7 +415,7 @@ export class AzureActiveDirectoryService { scope: scopeData.scopeStr, sessionId: existingId || `${claims.tid}/${(claims.oid || (claims.altsecid || '' + claims.ipd || ''))}/${uuid()}`, account: { - label: claims.email || claims.unique_name || claims.preferred_username || 'user@example.com', + label: `${claims.name} - ${claims.email}` || claims.email || claims.unique_name || claims.preferred_username || 'user@example.com', id: `${claims.tid}/${(claims.oid || (claims.altsecid || '' + claims.ipd || ''))}` } };