displayName -> label, use providerIds in favor of getProviderIds, #100993

This commit is contained in:
Rachel Macfarlane
2020-07-06 18:22:51 -07:00
parent 1728c5bab0
commit 348e2b4c6e
11 changed files with 57 additions and 36 deletions

View File

@@ -135,17 +135,17 @@ export class MainThreadAuthenticationProvider extends Disposable {
}
private registerSession(session: modes.AuthenticationSession) {
this._sessions.set(session.id, session.account.displayName);
this._sessions.set(session.id, session.account.label);
const existingSessionsForAccount = this._accounts.get(session.account.displayName);
const existingSessionsForAccount = this._accounts.get(session.account.label);
if (existingSessionsForAccount) {
this._accounts.set(session.account.displayName, existingSessionsForAccount.concat(session.id));
this._accounts.set(session.account.label, existingSessionsForAccount.concat(session.id));
return;
} else {
this._accounts.set(session.account.displayName, [session.id]);
this._accounts.set(session.account.label, [session.id]);
}
this.storageKeysSyncRegistryService.registerStorageKey({ key: `${this.id}-${session.account.displayName}`, version: 1 });
this.storageKeysSyncRegistryService.registerStorageKey({ key: `${this.id}-${session.account.label}`, version: 1 });
}
async signOut(accountName: string): Promise<void> {
@@ -273,7 +273,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
if (sessions.length) {
if (!this.authenticationService.supportsMultipleAccounts(providerId)) {
const session = sessions[0];
const allowed = await this.$getSessionsPrompt(providerId, session.account.displayName, label, extensionId, extensionName);
const allowed = await this.$getSessionsPrompt(providerId, session.account.label, label, extensionId, extensionName);
if (allowed) {
return session;
} else {
@@ -292,7 +292,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
}
const session = await this.authenticationService.login(providerId, scopes);
await this.$setTrustedExtension(providerId, session.account.displayName, extensionId, extensionName);
await this.$setTrustedExtension(providerId, session.account.label, extensionId, extensionName);
return session;
} else {
await this.$requestNewSession(providerId, scopes, extensionId, extensionName);
@@ -313,7 +313,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
if (existingSessionPreference) {
const matchingSession = potentialSessions.find(session => session.id === existingSessionPreference);
if (matchingSession) {
const allowed = await this.$getSessionsPrompt(providerId, matchingSession.account.displayName, providerName, extensionId, extensionName);
const allowed = await this.$getSessionsPrompt(providerId, matchingSession.account.label, providerName, extensionId, extensionName);
if (allowed) {
return matchingSession;
}
@@ -326,7 +326,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
quickPick.ignoreFocusOut = true;
const items: { label: string, session?: modes.AuthenticationSession }[] = potentialSessions.map(session => {
return {
label: session.account.displayName,
label: session.account.label,
session
};
});
@@ -351,7 +351,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
const session = selected.session ?? await this.authenticationService.login(providerId, scopes);
const accountName = session.account.displayName;
const accountName = session.account.label;
const allowList = readAllowedExtensions(this.storageService, providerId, accountName);
if (!allowList.find(allowed => allowed.id === extensionId)) {

View File

@@ -14,6 +14,8 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
private _proxy: MainThreadAuthenticationShape;
private _authenticationProviders: Map<string, vscode.AuthenticationProvider> = new Map<string, vscode.AuthenticationProvider>();
private _providerIds: string[] = [];
private _onDidChangeAuthenticationProviders = new Emitter<vscode.AuthenticationProvidersChangeEvent>();
readonly onDidChangeAuthenticationProviders: Event<vscode.AuthenticationProvidersChangeEvent> = this._onDidChangeAuthenticationProviders.event;
@@ -29,12 +31,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
}
get providerIds(): string[] {
const ids: string[] = [];
this._authenticationProviders.forEach(provider => {
ids.push(provider.id);
});
return ids;
return this._providerIds;
}
private async resolveSessions(providerId: string): Promise<ReadonlyArray<modes.AuthenticationSession>> {
@@ -72,7 +69,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
if (sessions.length) {
if (!provider.supportsMultipleAccounts) {
const session = sessions[0];
const allowed = await this._proxy.$getSessionsPrompt(providerId, session.account.displayName, provider.label, extensionId, extensionName);
const allowed = await this._proxy.$getSessionsPrompt(providerId, session.account.label, provider.label, extensionId, extensionName);
if (allowed) {
return session;
} else {
@@ -91,7 +88,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
}
const session = await provider.login(scopes);
await this._proxy.$setTrustedExtension(providerId, session.account.displayName, extensionId, extensionName);
await this._proxy.$setTrustedExtension(providerId, session.account.label, extensionId, extensionName);
return session;
} else {
await this._proxy.$requestNewSession(providerId, scopes, extensionId, extensionName);
@@ -115,6 +112,9 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
}
this._authenticationProviders.set(provider.id, provider);
if (!this._providerIds.includes(provider.id)) {
this._providerIds.push(provider.id);
}
const listener = provider.onDidChangeSessions(e => {
this._proxy.$sendDidChangeSessions(provider.id, e);
@@ -125,6 +125,10 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
return new Disposable(() => {
listener.dispose();
this._authenticationProviders.delete(provider.id);
const index = this._providerIds.findIndex(id => id === provider.id);
if (index > -1) {
this._providerIds.splice(index);
}
this._proxy.$unregisterAuthenticationProvider(provider.id);
});
}
@@ -177,6 +181,19 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
}
$onDidChangeAuthenticationProviders(added: string[], removed: string[]) {
added.forEach(id => {
if (!this._providerIds.includes(id)) {
this._providerIds.push(id);
}
});
removed.forEach(id => {
const index = this._providerIds.findIndex(provider => provider === id);
if (index > -1) {
this._providerIds.splice(index);
}
});
this._onDidChangeAuthenticationProviders.fire({ added, removed });
return Promise.resolve();
}

View File

@@ -2770,7 +2770,7 @@ export enum ExtensionMode {
//#region Authentication
export class AuthenticationSession implements vscode.AuthenticationSession {
constructor(public id: string, public accessToken: string, public account: { displayName: string, id: string }, public scopes: string[]) { }
constructor(public id: string, public accessToken: string, public account: { label: string, id: string }, public scopes: string[]) { }
}
//#endregion Authentication