diff --git a/extensions/microsoft-authentication/src/AADHelper.ts b/extensions/microsoft-authentication/src/AADHelper.ts index 72408f855a19b..b38bd63f80d98 100644 --- a/extensions/microsoft-authentication/src/AADHelper.ts +++ b/extensions/microsoft-authentication/src/AADHelper.ts @@ -203,6 +203,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(' '), @@ -410,14 +416,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 { @@ -429,7 +435,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 || ''))}` } };