Skip to content
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

Use email for label & use label to group results in Account menu #193727

Merged
merged 1 commit into from
Sep 21, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 1 addition & 8 deletions extensions/microsoft-authentication/src/AADHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,6 @@ export class AzureActiveDirectoryService {
throw e;
}

let label;
if (claims.name && claims.email) {
label = `${claims.name} - ${claims.email}`;
} else {
label = claims.email ?? claims.unique_name ?? claims.preferred_username ?? 'user@example.com';
}

const id = `${claims.tid}/${(claims.oid ?? (claims.altsecid ?? '' + claims.ipd ?? ''))}`;
const sessionId = existingId || `${id}/${randomUUID()}`;
this._logger.trace(`[${scopeData.scopeStr}] '${sessionId}' Token response parsed successfully.`);
Expand All @@ -543,7 +536,7 @@ export class AzureActiveDirectoryService {
scope: scopeData.scopeStr,
sessionId,
account: {
label,
label: claims.email ?? claims.preferred_username ?? claims.unique_name ?? 'user@example.com',
id,
type: claims.tid === MSA_TID || claims.tid === MSA_PASSTHRU_TID ? MicrosoftAccountType.MSA : MicrosoftAccountType.AAD
}
Expand Down
45 changes: 23 additions & 22 deletions src/vs/workbench/browser/parts/activitybar/activitybarActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
if (account.canSignOut) {
const signOutAction = disposables.add(new Action('signOut', localize('signOut', "Sign Out"), undefined, true, async () => {
const allSessions = await this.authenticationService.getSessions(providerId);
const sessionsForAccount = allSessions.filter(s => s.account.id === account.id);
const sessionsForAccount = allSessions.filter(s => s.account.label === account.label);
return await this.authenticationService.removeAccountSessions(providerId, account.label, sessionsForAccount);
}));
providerSubMenuActions.push(signOutAction);
Expand Down Expand Up @@ -399,34 +399,35 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {

private async addOrUpdateAccount(providerId: string, account: AuthenticationSessionAccount): Promise<void> {
let accounts = this.groupedAccounts.get(providerId);
if (accounts) {
const existingAccount = accounts.find(a => a.id === account.id);
if (existingAccount) {
// Update the label if it has changed
if (existingAccount.label !== account.label) {
existingAccount.label = account.label;
}
return;
}
} else {
if (!accounts) {
accounts = [];
this.groupedAccounts.set(providerId, accounts);
}

const sessionFromEmbedder = await this.sessionFromEmbedder.value;
// If the session stored from the embedder allows sign out, then we can treat it and all others as sign out-able
let canSignOut = !!sessionFromEmbedder?.canSignOut;
if (!canSignOut) {
if (sessionFromEmbedder?.id) {
const sessions = (await this.authenticationService.getSessions(providerId)).filter(s => s.account.id === account.id);
canSignOut = !sessions.some(s => s.id === sessionFromEmbedder.id);
} else {
// The default if we don't have a session from the embedder is to allow sign out
canSignOut = true;
}
let canSignOut = true;
if (
sessionFromEmbedder // if we have a session from the embedder
&& !sessionFromEmbedder.canSignOut // and that session says we can't sign out
&& (await this.authenticationService.getSessions(providerId)) // and that session is associated with the account we are adding/updating
.some(s =>
s.id === sessionFromEmbedder.id
&& s.account.id === account.id
)
) {
canSignOut = false;
}

accounts.push({ ...account, canSignOut });
const existingAccount = accounts.find(a => a.label === account.label);
if (existingAccount) {
// if we have an existing account and we discover that we
// can't sign out of it, update the account to mark it as "can't sign out"
if (!canSignOut) {
existingAccount.canSignOut = canSignOut;
}
} else {
accounts.push({ ...account, canSignOut });
}
}

private removeAccount(providerId: string, account: AuthenticationSessionAccount): void {
Expand Down