diff --git a/apps/browser/src/auth/popup/home.component.ts b/apps/browser/src/auth/popup/home.component.ts index a76e5b0b788..2b1cb89eb63 100644 --- a/apps/browser/src/auth/popup/home.component.ts +++ b/apps/browser/src/auth/popup/home.component.ts @@ -81,16 +81,7 @@ export class HomeComponent implements OnInit, OnDestroy { this.loginService.setEmail(this.formGroup.value.email); this.loginService.setRememberEmail(this.formGroup.value.rememberEmail); - - const queryParams: { email: string; redirectUrl?: string } = { - email: this.formGroup.value.email, - }; - - if (this.route.snapshot.queryParams.redirectUrl) { - queryParams.redirectUrl = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl); - } - - this.router.navigate(["login"], { queryParams }); + this.router.navigate(["login"], { queryParams: { email: this.formGroup.value.email } }); } get selfHostedDomain() { diff --git a/apps/browser/src/auth/popup/lock.component.ts b/apps/browser/src/auth/popup/lock.component.ts index f0c435a6877..dc3341a75dd 100644 --- a/apps/browser/src/auth/popup/lock.component.ts +++ b/apps/browser/src/auth/popup/lock.component.ts @@ -1,5 +1,5 @@ import { Component, NgZone } from "@angular/core"; -import { ActivatedRoute, Router } from "@angular/router"; +import { Router } from "@angular/router"; import { LockComponent as BaseLockComponent } from "@bitwarden/angular/auth/components/lock.component"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; @@ -22,6 +22,7 @@ import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/pass import { DialogService } from "@bitwarden/components"; import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors"; +import { BrowserRouterService } from "../../platform/popup/services/browser-router.service"; @Component({ selector: "app-lock", @@ -50,10 +51,10 @@ export class LockComponent extends BaseLockComponent { policyService: InternalPolicyService, passwordStrengthService: PasswordStrengthServiceAbstraction, private authService: AuthService, - route: ActivatedRoute, dialogService: DialogService, deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction, - userVerificationService: UserVerificationService + userVerificationService: UserVerificationService, + private routerService: BrowserRouterService ) { super( router, @@ -71,13 +72,21 @@ export class LockComponent extends BaseLockComponent { policyApiService, policyService, passwordStrengthService, - route, dialogService, deviceTrustCryptoService, userVerificationService ); this.successRoute = "/tabs/current"; this.isInitialLockScreen = (window as any).previousPopupUrl == null; + + super.onSuccessfulSubmit = async () => { + const previousUrl = await this.routerService.getPreviousUrl(); + if (previousUrl) { + this.router.navigateByUrl(previousUrl); + } else { + this.router.navigate([this.successRoute]); + } + }; } async ngOnInit() { diff --git a/apps/browser/src/auth/popup/login.component.ts b/apps/browser/src/auth/popup/login.component.ts index 279c006669c..1cca374db8a 100644 --- a/apps/browser/src/auth/popup/login.component.ts +++ b/apps/browser/src/auth/popup/login.component.ts @@ -19,6 +19,7 @@ import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/ge import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { flagEnabled } from "../../platform/flags"; +import { BrowserRouterService } from "../../platform/popup/services/browser-router.service"; @Component({ selector: "app-login", @@ -44,7 +45,8 @@ export class LoginComponent extends BaseLoginComponent { formBuilder: FormBuilder, formValidationErrorService: FormValidationErrorsService, route: ActivatedRoute, - loginService: LoginService + loginService: LoginService, + private routerService: BrowserRouterService ) { super( devicesApiService, @@ -71,29 +73,14 @@ export class LoginComponent extends BaseLoginComponent { super.successRoute = "/tabs/vault"; super.onSuccessfulLoginNavigate = async () => { - // The `redirectUrl` parameter determines the target route after a successful login. - // If provided in the URL's query parameters, the user will be redirected - // to the specified path once they are authenticated. - this.successRoute = this.route.snapshot.queryParams.redirectUrl - ? decodeURIComponent(this.route.snapshot.queryParams.redirectUrl) - : this.successRoute; + const previousUrl = await this.routerService.getPreviousUrl(); - this.router.navigateByUrl(this.successRoute); - }; - - super.onSuccessfulLoginTwoFactorNavigate = async () => { - // The `redirectUrl` parameter determines the target route after a successful login. - // If provided in the URL's query parameters, the user will be redirected - // to the specified path once they are authenticated. - const redirectUrl = this.route.snapshot.queryParams.redirectUrl - ? decodeURIComponent(this.route.snapshot.queryParams.redirectUrl) - : undefined; - - this.router.navigate([this.twoFactorRoute], { - queryParams: { - redirectUrl: redirectUrl, - }, - }); + if (previousUrl) { + this.router.navigateByUrl(previousUrl); + } else { + this.loginService.clearValues(); + this.router.navigate([this.successRoute]); + } }; this.showPasswordless = flagEnabled("showPasswordless"); diff --git a/apps/browser/src/auth/popup/two-factor.component.ts b/apps/browser/src/auth/popup/two-factor.component.ts index e74872bfe05..13755fe2eb9 100644 --- a/apps/browser/src/auth/popup/two-factor.component.ts +++ b/apps/browser/src/auth/popup/two-factor.component.ts @@ -22,6 +22,7 @@ import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.serv import { DialogService } from "@bitwarden/components"; import { BrowserApi } from "../../platform/browser/browser-api"; +import { BrowserRouterService } from "../../platform/popup/services/browser-router.service"; import { PopupUtilsService } from "../../popup/services/popup-utils.service"; const BroadcasterSubscriptionId = "TwoFactorComponent"; @@ -52,6 +53,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { loginService: LoginService, configService: ConfigServiceAbstraction, private dialogService: DialogService, + private routerService: BrowserRouterService, @Inject(WINDOW) protected win: Window ) { super( @@ -85,14 +87,13 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { super.successRoute = "/tabs/vault"; super.onSuccessfulLoginNavigate = async () => { - // The `redirectUrl` parameter determines the target route after a successful login. - // If provided in the URL's query parameters, the user will be redirected - // to the specified path once they are authenticated. - this.successRoute = this.route.snapshot.queryParams.redirectUrl - ? decodeURIComponent(this.route.snapshot.queryParams.redirectUrl) - : this.successRoute; + const previousUrl = await this.routerService.getPreviousUrl(); - this.router.navigateByUrl(this.successRoute); + if (previousUrl) { + this.router.navigateByUrl(previousUrl); + } else { + this.router.navigate([this.successRoute]); + } }; // FIXME: Chromium 110 has broken WebAuthn support in extensions via an iframe diff --git a/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts b/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts index 91c17ee2851..bf41fa930a9 100644 --- a/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts +++ b/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts @@ -15,7 +15,6 @@ import { } from "rxjs"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; -import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { UserRequestedFallbackAbortReason } from "@bitwarden/common/vault/abstractions/fido2/fido2-client.service.abstraction"; import { @@ -348,8 +347,7 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi ) ); - const authStatus = await this.authService.getAuthStatus(); - this.popout = await this.generatePopOut(authStatus); + this.popout = await this.generatePopOut(); if (this.popout.type === "window") { const popoutWindow = this.popout; @@ -378,36 +376,11 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi await connectPromise; } - private async generatePopOut(authStatus: AuthenticationStatus) { - if (authStatus === AuthenticationStatus.Unlocked) { - const queryParams = new URLSearchParams({ sessionId: this.sessionId }); - return this.popupUtilsService.popOut( - null, - `popup/index.html?uilocation=popout#/fido2?${queryParams.toString()}`, - { center: true } - ); - } - - let path: string; - - switch (authStatus) { - case AuthenticationStatus.LoggedOut: - path = "home"; - break; - case AuthenticationStatus.Locked: - path = "lock"; - break; - default: - throw new Error(`Unexpected auth status: ${authStatus}`); - } - - const redirectUrlParams = new URLSearchParams({ sessionId: this.sessionId }); - const redirectUrl = `/fido2?${redirectUrlParams.toString()}`; - - const queryParams = new URLSearchParams({ redirectUrl }); + private async generatePopOut() { + const queryParams = new URLSearchParams({ sessionId: this.sessionId }); return this.popupUtilsService.popOut( null, - `popup/index.html?uilocation=popout#/${path}?${queryParams.toString()}`, + `popup/index.html?uilocation=popout#/fido2?${queryParams.toString()}`, { center: true } ); } diff --git a/libs/angular/src/auth/components/lock.component.ts b/libs/angular/src/auth/components/lock.component.ts index 57f2a61b500..46927923787 100644 --- a/libs/angular/src/auth/components/lock.component.ts +++ b/libs/angular/src/auth/components/lock.component.ts @@ -1,5 +1,5 @@ import { Directive, NgZone, OnDestroy, OnInit } from "@angular/core"; -import { ActivatedRoute, Router } from "@angular/router"; +import { Router } from "@angular/router"; import { firstValueFrom, Subject } from "rxjs"; import { concatMap, take, takeUntil } from "rxjs/operators"; @@ -43,7 +43,6 @@ export class LockComponent implements OnInit, OnDestroy { supportsBiometric: boolean; biometricLock: boolean; biometricText: string; - redirectUrl: string; protected successRoute = "vault"; protected forcePasswordResetRoute = "update-temp-password"; @@ -72,7 +71,6 @@ export class LockComponent implements OnInit, OnDestroy { protected policyApiService: PolicyApiServiceAbstraction, protected policyService: InternalPolicyService, protected passwordStrengthService: PasswordStrengthServiceAbstraction, - protected route: ActivatedRoute, protected dialogService: DialogService, protected deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction, protected userVerificationService: UserVerificationService @@ -315,13 +313,6 @@ export class LockComponent implements OnInit, OnDestroy { await this.stateService.setEverBeenUnlocked(true); this.messagingService.send("unlocked"); - // The `redirectUrl` parameter determines the target route after a successful login. - // If provided in the URL's query parameters, the user will be redirected - // to the specified path once they are authenticated. - if (this.route.snapshot.queryParams.redirectUrl) { - this.successRoute = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl); - } - if (evaluatePasswordAfterUnlock) { try { // If we do not have any saved policies, attempt to load them from the service @@ -347,7 +338,7 @@ export class LockComponent implements OnInit, OnDestroy { if (this.onSuccessfulSubmit != null) { await this.onSuccessfulSubmit(); } else if (this.router != null) { - this.router.navigateByUrl(this.successRoute); + this.router.navigate([this.successRoute]); } } diff --git a/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts b/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts index 005d2db6428..29e8d628b62 100644 --- a/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts +++ b/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts @@ -239,7 +239,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr let cipherOptions: CipherView[]; //TODO: uncomment this when working on the login flow ticket - await userInterfaceSession.ensureUnlockedVault(); + // await userInterfaceSession.ensureUnlockedVault(); // eslint-disable-next-line no-empty if (params.allowCredentialDescriptorList?.length > 0) {