Auth providers - show dialog on token access, closes #89754

This commit is contained in:
Rachel Macfarlane
2020-02-06 15:30:42 -08:00
parent a4c2d6337d
commit cf96b11223
7 changed files with 59 additions and 22 deletions

View File

@@ -29,12 +29,26 @@ export class AuthenticationProviderWrapper implements vscode.AuthenticationProvi
}
async getSessions(): Promise<ReadonlyArray<vscode.AuthenticationSession>> {
const isAllowed = await this._proxy.$getSessionsPrompt(this._provider.id, this.displayName, ExtensionIdentifier.toKey(this._requestingExtension.identifier), this._requestingExtension.displayName || this._requestingExtension.name);
if (!isAllowed) {
throw new Error('User did not consent to session access.');
}
return (await this._provider.getSessions()).map(session => {
return {
id: session.id,
accountName: session.accountName,
scopes: session.scopes,
accessToken: async () => {
const isAllowed = await this._proxy.$getSessionsPrompt(
this._provider.id,
this.displayName,
ExtensionIdentifier.toKey(this._requestingExtension.identifier),
this._requestingExtension.displayName || this._requestingExtension.name);
return this._provider.getSessions();
if (!isAllowed) {
throw new Error('User did not consent to token access.');
}
return session.accessToken();
}
};
});
}
async login(scopes: string[]): Promise<vscode.AuthenticationSession> {
@@ -96,7 +110,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
return Promise.resolve(authProvider.login(scopes));
}
throw new Error(`Unable to find authentication provider with handle: ${0}`);
throw new Error(`Unable to find authentication provider with handle: ${providerId}`);
}
$logout(providerId: string, sessionId: string): Promise<void> {
@@ -105,7 +119,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
return Promise.resolve(authProvider.logout(sessionId));
}
throw new Error(`Unable to find authentication provider with handle: ${0}`);
throw new Error(`Unable to find authentication provider with handle: ${providerId}`);
}
$getSessions(providerId: string): Promise<ReadonlyArray<modes.AuthenticationSession>> {
@@ -114,6 +128,21 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
return Promise.resolve(authProvider.getSessions());
}
throw new Error(`Unable to find authentication provider with handle: ${0}`);
throw new Error(`Unable to find authentication provider with handle: ${providerId}`);
}
async $getSessionAccessToken(providerId: string, sessionId: string): Promise<string> {
const authProvider = this._authenticationProviders.get(providerId);
if (authProvider) {
const sessions = await authProvider.getSessions();
const session = sessions.find(session => session.id === sessionId);
if (session) {
return session.accessToken();
}
throw new Error(`Unable to find session with id: ${sessionId}`);
}
throw new Error(`Unable to find authentication provider with handle: ${providerId}`);
}
}