Avoid conflicting scopes and commandIds in quiet logins from Accounts (fix #137601) (#137613)

* Avoid conflicting scopes and commandIds in quiet logins from Accounts (fix #137601)

* revert from scopesJSON to scopesList but use space as separator

* define SCOPESLIST_SEPARATOR and use it consistently

* simplify diff
This commit is contained in:
John Murray 2021-11-22 18:38:39 +00:00 committed by GitHub
parent 00e466b4b9
commit 5128d2c32c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -163,13 +163,16 @@ export function readAllowedExtensions(storageService: IStorageService, providerI
return trustedExtensions;
}
export interface SessionRequest {
// OAuth2 spec prohibits space in a scope, so use that to join them.
const SCOPESLIST_SEPARATOR = ' ';
interface SessionRequest {
disposables: IDisposable[];
requestingExtensionIds: string[];
}
export interface SessionRequestInfo {
[scopes: string]: SessionRequest;
interface SessionRequestInfo {
[scopesList: string]: SessionRequest;
}
CommandsRegistry.registerCommand('workbench.getCodeExchangeProxyEndpoints', function (accessor, _) {
@ -347,7 +350,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
}
Object.keys(existingRequestsForProvider).forEach(requestedScopes => {
if (addedSessions.some(session => session.scopes.slice().join('') === requestedScopes)) {
if (addedSessions.some(session => session.scopes.slice().join(SCOPESLIST_SEPARATOR) === requestedScopes)) {
const sessionRequest = existingRequestsForProvider[requestedScopes];
sessionRequest?.disposables.forEach(item => item.dispose());
@ -613,7 +616,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
if (provider) {
const providerRequests = this._signInRequestItems.get(providerId);
const scopesList = scopes.join('');
const scopesList = scopes.join(SCOPESLIST_SEPARATOR);
const extensionHasExistingRequest = providerRequests
&& providerRequests[scopesList]
&& providerRequests[scopesList].requestingExtensionIds.includes(extensionId);
@ -622,10 +625,12 @@ export class AuthenticationService extends Disposable implements IAuthentication
return;
}
// Construct a commandId that won't clash with others generated here, nor likely with an extension's command
const commandId = `${providerId}:${extensionId}:signIn${Object.keys(providerRequests || []).length}`;
const menuItem = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
group: '2_signInRequests',
command: {
id: `${extensionId}signIn`,
id: commandId,
title: nls.localize({
key: 'signInRequest',
comment: [`The placeholder {0} will be replaced with an authentication provider's label. {1} will be replaced with an extension name. (1) is to indicate that this menu item contributes to a badge count.`]
@ -637,7 +642,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
});
const signInCommand = CommandsRegistry.registerCommand({
id: `${extensionId}signIn`,
id: commandId,
handler: async (accessor) => {
const authenticationService = accessor.get(IAuthenticationService);
const storageService = accessor.get(IStorageService);