Rename login/logout to createSession/removeSession

This commit is contained in:
Rachel Macfarlane 2021-02-11 16:44:35 -08:00
parent ea865096f1
commit eceff53351
12 changed files with 52 additions and 52 deletions

View file

@ -26,14 +26,14 @@ export async function activate(context: vscode.ExtensionContext) {
onDidChangeSessions: onDidChangeSessions.event, onDidChangeSessions: onDidChangeSessions.event,
getAllSessions: () => Promise.resolve(loginService.sessions), getAllSessions: () => Promise.resolve(loginService.sessions),
getSessions: (scopes: string[]) => loginService.getSessions(scopes), getSessions: (scopes: string[]) => loginService.getSessions(scopes),
login: async (scopeList: string[]) => { createSession: async (scopeList: string[]) => {
try { try {
/* __GDPR__ /* __GDPR__
"login" : { } "login" : { }
*/ */
telemetryReporter.sendTelemetryEvent('login'); telemetryReporter.sendTelemetryEvent('login');
const session = await loginService.login(scopeList.sort().join(' ')); const session = await loginService.createSession(scopeList.sort().join(' '));
Logger.info('Login success!'); Logger.info('Login success!');
onDidChangeSessions.fire({ added: [session], removed: [], changed: [] }); onDidChangeSessions.fire({ added: [session], removed: [], changed: [] });
return session; return session;
@ -57,14 +57,14 @@ export async function activate(context: vscode.ExtensionContext) {
throw e; throw e;
} }
}, },
logout: async (id: string) => { removeSession: async (id: string) => {
try { try {
/* __GDPR__ /* __GDPR__
"logout" : { } "logout" : { }
*/ */
telemetryReporter.sendTelemetryEvent('logout'); telemetryReporter.sendTelemetryEvent('logout');
const session = await loginService.logout(id); const session = await loginService.removeSession(id);
if (session) { if (session) {
onDidChangeSessions.fire({ added: [], removed: [session], changed: [] }); onDidChangeSessions.fire({ added: [], removed: [session], changed: [] });
} }

View file

@ -158,7 +158,7 @@ export class GitHubAuthenticationProvider {
return this._sessions; return this._sessions;
} }
public async login(scopes: string): Promise<vscode.AuthenticationSession> { public async createSession(scopes: string): Promise<vscode.AuthenticationSession> {
const token = await this._githubServer.login(scopes); const token = await this._githubServer.login(scopes);
const session = await this.tokenToSession(token, scopes.split(' ')); const session = await this.tokenToSession(token, scopes.split(' '));
await this.setToken(session); await this.setToken(session);
@ -190,7 +190,7 @@ export class GitHubAuthenticationProvider {
await this.storeSessions(); await this.storeSessions();
} }
public async logout(id: string): Promise<vscode.AuthenticationSession | undefined> { public async removeSession(id: string): Promise<vscode.AuthenticationSession | undefined> {
Logger.info(`Logging out of ${id}`); Logger.info(`Logging out of ${id}`);
const sessionIndex = this._sessions.findIndex(session => session.id === id); const sessionIndex = this._sessions.findIndex(session => session.id === id);
let session: vscode.AuthenticationSession | undefined; let session: vscode.AuthenticationSession | undefined;

View file

@ -144,7 +144,7 @@ export class AzureActiveDirectoryService {
this.pollForReconnect(session.id, session.refreshToken, session.scope); this.pollForReconnect(session.id, session.refreshToken, session.scope);
} }
} else { } else {
await this.logout(session.id); await this.removeSession(session.id);
} }
} }
}); });
@ -193,7 +193,7 @@ export class AzureActiveDirectoryService {
if (e.message === REFRESH_NETWORK_FAILURE) { if (e.message === REFRESH_NETWORK_FAILURE) {
// Ignore, will automatically retry on next poll. // Ignore, will automatically retry on next poll.
} else { } else {
await this.logout(session.id); await this.removeSession(session.id);
} }
} }
} }
@ -202,7 +202,7 @@ export class AzureActiveDirectoryService {
promises = promises.concat(this._tokens.map(async token => { promises = promises.concat(this._tokens.map(async token => {
const matchesExisting = sessions.some(session => token.scope === session.scope && token.sessionId === session.id); const matchesExisting = sessions.some(session => token.scope === session.scope && token.sessionId === session.id);
if (!matchesExisting) { if (!matchesExisting) {
await this.logout(token.sessionId); await this.removeSession(token.sessionId);
removed.push(this.convertToSessionSync(token)); removed.push(this.convertToSessionSync(token));
} }
})); }));
@ -306,7 +306,7 @@ export class AzureActiveDirectoryService {
return Promise.all(this._tokens.map(token => this.convertToSession(token))); return Promise.all(this._tokens.map(token => this.convertToSession(token)));
} }
public async login(scope: string): Promise<vscode.AuthenticationSession> { public async createSession(scope: string): Promise<vscode.AuthenticationSession> {
Logger.info('Logging in...'); Logger.info('Logging in...');
if (!scope.includes('offline_access')) { if (!scope.includes('offline_access')) {
Logger.info('Warning: The \'offline_access\' scope was not included, so the generated token will not be able to be refreshed.'); Logger.info('Warning: The \'offline_access\' scope was not included, so the generated token will not be able to be refreshed.');
@ -507,7 +507,7 @@ export class AzureActiveDirectoryService {
this.pollForReconnect(token.sessionId, token.refreshToken, token.scope); this.pollForReconnect(token.sessionId, token.refreshToken, token.scope);
} }
} else { } else {
await this.logout(token.sessionId); await this.removeSession(token.sessionId);
onDidChangeSessions.fire({ added: [], removed: [this.convertToSessionSync(token)], changed: [] }); onDidChangeSessions.fire({ added: [], removed: [this.convertToSessionSync(token)], changed: [] });
} }
} }
@ -687,7 +687,7 @@ export class AzureActiveDirectoryService {
}); });
} }
public async logout(sessionId: string): Promise<vscode.AuthenticationSession | undefined> { public async removeSession(sessionId: string): Promise<vscode.AuthenticationSession | undefined> {
Logger.info(`Logging out of session '${sessionId}'`); Logger.info(`Logging out of session '${sessionId}'`);
const token = this.removeInMemorySessionData(sessionId); const token = this.removeInMemorySessionData(sessionId);
let session: vscode.AuthenticationSession | undefined; let session: vscode.AuthenticationSession | undefined;

View file

@ -22,14 +22,14 @@ export async function activate(context: vscode.ExtensionContext) {
onDidChangeSessions: onDidChangeSessions.event, onDidChangeSessions: onDidChangeSessions.event,
getAllSessions: () => Promise.resolve(loginService.sessions), getAllSessions: () => Promise.resolve(loginService.sessions),
getSessions: (scopes: string[]) => loginService.getSessions(scopes), getSessions: (scopes: string[]) => loginService.getSessions(scopes),
login: async (scopes: string[]) => { createSession: async (scopes: string[]) => {
try { try {
/* __GDPR__ /* __GDPR__
"login" : { } "login" : { }
*/ */
telemetryReporter.sendTelemetryEvent('login'); telemetryReporter.sendTelemetryEvent('login');
const session = await loginService.login(scopes.sort().join(' ')); const session = await loginService.createSession(scopes.sort().join(' '));
onDidChangeSessions.fire({ added: [session], removed: [], changed: [] }); onDidChangeSessions.fire({ added: [session], removed: [], changed: [] });
return session; return session;
} catch (e) { } catch (e) {
@ -41,14 +41,14 @@ export async function activate(context: vscode.ExtensionContext) {
throw e; throw e;
} }
}, },
logout: async (id: string) => { removeSession: async (id: string) => {
try { try {
/* __GDPR__ /* __GDPR__
"logout" : { } "logout" : { }
*/ */
telemetryReporter.sendTelemetryEvent('logout'); telemetryReporter.sendTelemetryEvent('logout');
const session = await loginService.logout(id); const session = await loginService.removeSession(id);
if (session) { if (session) {
onDidChangeSessions.fire({ added: [], removed: [session], changed: [] }); onDidChangeSessions.fire({ added: [], removed: [session], changed: [] });
} }

View file

@ -82,14 +82,14 @@ declare module 'vscode' {
* Prompts a user to login. * Prompts a user to login.
*/ */
// eslint-disable-next-line vscode-dts-provider-naming // eslint-disable-next-line vscode-dts-provider-naming
login(scopes: string[]): Thenable<AuthenticationSession>; createSession(scopes: string[]): Thenable<AuthenticationSession>;
/** /**
* Removes the session corresponding to session id. * Removes the session corresponding to session id.
* @param sessionId The session id to log out of * @param sessionId The session id to log out of
*/ */
// eslint-disable-next-line vscode-dts-provider-naming // eslint-disable-next-line vscode-dts-provider-naming
logout(sessionId: string): Thenable<void>; removeSession(sessionId: string): Thenable<void>;
} }
/** /**

View file

@ -71,7 +71,7 @@ export class MainThreadAuthenticationProvider extends Disposable {
quickPick.show(); quickPick.show();
} }
async signOut(accountName: string, sessions: modes.AuthenticationSession[]): Promise<void> { async removeAccountSessions(accountName: string, sessions: modes.AuthenticationSession[]): Promise<void> {
const accountUsages = readAccountUsages(this.storageService, this.id, accountName); const accountUsages = readAccountUsages(this.storageService, this.id, accountName);
const result = await this.dialogService.confirm({ const result = await this.dialogService.confirm({
@ -82,8 +82,8 @@ export class MainThreadAuthenticationProvider extends Disposable {
}); });
if (result.confirmed) { if (result.confirmed) {
const logoutPromises = sessions.map(session => this.logout(session.id)); const removeSessionPromises = sessions.map(session => this.removeSession(session.id));
await Promise.all(logoutPromises); await Promise.all(removeSessionPromises);
removeAccountUsage(this.storageService, this.id, accountName); removeAccountUsage(this.storageService, this.id, accountName);
this.storageService.remove(`${this.id}-${accountName}`, StorageScope.GLOBAL); this.storageService.remove(`${this.id}-${accountName}`, StorageScope.GLOBAL);
} }
@ -97,12 +97,12 @@ export class MainThreadAuthenticationProvider extends Disposable {
return this._proxy.$getAllSessions(this.id); return this._proxy.$getAllSessions(this.id);
} }
login(scopes: string[]): Promise<modes.AuthenticationSession> { createSession(scopes: string[]): Promise<modes.AuthenticationSession> {
return this._proxy.$login(this.id, scopes); return this._proxy.$createSession(this.id, scopes);
} }
async logout(sessionId: string): Promise<void> { async removeSession(sessionId: string): Promise<void> {
await this._proxy.$logout(this.id, sessionId); await this._proxy.$removeSession(this.id, sessionId);
this.notificationService.info(nls.localize('signedOut', "Successfully signed out.")); this.notificationService.info(nls.localize('signedOut', "Successfully signed out."));
} }
} }
@ -159,8 +159,8 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
this.authenticationService.sessionsUpdate(id, event); this.authenticationService.sessionsUpdate(id, event);
} }
$logout(providerId: string, sessionId: string): Promise<void> { $removeSession(providerId: string, sessionId: string): Promise<void> {
return this.authenticationService.logout(providerId, sessionId); return this.authenticationService.removeSession(providerId, sessionId);
} }
private async loginPrompt(providerName: string, extensionName: string): Promise<boolean> { private async loginPrompt(providerName: string, extensionName: string): Promise<boolean> {
const { choice } = await this.dialogService.show( const { choice } = await this.dialogService.show(
@ -247,7 +247,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
throw new Error('User did not consent to login.'); throw new Error('User did not consent to login.');
} }
session = await this.authenticationService.login(providerId, scopes, true); session = await this.authenticationService.createSession(providerId, scopes, true);
await this.setTrustedExtensionAndAccountPreference(providerId, session.account.label, extensionId, extensionName, session.id); await this.setTrustedExtensionAndAccountPreference(providerId, session.account.label, extensionId, extensionName, session.id);
} else { } else {
await this.authenticationService.requestNewSession(providerId, scopes, extensionId, extensionName); await this.authenticationService.requestNewSession(providerId, scopes, extensionId, extensionName);

View file

@ -230,7 +230,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
}, },
logout(providerId: string, sessionId: string): Thenable<void> { logout(providerId: string, sessionId: string): Thenable<void> {
checkProposedApiEnabled(extension); checkProposedApiEnabled(extension);
return extHostAuthentication.logout(providerId, sessionId); return extHostAuthentication.removeSession(providerId, sessionId);
} }
}; };

View file

@ -168,7 +168,7 @@ export interface MainThreadAuthenticationShape extends IDisposable {
$ensureProvider(id: string): Promise<void>; $ensureProvider(id: string): Promise<void>;
$sendDidChangeSessions(providerId: string, event: modes.AuthenticationSessionsChangeEvent): void; $sendDidChangeSessions(providerId: string, event: modes.AuthenticationSessionsChangeEvent): void;
$getSession(providerId: string, scopes: string[], extensionId: string, extensionName: string, options: { createIfNone?: boolean, clearSessionPreference?: boolean }): Promise<modes.AuthenticationSession | undefined>; $getSession(providerId: string, scopes: string[], extensionId: string, extensionName: string, options: { createIfNone?: boolean, clearSessionPreference?: boolean }): Promise<modes.AuthenticationSession | undefined>;
$logout(providerId: string, sessionId: string): Promise<void>; $removeSession(providerId: string, sessionId: string): Promise<void>;
} }
export interface MainThreadSecretStateShape extends IDisposable { export interface MainThreadSecretStateShape extends IDisposable {
@ -1128,8 +1128,8 @@ export interface ExtHostLabelServiceShape {
export interface ExtHostAuthenticationShape { export interface ExtHostAuthenticationShape {
$getAllSessions(id: string): Promise<ReadonlyArray<modes.AuthenticationSession>>; $getAllSessions(id: string): Promise<ReadonlyArray<modes.AuthenticationSession>>;
$getSessions(id: string, scopes: string[]): Promise<ReadonlyArray<modes.AuthenticationSession>>; $getSessions(id: string, scopes: string[]): Promise<ReadonlyArray<modes.AuthenticationSession>>;
$login(id: string, scopes: string[]): Promise<modes.AuthenticationSession>; $createSession(id: string, scopes: string[]): Promise<modes.AuthenticationSession>;
$logout(id: string, sessionId: string): Promise<void>; $removeSession(id: string, sessionId: string): Promise<void>;
$onDidChangeAuthenticationSessions(id: string, label: string, event: modes.AuthenticationSessionsChangeEvent): Promise<void>; $onDidChangeAuthenticationSessions(id: string, label: string, event: modes.AuthenticationSessionsChangeEvent): Promise<void>;
$onDidChangeAuthenticationProviders(added: modes.AuthenticationProviderInformation[], removed: modes.AuthenticationProviderInformation[]): Promise<void>; $onDidChangeAuthenticationProviders(added: modes.AuthenticationProviderInformation[], removed: modes.AuthenticationProviderInformation[]): Promise<void>;
$setProviders(providers: modes.AuthenticationProviderInformation[]): Promise<void>; $setProviders(providers: modes.AuthenticationProviderInformation[]): Promise<void>;

View file

@ -87,13 +87,13 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
return this._proxy.$getSession(providerId, scopes, extensionId, extensionName, options); return this._proxy.$getSession(providerId, scopes, extensionId, extensionName, options);
} }
async logout(providerId: string, sessionId: string): Promise<void> { async removeSession(providerId: string, sessionId: string): Promise<void> {
const providerData = this._authenticationProviders.get(providerId); const providerData = this._authenticationProviders.get(providerId);
if (!providerData) { if (!providerData) {
return this._proxy.$logout(providerId, sessionId); return this._proxy.$removeSession(providerId, sessionId);
} }
return providerData.provider.logout(sessionId); return providerData.provider.removeSession(sessionId);
} }
registerAuthenticationProvider(id: string, label: string, provider: vscode.AuthenticationProvider, options?: vscode.AuthenticationProviderOptions): vscode.Disposable { registerAuthenticationProvider(id: string, label: string, provider: vscode.AuthenticationProvider, options?: vscode.AuthenticationProviderOptions): vscode.Disposable {
@ -129,19 +129,19 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
}); });
} }
$login(providerId: string, scopes: string[]): Promise<modes.AuthenticationSession> { $createSession(providerId: string, scopes: string[]): Promise<modes.AuthenticationSession> {
const providerData = this._authenticationProviders.get(providerId); const providerData = this._authenticationProviders.get(providerId);
if (providerData) { if (providerData) {
return Promise.resolve(providerData.provider.login(scopes)); return Promise.resolve(providerData.provider.createSession(scopes));
} }
throw new Error(`Unable to find authentication provider with handle: ${providerId}`); throw new Error(`Unable to find authentication provider with handle: ${providerId}`);
} }
$logout(providerId: string, sessionId: string): Promise<void> { $removeSession(providerId: string, sessionId: string): Promise<void> {
const providerData = this._authenticationProviders.get(providerId); const providerData = this._authenticationProviders.get(providerId);
if (providerData) { if (providerData) {
return Promise.resolve(providerData.provider.logout(sessionId)); return Promise.resolve(providerData.provider.removeSession(sessionId));
} }
throw new Error(`Unable to find authentication provider with handle: ${providerId}`); throw new Error(`Unable to find authentication provider with handle: ${providerId}`);

View file

@ -240,7 +240,7 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
})); }));
const signOutAction = disposables.add(new Action('signOut', localize('signOut', "Sign Out"), '', true, () => { const signOutAction = disposables.add(new Action('signOut', localize('signOut', "Sign Out"), '', true, () => {
return this.authenticationService.signOutOfAccount(sessionInfo.providerId, accountName, sessionInfo.sessions[accountName]); return this.authenticationService.removeAccountSessions(sessionInfo.providerId, accountName, sessionInfo.sessions[accountName]);
})); }));
const providerSubMenuActions = [manageExtensionsAction]; const providerSubMenuActions = [manageExtensionsAction];

View file

@ -128,11 +128,11 @@ export interface IAuthenticationService {
getAllSessions(providerId: string, activateImmediate?: boolean): Promise<ReadonlyArray<AuthenticationSession>>; getAllSessions(providerId: string, activateImmediate?: boolean): Promise<ReadonlyArray<AuthenticationSession>>;
getLabel(providerId: string): string; getLabel(providerId: string): string;
supportsMultipleAccounts(providerId: string): boolean; supportsMultipleAccounts(providerId: string): boolean;
login(providerId: string, scopes: string[], activateImmediate?: boolean): Promise<AuthenticationSession>; createSession(providerId: string, scopes: string[], activateImmediate?: boolean): Promise<AuthenticationSession>;
logout(providerId: string, sessionId: string): Promise<void>; removeSession(providerId: string, sessionId: string): Promise<void>;
manageTrustedExtensionsForAccount(providerId: string, accountName: string): Promise<void>; manageTrustedExtensionsForAccount(providerId: string, accountName: string): Promise<void>;
signOutOfAccount(providerId: string, accountName: string, sessions: AuthenticationSession[]): Promise<void>; removeAccountSessions(providerId: string, accountName: string, sessions: AuthenticationSession[]): Promise<void>;
} }
export interface AllowedExtension { export interface AllowedExtension {
@ -473,7 +473,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
quickPick.placeholder = nls.localize('getSessionPlateholder', "Select an account for '{0}' to use or Esc to cancel", extensionName); quickPick.placeholder = nls.localize('getSessionPlateholder', "Select an account for '{0}' to use or Esc to cancel", extensionName);
quickPick.onDidAccept(async _ => { quickPick.onDidAccept(async _ => {
const session = quickPick.selectedItems[0].session ?? await this.login(providerId, availableSessions[0].scopes as string[]); const session = quickPick.selectedItems[0].session ?? await this.createSession(providerId, availableSessions[0].scopes as string[]);
const accountName = session.account.label; const accountName = session.account.label;
const allowList = readAllowedExtensions(this.storageService, providerId, accountName); const allowList = readAllowedExtensions(this.storageService, providerId, accountName);
@ -610,7 +610,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
handler: async (accessor) => { handler: async (accessor) => {
const authenticationService = accessor.get(IAuthenticationService); const authenticationService = accessor.get(IAuthenticationService);
const storageService = accessor.get(IStorageService); const storageService = accessor.get(IStorageService);
const session = await authenticationService.login(providerId, scopes); const session = await authenticationService.createSession(providerId, scopes);
// Add extension to allow list since user explicitly signed in on behalf of it // Add extension to allow list since user explicitly signed in on behalf of it
const allowList = readAllowedExtensions(storageService, providerId, session.account.label); const allowList = readAllowedExtensions(storageService, providerId, session.account.label);
@ -712,19 +712,19 @@ export class AuthenticationService extends Disposable implements IAuthentication
} }
} }
async login(id: string, scopes: string[], activateImmediate: boolean = false): Promise<AuthenticationSession> { async createSession(id: string, scopes: string[], activateImmediate: boolean = false): Promise<AuthenticationSession> {
try { try {
const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate); const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate);
return await authProvider.login(scopes); return await authProvider.createSession(scopes);
} catch (_) { } catch (_) {
throw new Error(`No authentication provider '${id}' is currently registered.`); throw new Error(`No authentication provider '${id}' is currently registered.`);
} }
} }
async logout(id: string, sessionId: string): Promise<void> { async removeSession(id: string, sessionId: string): Promise<void> {
const authProvider = this._authenticationProviders.get(id); const authProvider = this._authenticationProviders.get(id);
if (authProvider) { if (authProvider) {
return authProvider.logout(sessionId); return authProvider.removeSession(sessionId);
} else { } else {
throw new Error(`No authentication provider '${id}' is currently registered.`); throw new Error(`No authentication provider '${id}' is currently registered.`);
} }
@ -739,10 +739,10 @@ export class AuthenticationService extends Disposable implements IAuthentication
} }
} }
async signOutOfAccount(id: string, accountName: string, sessions: AuthenticationSession[]): Promise<void> { async removeAccountSessions(id: string, accountName: string, sessions: AuthenticationSession[]): Promise<void> {
const authProvider = this._authenticationProviders.get(id); const authProvider = this._authenticationProviders.get(id);
if (authProvider) { if (authProvider) {
return authProvider.signOut(accountName, sessions); return authProvider.removeAccountSessions(accountName, sessions);
} else { } else {
throw new Error(`No authentication provider '${id}' is currently registered.`); throw new Error(`No authentication provider '${id}' is currently registered.`);
} }

View file

@ -471,7 +471,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat
} }
let sessionId: string, accountName: string, accountId: string; let sessionId: string, accountName: string, accountId: string;
if (isAuthenticationProvider(result)) { if (isAuthenticationProvider(result)) {
const session = await this.authenticationService.login(result.id, result.scopes); const session = await this.authenticationService.createSession(result.id, result.scopes);
sessionId = session.id; sessionId = session.id;
accountName = session.account.label; accountName = session.account.label;
accountId = session.account.id; accountId = session.account.id;