mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Rename login/logout to createSession/removeSession
This commit is contained in:
parent
ea865096f1
commit
eceff53351
|
@ -26,14 +26,14 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
onDidChangeSessions: onDidChangeSessions.event,
|
||||
getAllSessions: () => Promise.resolve(loginService.sessions),
|
||||
getSessions: (scopes: string[]) => loginService.getSessions(scopes),
|
||||
login: async (scopeList: string[]) => {
|
||||
createSession: async (scopeList: string[]) => {
|
||||
try {
|
||||
/* __GDPR__
|
||||
"login" : { }
|
||||
*/
|
||||
telemetryReporter.sendTelemetryEvent('login');
|
||||
|
||||
const session = await loginService.login(scopeList.sort().join(' '));
|
||||
const session = await loginService.createSession(scopeList.sort().join(' '));
|
||||
Logger.info('Login success!');
|
||||
onDidChangeSessions.fire({ added: [session], removed: [], changed: [] });
|
||||
return session;
|
||||
|
@ -57,14 +57,14 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
throw e;
|
||||
}
|
||||
},
|
||||
logout: async (id: string) => {
|
||||
removeSession: async (id: string) => {
|
||||
try {
|
||||
/* __GDPR__
|
||||
"logout" : { }
|
||||
*/
|
||||
telemetryReporter.sendTelemetryEvent('logout');
|
||||
|
||||
const session = await loginService.logout(id);
|
||||
const session = await loginService.removeSession(id);
|
||||
if (session) {
|
||||
onDidChangeSessions.fire({ added: [], removed: [session], changed: [] });
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ export class GitHubAuthenticationProvider {
|
|||
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 session = await this.tokenToSession(token, scopes.split(' '));
|
||||
await this.setToken(session);
|
||||
|
@ -190,7 +190,7 @@ export class GitHubAuthenticationProvider {
|
|||
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}`);
|
||||
const sessionIndex = this._sessions.findIndex(session => session.id === id);
|
||||
let session: vscode.AuthenticationSession | undefined;
|
||||
|
|
|
@ -144,7 +144,7 @@ export class AzureActiveDirectoryService {
|
|||
this.pollForReconnect(session.id, session.refreshToken, session.scope);
|
||||
}
|
||||
} else {
|
||||
await this.logout(session.id);
|
||||
await this.removeSession(session.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -193,7 +193,7 @@ export class AzureActiveDirectoryService {
|
|||
if (e.message === REFRESH_NETWORK_FAILURE) {
|
||||
// Ignore, will automatically retry on next poll.
|
||||
} 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 => {
|
||||
const matchesExisting = sessions.some(session => token.scope === session.scope && token.sessionId === session.id);
|
||||
if (!matchesExisting) {
|
||||
await this.logout(token.sessionId);
|
||||
await this.removeSession(token.sessionId);
|
||||
removed.push(this.convertToSessionSync(token));
|
||||
}
|
||||
}));
|
||||
|
@ -306,7 +306,7 @@ export class AzureActiveDirectoryService {
|
|||
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...');
|
||||
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.');
|
||||
|
@ -507,7 +507,7 @@ export class AzureActiveDirectoryService {
|
|||
this.pollForReconnect(token.sessionId, token.refreshToken, token.scope);
|
||||
}
|
||||
} else {
|
||||
await this.logout(token.sessionId);
|
||||
await this.removeSession(token.sessionId);
|
||||
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}'`);
|
||||
const token = this.removeInMemorySessionData(sessionId);
|
||||
let session: vscode.AuthenticationSession | undefined;
|
||||
|
|
|
@ -22,14 +22,14 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
onDidChangeSessions: onDidChangeSessions.event,
|
||||
getAllSessions: () => Promise.resolve(loginService.sessions),
|
||||
getSessions: (scopes: string[]) => loginService.getSessions(scopes),
|
||||
login: async (scopes: string[]) => {
|
||||
createSession: async (scopes: string[]) => {
|
||||
try {
|
||||
/* __GDPR__
|
||||
"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: [] });
|
||||
return session;
|
||||
} catch (e) {
|
||||
|
@ -41,14 +41,14 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
throw e;
|
||||
}
|
||||
},
|
||||
logout: async (id: string) => {
|
||||
removeSession: async (id: string) => {
|
||||
try {
|
||||
/* __GDPR__
|
||||
"logout" : { }
|
||||
*/
|
||||
telemetryReporter.sendTelemetryEvent('logout');
|
||||
|
||||
const session = await loginService.logout(id);
|
||||
const session = await loginService.removeSession(id);
|
||||
if (session) {
|
||||
onDidChangeSessions.fire({ added: [], removed: [session], changed: [] });
|
||||
}
|
||||
|
|
4
src/vs/vscode.proposed.d.ts
vendored
4
src/vs/vscode.proposed.d.ts
vendored
|
@ -82,14 +82,14 @@ declare module 'vscode' {
|
|||
* Prompts a user to login.
|
||||
*/
|
||||
// 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.
|
||||
* @param sessionId The session id to log out of
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
logout(sessionId: string): Thenable<void>;
|
||||
removeSession(sessionId: string): Thenable<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,7 @@ export class MainThreadAuthenticationProvider extends Disposable {
|
|||
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 result = await this.dialogService.confirm({
|
||||
|
@ -82,8 +82,8 @@ export class MainThreadAuthenticationProvider extends Disposable {
|
|||
});
|
||||
|
||||
if (result.confirmed) {
|
||||
const logoutPromises = sessions.map(session => this.logout(session.id));
|
||||
await Promise.all(logoutPromises);
|
||||
const removeSessionPromises = sessions.map(session => this.removeSession(session.id));
|
||||
await Promise.all(removeSessionPromises);
|
||||
removeAccountUsage(this.storageService, this.id, accountName);
|
||||
this.storageService.remove(`${this.id}-${accountName}`, StorageScope.GLOBAL);
|
||||
}
|
||||
|
@ -97,12 +97,12 @@ export class MainThreadAuthenticationProvider extends Disposable {
|
|||
return this._proxy.$getAllSessions(this.id);
|
||||
}
|
||||
|
||||
login(scopes: string[]): Promise<modes.AuthenticationSession> {
|
||||
return this._proxy.$login(this.id, scopes);
|
||||
createSession(scopes: string[]): Promise<modes.AuthenticationSession> {
|
||||
return this._proxy.$createSession(this.id, scopes);
|
||||
}
|
||||
|
||||
async logout(sessionId: string): Promise<void> {
|
||||
await this._proxy.$logout(this.id, sessionId);
|
||||
async removeSession(sessionId: string): Promise<void> {
|
||||
await this._proxy.$removeSession(this.id, sessionId);
|
||||
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);
|
||||
}
|
||||
|
||||
$logout(providerId: string, sessionId: string): Promise<void> {
|
||||
return this.authenticationService.logout(providerId, sessionId);
|
||||
$removeSession(providerId: string, sessionId: string): Promise<void> {
|
||||
return this.authenticationService.removeSession(providerId, sessionId);
|
||||
}
|
||||
private async loginPrompt(providerName: string, extensionName: string): Promise<boolean> {
|
||||
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.');
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
await this.authenticationService.requestNewSession(providerId, scopes, extensionId, extensionName);
|
||||
|
|
|
@ -230,7 +230,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
},
|
||||
logout(providerId: string, sessionId: string): Thenable<void> {
|
||||
checkProposedApiEnabled(extension);
|
||||
return extHostAuthentication.logout(providerId, sessionId);
|
||||
return extHostAuthentication.removeSession(providerId, sessionId);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ export interface MainThreadAuthenticationShape extends IDisposable {
|
|||
$ensureProvider(id: string): Promise<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>;
|
||||
$logout(providerId: string, sessionId: string): Promise<void>;
|
||||
$removeSession(providerId: string, sessionId: string): Promise<void>;
|
||||
}
|
||||
|
||||
export interface MainThreadSecretStateShape extends IDisposable {
|
||||
|
@ -1128,8 +1128,8 @@ export interface ExtHostLabelServiceShape {
|
|||
export interface ExtHostAuthenticationShape {
|
||||
$getAllSessions(id: string): Promise<ReadonlyArray<modes.AuthenticationSession>>;
|
||||
$getSessions(id: string, scopes: string[]): Promise<ReadonlyArray<modes.AuthenticationSession>>;
|
||||
$login(id: string, scopes: string[]): Promise<modes.AuthenticationSession>;
|
||||
$logout(id: string, sessionId: string): Promise<void>;
|
||||
$createSession(id: string, scopes: string[]): Promise<modes.AuthenticationSession>;
|
||||
$removeSession(id: string, sessionId: string): Promise<void>;
|
||||
$onDidChangeAuthenticationSessions(id: string, label: string, event: modes.AuthenticationSessionsChangeEvent): Promise<void>;
|
||||
$onDidChangeAuthenticationProviders(added: modes.AuthenticationProviderInformation[], removed: modes.AuthenticationProviderInformation[]): Promise<void>;
|
||||
$setProviders(providers: modes.AuthenticationProviderInformation[]): Promise<void>;
|
||||
|
|
|
@ -87,13 +87,13 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
|
|||
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);
|
||||
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 {
|
||||
|
@ -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);
|
||||
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}`);
|
||||
}
|
||||
|
||||
$logout(providerId: string, sessionId: string): Promise<void> {
|
||||
$removeSession(providerId: string, sessionId: string): Promise<void> {
|
||||
const providerData = this._authenticationProviders.get(providerId);
|
||||
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}`);
|
||||
|
|
|
@ -240,7 +240,7 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
|
|||
}));
|
||||
|
||||
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];
|
||||
|
|
|
@ -128,11 +128,11 @@ export interface IAuthenticationService {
|
|||
getAllSessions(providerId: string, activateImmediate?: boolean): Promise<ReadonlyArray<AuthenticationSession>>;
|
||||
getLabel(providerId: string): string;
|
||||
supportsMultipleAccounts(providerId: string): boolean;
|
||||
login(providerId: string, scopes: string[], activateImmediate?: boolean): Promise<AuthenticationSession>;
|
||||
logout(providerId: string, sessionId: string): Promise<void>;
|
||||
createSession(providerId: string, scopes: string[], activateImmediate?: boolean): Promise<AuthenticationSession>;
|
||||
removeSession(providerId: string, sessionId: 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 {
|
||||
|
@ -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.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 allowList = readAllowedExtensions(this.storageService, providerId, accountName);
|
||||
|
@ -610,7 +610,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
|
|||
handler: async (accessor) => {
|
||||
const authenticationService = accessor.get(IAuthenticationService);
|
||||
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
|
||||
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 {
|
||||
const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate);
|
||||
return await authProvider.login(scopes);
|
||||
return await authProvider.createSession(scopes);
|
||||
} catch (_) {
|
||||
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);
|
||||
if (authProvider) {
|
||||
return authProvider.logout(sessionId);
|
||||
return authProvider.removeSession(sessionId);
|
||||
} else {
|
||||
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);
|
||||
if (authProvider) {
|
||||
return authProvider.signOut(accountName, sessions);
|
||||
return authProvider.removeAccountSessions(accountName, sessions);
|
||||
} else {
|
||||
throw new Error(`No authentication provider '${id}' is currently registered.`);
|
||||
}
|
||||
|
|
|
@ -471,7 +471,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat
|
|||
}
|
||||
let sessionId: string, accountName: string, accountId: string;
|
||||
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;
|
||||
accountName = session.account.label;
|
||||
accountId = session.account.id;
|
||||
|
|
Loading…
Reference in a new issue