提交 348e2b4c 编写于 作者: R Rachel Macfarlane

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

上级 1728c5ba
......@@ -14,7 +14,8 @@ export const onDidChangeSessions = new vscode.EventEmitter<vscode.Authentication
interface SessionData {
id: string;
account?: {
displayName: string;
label?: string;
displayName?: string;
id: string;
}
scopes: string[];
......@@ -95,7 +96,9 @@ export class GitHubAuthenticationProvider {
return {
id: session.id,
account: {
displayName: session.account?.displayName ?? userInfo!.accountName,
label: session.account
? session.account.label || session.account.displayName!
: userInfo!.accountName,
id: session.account?.id ?? userInfo!.id
},
scopes: session.scopes,
......@@ -138,7 +141,7 @@ export class GitHubAuthenticationProvider {
private async tokenToSession(token: string, scopes: string[]): Promise<vscode.AuthenticationSession> {
const userInfo = await this._githubServer.getUserInfo(token);
return new vscode.AuthenticationSession(uuid(), token, { displayName: userInfo.accountName, id: userInfo.id }, scopes);
return new vscode.AuthenticationSession(uuid(), token, { label: userInfo.accountName, id: userInfo.id }, scopes);
}
private async setToken(session: vscode.AuthenticationSession): Promise<void> {
......
......@@ -26,7 +26,7 @@ interface IToken {
refreshToken: string;
account: {
displayName: string;
label: string;
id: string;
};
scope: string;
......@@ -48,7 +48,8 @@ interface IStoredSession {
refreshToken: string;
scope: string; // Scopes are alphabetized and joined with a space
account: {
displayName: string,
label?: string;
displayName?: string,
id: string
}
}
......@@ -101,7 +102,7 @@ export class AzureActiveDirectoryService {
accessToken: undefined,
refreshToken: session.refreshToken,
account: {
displayName: session.account.displayName,
label: session.account.label ?? session.account.displayName!,
id: session.account.id
},
scope: session.scope,
......@@ -437,7 +438,7 @@ export class AzureActiveDirectoryService {
scope,
sessionId: existingId || `${claims.tid}/${(claims.oid || (claims.altsecid || '' + claims.ipd || ''))}/${uuid()}`,
account: {
displayName: claims.email || claims.unique_name || 'user@example.com',
label: claims.email || claims.unique_name || 'user@example.com',
id: `${claims.tid}/${(claims.oid || (claims.altsecid || '' + claims.ipd || ''))}`
}
};
......
......@@ -1413,7 +1413,7 @@ export interface AuthenticationSession {
id: string;
accessToken: string;
account: {
displayName: string;
label: string;
id: string;
}
scopes: ReadonlyArray<string>;
......
......@@ -52,7 +52,7 @@ declare module 'vscode' {
/**
* The human-readable name of the account.
*/
readonly displayName: string;
readonly label: string;
/**
* The unique identifier of the account.
......@@ -175,13 +175,13 @@ declare module 'vscode' {
export const onDidChangeAuthenticationProviders: Event<AuthenticationProvidersChangeEvent>;
/**
* @deprecated
* The ids of the currently registered authentication providers.
* @returns An array of the ids of authentication providers that are currently registered.
*/
export function getProviderIds(): Thenable<ReadonlyArray<string>>;
/**
* @deprecated
* An array of the ids of authentication providers that are currently registered.
*/
export const providerIds: ReadonlyArray<string>;
......
......@@ -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)) {
......
......@@ -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();
}
......
......@@ -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
......
......@@ -141,7 +141,7 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
const providers = this.authenticationService.getProviderIds();
const allSessions = providers.map(async id => {
const sessions = await this.authenticationService.getSessions(id);
const uniqueSessions = distinct(sessions, session => session.account.displayName);
const uniqueSessions = distinct(sessions, session => session.account.label);
return {
providerId: id,
sessions: uniqueSessions
......@@ -153,7 +153,7 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
result.forEach(sessionInfo => {
const providerDisplayName = this.authenticationService.getLabel(sessionInfo.providerId);
sessionInfo.sessions.forEach(session => {
const accountName = session.account.displayName;
const accountName = session.account.label;
const menu = new ContextSubMenu(`${accountName} (${providerDisplayName})`, [
new Action(`configureSessions${accountName}`, nls.localize('manageTrustedExtensions', "Manage Trusted Extensions"), '', true, _ => {
return this.authenticationService.manageTrustedExtensionsForAccount(sessionInfo.providerId, accountName);
......
......@@ -185,7 +185,7 @@ export async function readTrustedDomains(accessor: ServicesAccessor) {
const userDomains =
authenticationService.isAuthenticationProviderRegistered('github')
? ((await authenticationService.getSessions('github')) ?? [])
.map(session => session.account.displayName)
.map(session => session.account.label)
.filter((v, i, a) => a.indexOf(v) === i)
.map(username => `https://github.com/${username}/`)
: [];
......
......@@ -255,10 +255,10 @@ export class AuthenticationService extends Disposable implements IAuthentication
const session = await authenticationService.login(providerId, scopes);
// Add extension to allow list since user explicitly signed in on behalf of it
const allowList = readAllowedExtensions(storageService, providerId, session.account.displayName);
const allowList = readAllowedExtensions(storageService, providerId, session.account.label);
if (!allowList.find(allowed => allowed.id === extensionId)) {
allowList.push({ id: extensionId, name: extensionName });
storageService.store(`${providerId}-${session.account.displayName}`, JSON.stringify(allowList), StorageScope.GLOBAL);
storageService.store(`${providerId}-${session.account.label}`, JSON.stringify(allowList), StorageScope.GLOBAL);
}
// And also set it as the preferred account for the extension
......
......@@ -49,7 +49,7 @@ class UserDataSyncAccount implements IUserDataSyncAccount {
constructor(readonly authenticationProviderId: string, private readonly session: AuthenticationSession) { }
get sessionId(): string { return this.session.id; }
get accountName(): string { return this.session.account.displayName; }
get accountName(): string { return this.session.account.label; }
get accountId(): string { return this.session.account.id; }
get token(): string { return this.session.accessToken; }
}
......@@ -305,7 +305,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat
if (isAuthenticationProvider(result)) {
const session = await this.authenticationService.login(result.id, result.scopes);
sessionId = session.id;
accountName = session.account.displayName;
accountName = session.account.label;
accountId = session.account.id;
} else {
sessionId = result.sessionId;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册