Skip to content

Commit

Permalink
Remove onSuccessfulLogin callback
Browse files Browse the repository at this point in the history
  • Loading branch information
alec-livefront committed Nov 30, 2024
1 parent 794a215 commit 192f06e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import {
SsoComponentService,
} from "@bitwarden/auth/angular";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { ClientType } from "@bitwarden/common/enums";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";

import { BrowserApi } from "../../../platform/browser/browser-api";

/**
* This service is used to handle the SSO login process for the browser extension.
*/
Expand All @@ -27,7 +24,6 @@ export class ExtensionSsoComponentService
{
clientId: SsoClientType;
redirectUri: string;
onSuccessfulLogin: () => Promise<void>;
onSuccessfulLoginTde: () => Promise<void>;
onSuccessfulLoginTdeNavigate: () => Promise<void>;

Expand All @@ -46,21 +42,6 @@ export class ExtensionSsoComponentService
this.redirectUri = env.getWebVaultUrl() + "/sso-connector.html";
});

this.onSuccessfulLogin = async () => {
try {
await this.syncService.fullSync(true, true);
} catch (error) {
this.logService.error("Error syncing after SSO login:", error);
}

// If the vault is unlocked then this will clear keys from memory, which we don't want to do
if ((await this.authService.getAuthStatus()) !== AuthenticationStatus.Unlocked) {
BrowserApi.reloadOpenWindows();
}

this.window.close();
};

this.onSuccessfulLoginTde = async () => {
try {
await this.syncService.fullSync(true, true);
Expand Down
10 changes: 0 additions & 10 deletions apps/desktop/src/auth/login/desktop-sso-component.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class DesktopSsoComponentService
* The redirect URI for the SSO component service.
*/
redirectUri: string;
onSuccessfulLogin: () => Promise<void>;
onSuccessfulLoginTde: () => Promise<void>;

constructor(
Expand All @@ -35,15 +34,6 @@ export class DesktopSsoComponentService
) {
super();
this.clientId = ClientType.Desktop;
// this.redirectUri = "bitwarden://sso-callback";

this.onSuccessfulLogin = async () => {
try {
await this.syncService.fullSync(true, true);
} catch (error) {
this.logService.error("Error syncing after SSO login:", error);
}
};

this.onSuccessfulLoginTde = async () => {
try {
Expand Down
5 changes: 5 additions & 0 deletions libs/auth/src/angular/sso/default-sso-component.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export class DefaultSsoComponentService implements SsoComponentService {
* Default undefined implementation as extension and desktop don't need to close windows.
*/
closeWindow: () => undefined | Promise<void>;

/**
* Default undefined implementation as extension and desktop don't need to prevent clearing keys.
*/
preventClearingKeys?: () => undefined | Promise<void>;
}
6 changes: 5 additions & 1 deletion libs/auth/src/angular/sso/sso-component.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ export abstract class SsoComponentService {
/**
* Navigation callbacks
*/
onSuccessfulLogin?(): Promise<void>;
onSuccessfulLoginTde?(): Promise<void>;

/**
* Closes the window.
*/
closeWindow?(): Promise<void>;

/**
* Prevents clearing keys from memory.
*/
preventClearingKeys?(): Promise<void>;
}
12 changes: 8 additions & 4 deletions libs/auth/src/angular/sso/sso.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import {
AsyncActionsModule,
ButtonModule,
Expand Down Expand Up @@ -114,6 +115,7 @@ export class SsoComponent implements OnInit {
private accountService: AccountService,
private toastService: ToastService,
private ssoComponentService: SsoComponentService,
private syncService: SyncService,
) {
this.redirectUri = window.location.origin + "/sso-connector.html";
}
Expand Down Expand Up @@ -480,12 +482,14 @@ export class SsoComponent implements OnInit {
}

private async handleSuccessfulLogin() {
if (this.ssoComponentService.onSuccessfulLogin) {
// Don't await b/c causes hang on desktop & browser
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.ssoComponentService.onSuccessfulLogin();
try {
await this.syncService.fullSync(true, true);
} catch (error) {
this.logService.error("Error syncing after TDE SSO login:", error);
}

await this.ssoComponentService.preventClearingKeys?.();

await this.navigateViaCallbackOrRoute(async () => {}, ["lock"]);
}

Expand Down

0 comments on commit 192f06e

Please sign in to comment.