mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Address feedback on auth provider API
This commit is contained in:
parent
0d1933a322
commit
a155fcf762
|
@ -141,7 +141,12 @@ 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, { label: userInfo.accountName, id: userInfo.id }, scopes);
|
||||
return {
|
||||
id: uuid(),
|
||||
accessToken: token,
|
||||
account: { label: userInfo.accountName, id: userInfo.id },
|
||||
scopes
|
||||
};
|
||||
}
|
||||
|
||||
private async setToken(session: vscode.AuthenticationSession): Promise<void> {
|
||||
|
|
|
@ -219,7 +219,12 @@ export class AzureActiveDirectoryService {
|
|||
|
||||
private async convertToSession(token: IToken): Promise<vscode.AuthenticationSession> {
|
||||
const resolvedToken = await this.resolveAccessToken(token);
|
||||
return new vscode.AuthenticationSession(token.sessionId, resolvedToken, token.account, token.scope.split(' '));
|
||||
return {
|
||||
id: token.sessionId,
|
||||
accessToken: resolvedToken,
|
||||
account: token.account,
|
||||
scopes: token.scope.split(' ')
|
||||
};
|
||||
}
|
||||
|
||||
private async resolveAccessToken(token: IToken): Promise<string> {
|
||||
|
|
15
src/vs/vscode.proposed.d.ts
vendored
15
src/vs/vscode.proposed.d.ts
vendored
|
@ -18,7 +18,7 @@ declare module 'vscode' {
|
|||
|
||||
// #region auth provider: https://github.com/microsoft/vscode/issues/88309
|
||||
|
||||
export class AuthenticationSession {
|
||||
export interface AuthenticationSession {
|
||||
/**
|
||||
* The identifier of the authentication session.
|
||||
*/
|
||||
|
@ -39,8 +39,6 @@ declare module 'vscode' {
|
|||
* are defined by the authentication provider.
|
||||
*/
|
||||
readonly scopes: ReadonlyArray<string>;
|
||||
|
||||
constructor(id: string, accessToken: string, account: AuthenticationSessionAccountInformation, scopes: string[]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,17 +210,6 @@ declare module 'vscode' {
|
|||
*/
|
||||
export const providers: ReadonlyArray<AuthenticationProviderInformation>;
|
||||
|
||||
/**
|
||||
* Returns whether a provider has any sessions matching the requested scopes. This request
|
||||
* is transparent to the user, no UI is shown. Rejects if a provider with providerId is not
|
||||
* registered.
|
||||
* @param providerId The id of the provider
|
||||
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication
|
||||
* provider
|
||||
* @returns A thenable that resolve to whether the provider has sessions with the requested scopes.
|
||||
*/
|
||||
export function hasSessions(providerId: string, scopes: string[]): Thenable<boolean>;
|
||||
|
||||
/**
|
||||
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
|
||||
* registered, or if the user does not consent to sharing authentication information with
|
||||
|
|
|
@ -205,9 +205,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
get providers(): ReadonlyArray<vscode.AuthenticationProviderInformation> {
|
||||
return extHostAuthentication.providers;
|
||||
},
|
||||
hasSessions(providerId: string, scopes: string[]): Thenable<boolean> {
|
||||
return extHostAuthentication.hasSessions(providerId, scopes);
|
||||
},
|
||||
getSession(providerId: string, scopes: string[], options: vscode.AuthenticationGetSessionOptions) {
|
||||
return extHostAuthentication.getSession(extension, providerId, scopes, options as any);
|
||||
},
|
||||
|
@ -1103,8 +1100,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
TimelineItem: extHostTypes.TimelineItem,
|
||||
CellKind: extHostTypes.CellKind,
|
||||
CellOutputKind: extHostTypes.CellOutputKind,
|
||||
NotebookCellRunState: extHostTypes.NotebookCellRunState,
|
||||
AuthenticationSession: extHostTypes.AuthenticationSession
|
||||
NotebookCellRunState: extHostTypes.NotebookCellRunState
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -40,25 +40,6 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
|
|||
return Object.freeze(this._providers);
|
||||
}
|
||||
|
||||
private async resolveSessions(providerId: string): Promise<ReadonlyArray<modes.AuthenticationSession>> {
|
||||
const provider = this._authenticationProviders.get(providerId);
|
||||
|
||||
let sessions;
|
||||
if (!provider) {
|
||||
sessions = await this._proxy.$getSessions(providerId);
|
||||
} else {
|
||||
sessions = await provider.getSessions();
|
||||
}
|
||||
|
||||
return sessions;
|
||||
}
|
||||
|
||||
async hasSessions(providerId: string, scopes: string[]): Promise<boolean> {
|
||||
const orderedScopes = scopes.sort().join(' ');
|
||||
const sessions = await this.resolveSessions(providerId);
|
||||
return !!(sessions.filter(session => session.scopes.slice().sort().join(' ') === orderedScopes).length);
|
||||
}
|
||||
|
||||
async getSession(requestingExtension: IExtensionDescription, providerId: string, scopes: string[], options: vscode.AuthenticationGetSessionOptions & { createIfNone: true }): Promise<vscode.AuthenticationSession>;
|
||||
async getSession(requestingExtension: IExtensionDescription, providerId: string, scopes: string[], options: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined> {
|
||||
const provider = this._authenticationProviders.get(providerId);
|
||||
|
|
|
@ -2774,13 +2774,6 @@ export enum ExtensionMode {
|
|||
|
||||
//#endregion ExtensionContext
|
||||
|
||||
|
||||
//#region Authentication
|
||||
export class AuthenticationSession implements vscode.AuthenticationSession {
|
||||
constructor(public id: string, public accessToken: string, public account: { label: string, id: string }, public scopes: string[]) { }
|
||||
}
|
||||
|
||||
//#endregion Authentication
|
||||
export enum StandardTokenType {
|
||||
Other = 0,
|
||||
Comment = 1,
|
||||
|
|
Loading…
Reference in a new issue