Skip to content

Commit bdc347e

Browse files
Use ExtensionIdentitfier class to squash some "toLower" bugs (microsoft#232179)
Fixes microsoft#231964
1 parent 329740d commit bdc347e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/vs/workbench/contrib/authentication/browser/actions/manageAccountPreferencesForExtensionAction.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { DisposableStore, IDisposable } from '../../../../../base/common/lifecyc
88
import { localize, localize2 } from '../../../../../nls.js';
99
import { Action2 } from '../../../../../platform/actions/common/actions.js';
1010
import { IDialogService } from '../../../../../platform/dialogs/common/dialogs.js';
11+
import { ExtensionIdentifier } from '../../../../../platform/extensions/common/extensions.js';
1112
import { IInstantiationService, ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
1213
import { ILogService } from '../../../../../platform/log/common/log.js';
1314
import { IQuickInputService, IQuickPick, IQuickPickItem, QuickPickInput } from '../../../../../platform/quickinput/common/quickInput.js';
1415
import { IAccountUsage, IAuthenticationUsageService } from '../../../../services/authentication/browser/authenticationUsageService.js';
15-
import { AuthenticationSessionAccount, IAuthenticationExtensionsService, IAuthenticationService } from '../../../../services/authentication/common/authentication.js';
16+
import { AuthenticationSessionAccount, IAuthenticationExtensionsService, IAuthenticationService, INTERNAL_AUTH_PROVIDER_PREFIX } from '../../../../services/authentication/common/authentication.js';
1617
import { IExtensionService } from '../../../../services/extensions/common/extensions.js';
1718

1819
export class ManageAccountPreferencesForExtensionAction extends Action2 {
@@ -71,9 +72,13 @@ class ManageAccountPreferenceForExtensionActionImpl {
7172
providerIdToAccounts.set(providerId, await this._authenticationService.getAccounts(providerId));
7273
} else {
7374
for (const providerId of this._authenticationService.getProviderIds()) {
75+
if (providerId.startsWith(INTERNAL_AUTH_PROVIDER_PREFIX)) {
76+
// Don't show internal providers
77+
continue;
78+
}
7479
const accounts = await this._authenticationService.getAccounts(providerId);
7580
for (const account of accounts) {
76-
const usage = this._authenticationUsageService.readAccountUsages(providerId, account.label).find(u => u.extensionId === extensionId.toLowerCase());
81+
const usage = this._authenticationUsageService.readAccountUsages(providerId, account.label).find(u => ExtensionIdentifier.equals(u.extensionId, extensionId));
7782
if (usage) {
7883
providerIds.push(providerId);
7984
providerIdToAccounts.set(providerId, accounts);
@@ -113,7 +118,7 @@ class ManageAccountPreferenceForExtensionActionImpl {
113118
// Get the last used scopes for the last used account. This will be used to pre-fill the scopes when adding a new account.
114119
// If there's no scopes, then don't add this option.
115120
const lastUsedScopes = accounts
116-
.flatMap(account => this._authenticationUsageService.readAccountUsages(chosenProviderId!, account.label).find(u => u.extensionId === extensionId.toLowerCase()))
121+
.flatMap(account => this._authenticationUsageService.readAccountUsages(chosenProviderId!, account.label).find(u => ExtensionIdentifier.equals(u.extensionId, extensionId)))
117122
.filter((usage): usage is IAccountUsage => !!usage)
118123
.sort((a, b) => b.lastUsed - a.lastUsed)?.[0]?.scopes;
119124
if (lastUsedScopes) {

src/vs/workbench/services/authentication/browser/authenticationExtensionsService.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { IAuthenticationUsageService } from './authenticationUsageService.js';
1818
import { AuthenticationSession, IAuthenticationProvider, IAuthenticationService, IAuthenticationExtensionsService, AuthenticationSessionAccount } from '../common/authentication.js';
1919
import { Emitter } from '../../../../base/common/event.js';
2020
import { IProductService } from '../../../../platform/product/common/productService.js';
21+
import { ExtensionIdentifier } from '../../../../platform/extensions/common/extensions.js';
2122

2223
// OAuth2 spec prohibits space in a scope, so use that to join them.
2324
const SCOPESLIST_SEPARATOR = ' ';
@@ -153,7 +154,8 @@ export class AuthenticationExtensionsService extends Disposable implements IAuth
153154
//#region Account/Session Preference
154155

155156
updateAccountPreference(extensionId: string, providerId: string, account: AuthenticationSessionAccount): void {
156-
const parentExtensionId = this._inheritAuthAccountPreferenceChildToParent[extensionId] ?? extensionId;
157+
const realExtensionId = ExtensionIdentifier.toKey(extensionId);
158+
const parentExtensionId = this._inheritAuthAccountPreferenceChildToParent[realExtensionId] ?? realExtensionId;
157159
const key = this._getKey(parentExtensionId, providerId);
158160

159161
// Store the preference in the workspace and application storage. This allows new workspaces to
@@ -168,14 +170,16 @@ export class AuthenticationExtensionsService extends Disposable implements IAuth
168170
}
169171

170172
getAccountPreference(extensionId: string, providerId: string): string | undefined {
171-
const key = this._getKey(this._inheritAuthAccountPreferenceChildToParent[extensionId] ?? extensionId, providerId);
173+
const realExtensionId = ExtensionIdentifier.toKey(extensionId);
174+
const key = this._getKey(this._inheritAuthAccountPreferenceChildToParent[realExtensionId] ?? realExtensionId, providerId);
172175

173176
// If a preference is set in the workspace, use that. Otherwise, use the global preference.
174177
return this.storageService.get(key, StorageScope.WORKSPACE) ?? this.storageService.get(key, StorageScope.APPLICATION);
175178
}
176179

177180
removeAccountPreference(extensionId: string, providerId: string): void {
178-
const key = this._getKey(this._inheritAuthAccountPreferenceChildToParent[extensionId] ?? extensionId, providerId);
181+
const realExtensionId = ExtensionIdentifier.toKey(extensionId);
182+
const key = this._getKey(this._inheritAuthAccountPreferenceChildToParent[realExtensionId] ?? realExtensionId, providerId);
179183

180184
// This won't affect any other workspaces that have a preference set, but it will remove the preference
181185
// for this workspace and the global preference. This is only paired with a call to updateSessionPreference...
@@ -192,11 +196,12 @@ export class AuthenticationExtensionsService extends Disposable implements IAuth
192196
// TODO@TylerLeonhardt: Remove all of this after a couple iterations
193197

194198
updateSessionPreference(providerId: string, extensionId: string, session: AuthenticationSession): void {
199+
const realExtensionId = ExtensionIdentifier.toKey(extensionId);
195200
// The 3 parts of this key are important:
196201
// * Extension id: The extension that has a preference
197202
// * Provider id: The provider that the preference is for
198203
// * The scopes: The subset of sessions that the preference applies to
199-
const key = `${extensionId}-${providerId}-${session.scopes.join(SCOPESLIST_SEPARATOR)}`;
204+
const key = `${realExtensionId}-${providerId}-${session.scopes.join(SCOPESLIST_SEPARATOR)}`;
200205

201206
// Store the preference in the workspace and application storage. This allows new workspaces to
202207
// have a preference set already to limit the number of prompts that are shown... but also allows
@@ -206,22 +211,24 @@ export class AuthenticationExtensionsService extends Disposable implements IAuth
206211
}
207212

208213
getSessionPreference(providerId: string, extensionId: string, scopes: string[]): string | undefined {
214+
const realExtensionId = ExtensionIdentifier.toKey(extensionId);
209215
// The 3 parts of this key are important:
210216
// * Extension id: The extension that has a preference
211217
// * Provider id: The provider that the preference is for
212218
// * The scopes: The subset of sessions that the preference applies to
213-
const key = `${extensionId}-${providerId}-${scopes.join(SCOPESLIST_SEPARATOR)}`;
219+
const key = `${realExtensionId}-${providerId}-${scopes.join(SCOPESLIST_SEPARATOR)}`;
214220

215221
// If a preference is set in the workspace, use that. Otherwise, use the global preference.
216222
return this.storageService.get(key, StorageScope.WORKSPACE) ?? this.storageService.get(key, StorageScope.APPLICATION);
217223
}
218224

219225
removeSessionPreference(providerId: string, extensionId: string, scopes: string[]): void {
226+
const realExtensionId = ExtensionIdentifier.toKey(extensionId);
220227
// The 3 parts of this key are important:
221228
// * Extension id: The extension that has a preference
222229
// * Provider id: The provider that the preference is for
223230
// * The scopes: The subset of sessions that the preference applies to
224-
const key = `${extensionId}-${providerId}-${scopes.join(SCOPESLIST_SEPARATOR)}`;
231+
const key = `${realExtensionId}-${providerId}-${scopes.join(SCOPESLIST_SEPARATOR)}`;
225232

226233
// This won't affect any other workspaces that have a preference set, but it will remove the preference
227234
// for this workspace and the global preference. This is only paired with a call to updateSessionPreference...

0 commit comments

Comments
 (0)