Skip to content

Commit

Permalink
Revert "Add hook to remove account after sign out"
Browse files Browse the repository at this point in the history
This reverts commit 46b5f3c.
  • Loading branch information
lewis-sanchez committed Nov 26, 2023
1 parent 46b5f3c commit 5a401fa
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 34 deletions.
15 changes: 1 addition & 14 deletions src/sql/platform/accounts/common/accountActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,15 @@ export class GitHubCopilotSignOutAction extends Action {

constructor(
private _account: azdata.Account,
@IAccountManagementService private _accountManagementService: IAccountManagementService,
@INotificationService private _notificationService: INotificationService,
@IAuthenticationService private readonly authenticationService: IAuthenticationService
) {
super(GitHubCopilotSignOutAction.ID, GitHubCopilotSignOutAction.LABEL, 'remove-account-action codicon remove');
}

public override async run(): Promise<void> {
const removeAccount = async () => {
try {
await this._accountManagementService.updateAccountList(this._account)
} catch (err) {
this._notificationService.notify({
severity: Severity.Error,
message: localize('removeAccountFailed', "Failed to remove account after signing out")
});
}
};

const providerId = this._account.key.providerId;
const allSessions = await this.authenticationService.getSessions(providerId);
const sessionsForAccount = allSessions.filter(s => s.account.label === this._account.displayInfo.userId);
await this.authenticationService.removeAccountSessions(providerId, this._account.displayInfo.userId, sessionsForAccount, removeAccount);
await this.authenticationService.removeAccountSessions(providerId, this._account.displayInfo.userId, sessionsForAccount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,6 @@ export class AccountManagementService implements IAccountManagementService {
});
}

/**
* Updates the account list for a provider.
* @param provider Provider to update the account list for
*/
public updateAccountList(provider: AccountProviderWithMetadata): void {
this.fireAccountListUpdate(provider, false);
}

/**
* Removes all registered accounts
*/
Expand Down
8 changes: 1 addition & 7 deletions src/vs/workbench/api/browser/mainThreadAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class MainThreadAuthenticationProvider extends Disposable implements IAut
quickPick.show();
}

async removeAccountSessions(accountName: string, sessions: AuthenticationSession[], removeAccount: () => Promise<void> | undefined): Promise<void> { // {{SQL CARBON EDIT}} - Remove account delegate to remove an account when the user chooses to sign out.
async removeAccountSessions(accountName: string, sessions: AuthenticationSession[]): Promise<void> {
const accountUsages = readAccountUsages(this.storageService, this.id, accountName);

const { confirmed } = await this.dialogService.confirm({
Expand All @@ -112,12 +112,6 @@ export class MainThreadAuthenticationProvider extends Disposable implements IAut
await Promise.all(removeSessionPromises);
removeAccountUsage(this.storageService, this.id, accountName);
this.storageService.remove(`${this.id}-${accountName}`, StorageScope.APPLICATION);

// {{SQL CARBON EDIT}} - BEGIN - Invoking removeAccount delegate if a callback definition is defined.
if (removeAccount) {
await removeAccount();
}
// {{SQL CARBON EDIT}} - END
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
const signOutAction = disposables.add(new Action('signOut', localize('signOut', "Sign Out"), undefined, true, async () => {
const allSessions = await this.authenticationService.getSessions(providerId);
const sessionsForAccount = allSessions.filter(s => s.account.id === account.id);
return await this.authenticationService.removeAccountSessions(providerId, account.label, sessionsForAccount, undefined); // {{SQL CARBON EDIT}} - Explicitly making removeAccount delegate a no-op operation
return await this.authenticationService.removeAccountSessions(providerId, account.label, sessionsForAccount);
}));
providerSubMenuActions.push(signOutAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,10 @@ export class AuthenticationService extends Disposable implements IAuthentication
}
}

async removeAccountSessions(id: string, accountName: string, sessions: AuthenticationSession[], removeAccount: () => Promise<void> | undefined = undefined): Promise<void> { // {{SQL CARBON EDIT}} - Added removeAccount delegate to update accounts pane after session sign out
async removeAccountSessions(id: string, accountName: string, sessions: AuthenticationSession[]): Promise<void> {
const authProvider = this._authenticationProviders.get(id);
if (authProvider) {
return authProvider.removeAccountSessions(accountName, sessions, removeAccount); // {{SQL CARBON EDIT}} - Added removeAccount delegate to update accounts pane after session sign out
return authProvider.removeAccountSessions(accountName, sessions);
} else {
throw new Error(`No authentication provider '${id}' is currently registered.`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface IAuthenticationService {
removeSession(providerId: string, sessionId: string): Promise<void>;

manageTrustedExtensionsForAccount(providerId: string, accountName: string): Promise<void>;
removeAccountSessions(providerId: string, accountName: string, sessions: AuthenticationSession[], removeAccount: () => Promise<void> | undefined): Promise<void>; // {{SQL CARBON EDIT}} - Added removeAccount delegate to update the accounts pane
removeAccountSessions(providerId: string, accountName: string, sessions: AuthenticationSession[]): Promise<void>;
}

export interface IAuthenticationProviderCreateSessionOptions {
Expand All @@ -84,7 +84,7 @@ export interface IAuthenticationProvider {
readonly supportsMultipleAccounts: boolean;
dispose(): void;
manageTrustedExtensions(accountName: string): void;
removeAccountSessions(accountName: string, sessions: AuthenticationSession[], removeAccount: () => Promise<void> | undefined): Promise<void>; // {{SQL CARBON EDIT}} - Added removeAccount delegate to update the accounts pane
removeAccountSessions(accountName: string, sessions: AuthenticationSession[]): Promise<void>;
getSessions(scopes?: string[]): Promise<readonly AuthenticationSession[]>;
createSession(scopes: string[], options: IAuthenticationProviderCreateSessionOptions): Promise<AuthenticationSession>;
removeSession(sessionId: string): Promise<void>;
Expand Down

0 comments on commit 5a401fa

Please sign in to comment.