1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Updated components to use browserRouterService for routing to previous page

This commit is contained in:
gbubemismith
2023-09-04 15:30:44 -04:00
parent c204c70e6b
commit a655b96bfe
7 changed files with 39 additions and 87 deletions

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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");

View File

@@ -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

View File

@@ -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 }
);
}

View File

@@ -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]);
}
}

View File

@@ -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) {