1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Code cleanup to remove sessionId from login component

This commit is contained in:
gbubemismith
2023-08-22 16:22:45 -04:00
parent 905ac1987c
commit ef4a1d9b7b
4 changed files with 22 additions and 25 deletions

View File

@@ -20,9 +20,6 @@ export class HomeComponent implements OnInit, OnDestroy {
private destroyed$: Subject<void> = new Subject(); private destroyed$: Subject<void> = new Subject();
loginInitiated = false; loginInitiated = false;
//use this to redirect somehwere else after login
redirectPath: string;
sessionId: string;
formGroup = this.formBuilder.group({ formGroup = this.formBuilder.group({
email: ["", [Validators.required, Validators.email]], email: ["", [Validators.required, Validators.email]],
rememberEmail: [false], rememberEmail: [false],
@@ -40,11 +37,6 @@ export class HomeComponent implements OnInit, OnDestroy {
) {} ) {}
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.route?.queryParams.pipe(takeUntil(this.destroyed$)).subscribe((params) => {
this.redirectPath = params?.redirectPath;
this.sessionId = params?.sessionId;
});
let savedEmail = this.loginService.getEmail(); let savedEmail = this.loginService.getEmail();
const rememberEmail = this.loginService.getRememberEmail(); const rememberEmail = this.loginService.getRememberEmail();
@@ -90,11 +82,12 @@ export class HomeComponent implements OnInit, OnDestroy {
this.loginService.setEmail(this.formGroup.value.email); this.loginService.setEmail(this.formGroup.value.email);
this.loginService.setRememberEmail(this.formGroup.value.rememberEmail); this.loginService.setRememberEmail(this.formGroup.value.rememberEmail);
// const decodedRedirectUrl = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl);
// console.log(decodedRedirectUrl, this.route);
this.router.navigate(["login"], { this.router.navigate(["login"], {
queryParams: { queryParams: {
email: this.formGroup.value.email, email: this.formGroup.value.email,
redirectPath: this.redirectPath, redirectUrl: this.route.snapshot.queryParams.redirectUrl,
sessionId: this.sessionId,
}, },
}); });
} }

View File

@@ -352,7 +352,7 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi
this.popout = await this.generatePopOut(authStatus); this.popout = await this.generatePopOut(authStatus);
if (this.popout.type === "window") { if (this.popout.type === "window") {
const popoutWindow = this.popout as { type: "window"; window: chrome.windows.Window }; const popoutWindow = this.popout;
this.windowClosed$ this.windowClosed$
.pipe( .pipe(
filter((windowId) => popoutWindow.window.id === windowId), filter((windowId) => popoutWindow.window.id === windowId),
@@ -363,7 +363,7 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi
this.abort(); this.abort();
}); });
} else if (this.popout.type === "tab") { } else if (this.popout.type === "tab") {
const popoutTab = this.popout as { type: "tab"; tab: chrome.tabs.Tab }; const popoutTab = this.popout;
this.tabClosed$ this.tabClosed$
.pipe( .pipe(
filter((tabId) => popoutTab.tab.id === tabId), filter((tabId) => popoutTab.tab.id === tabId),
@@ -379,6 +379,15 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi
} }
private async generatePopOut(authStatus: AuthenticationStatus) { 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; let path: string;
switch (authStatus) { switch (authStatus) {
@@ -389,21 +398,16 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi
path = "lock"; path = "lock";
break; break;
default: default:
path = "fido2"; throw new Error(`Unexpected auth status: ${authStatus}`);
} }
const queryParams = new URLSearchParams({ sessionId: this.sessionId }); const redirectUrlParams = new URLSearchParams({ sessionId: this.sessionId });
if ( const redirectUrl = `/fido2?${redirectUrlParams.toString()}`;
authStatus === AuthenticationStatus.LoggedOut ||
authStatus === AuthenticationStatus.Locked
) {
queryParams.append("redirectPath", "fido2");
}
const queryString = queryParams.toString(); const queryParams = new URLSearchParams({ redirectUrl });
return this.popupUtilsService.popOut( return this.popupUtilsService.popOut(
null, null,
`popup/index.html?uilocation=popout#/${path}?${queryString}`, `popup/index.html?uilocation=popout#/${path}?${queryParams.toString()}`,
{ center: true } { center: true }
); );
} }

View File

@@ -83,7 +83,7 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
} }
if (qParams.sessionId != null) { if (qParams.sessionId != null) {
this.sessionId = qParams?.sessionId; this.sessionId = qParams.sessionId;
} }
}); });

View File

@@ -84,7 +84,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
} }
//TODO: uncomment this when working on the login flow ticket //TODO: uncomment this when working on the login flow ticket
// await userInterfaceSession.ensureUnlockedVault(); await userInterfaceSession.ensureUnlockedVault();
const existingCipherIds = await this.findExcludedCredentials( const existingCipherIds = await this.findExcludedCredentials(
params.excludeCredentialDescriptorList params.excludeCredentialDescriptorList
@@ -239,7 +239,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
let cipherOptions: CipherView[]; let cipherOptions: CipherView[];
//TODO: uncomment this when working on the login flow ticket //TODO: uncomment this when working on the login flow ticket
// await userInterfaceSession.ensureUnlockedVault(); await userInterfaceSession.ensureUnlockedVault();
// eslint-disable-next-line no-empty // eslint-disable-next-line no-empty
if (params.allowCredentialDescriptorList?.length > 0) { if (params.allowCredentialDescriptorList?.length > 0) {