mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Add supportsMultipleAccounts to auth providers
This commit is contained in:
parent
4a875e0d7c
commit
cbb0b04d7d
|
@ -25,6 +25,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
vscode.authentication.registerAuthenticationProvider({
|
||||
id: 'github',
|
||||
displayName: 'GitHub',
|
||||
supportsMultipleAccounts: false,
|
||||
onDidChangeSessions: onDidChangeSessions.event,
|
||||
getSessions: () => Promise.resolve(loginService.sessions),
|
||||
login: async (scopeList: string[]) => {
|
||||
|
|
|
@ -20,6 +20,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
context.subscriptions.push(vscode.authentication.registerAuthenticationProvider({
|
||||
id: 'microsoft',
|
||||
displayName: 'Microsoft',
|
||||
supportsMultipleAccounts: true,
|
||||
onDidChangeSessions: onDidChangeSessions.event,
|
||||
getSessions: () => Promise.resolve(loginService.sessions),
|
||||
login: async (scopes: string[]) => {
|
||||
|
|
10
src/vs/vscode.proposed.d.ts
vendored
10
src/vs/vscode.proposed.d.ts
vendored
|
@ -77,6 +77,11 @@ declare module 'vscode' {
|
|||
readonly id: string;
|
||||
readonly displayName: string;
|
||||
|
||||
/**
|
||||
* Whether it is possible to be signed into multiple accounts at once.
|
||||
*/
|
||||
supportsMultipleAccounts: boolean;
|
||||
|
||||
/**
|
||||
* An [event](#Event) which fires when the array of sessions has changed, or data
|
||||
* within a session has changed.
|
||||
|
@ -143,6 +148,7 @@ declare module 'vscode' {
|
|||
export function getSession(providerId: string, scopes: string[], options: GetSessionOptions): Thenable<AuthenticationSession | undefined>;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Get existing authentication sessions. Rejects if a provider with providerId is not
|
||||
* registered, or if the user does not consent to sharing authentication information with
|
||||
* the extension.
|
||||
|
@ -150,9 +156,10 @@ declare module 'vscode' {
|
|||
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication
|
||||
* provider
|
||||
*/
|
||||
export function getSessions(providerId: string, scopes: string[]): Thenable<readonly AuthenticationSession[]>;
|
||||
export function getSessions(providerId: string, scopes: string[]): Thenable<ReadonlyArray<AuthenticationSession>>;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Prompt a user to login to create a new authenticaiton session. Rejects if a provider with
|
||||
* providerId is not registered, or if the user does not consent to sharing authentication
|
||||
* information with the extension.
|
||||
|
@ -163,6 +170,7 @@ declare module 'vscode' {
|
|||
export function login(providerId: string, scopes: string[]): Thenable<AuthenticationSession>;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Logout of a specific session.
|
||||
* @param providerId The id of the provider to use
|
||||
* @param sessionId The session id to remove
|
||||
|
|
|
@ -52,8 +52,18 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
|
|||
const orderedScopes = scopes.sort().join(' ');
|
||||
const sessions = (await provider.getSessions()).filter(session => session.scopes.sort().join(' ') === orderedScopes);
|
||||
if (sessions.length) {
|
||||
// On renderer side, confirm consent, ask user to choose between accounts if multiple sessions are valid
|
||||
const extensionName = requestingExtension.displayName || requestingExtension.name;
|
||||
if (!provider.supportsMultipleAccounts) {
|
||||
const session = sessions[0];
|
||||
const allowed = await this._proxy.$getSessionsPrompt(provider.id, session.account.displayName, provider.displayName, ExtensionIdentifier.toKey(requestingExtension.identifier), extensionName);
|
||||
if (allowed) {
|
||||
return session;
|
||||
} else {
|
||||
throw new Error('User did not consent to login.');
|
||||
}
|
||||
}
|
||||
|
||||
// On renderer side, confirm consent, ask user to choose between accounts if multiple sessions are valid
|
||||
const selected = await this._proxy.$getSession(provider.id, provider.displayName, ExtensionIdentifier.toKey(requestingExtension.identifier), extensionName, sessions, scopes, !!options.clearSessionPreference);
|
||||
return sessions.find(session => session.id === selected.id);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue