From 383a4851b6755b959f91774d8e9b60991122e471 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Fri, 28 Jun 2024 15:35:10 +0200 Subject: [PATCH] Add auto submit on identifier query parameter (#9803) --- apps/web/src/app/auth/sso.component.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/auth/sso.component.ts b/apps/web/src/app/auth/sso.component.ts index 69bfd0a8c48..b1b22ecafcc 100644 --- a/apps/web/src/app/auth/sso.component.ts +++ b/apps/web/src/app/auth/sso.component.ts @@ -1,6 +1,7 @@ import { Component } from "@angular/core"; import { FormControl, FormGroup, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; +import { firstValueFrom } from "rxjs"; import { first } from "rxjs/operators"; import { SsoComponent as BaseSsoComponent } from "@bitwarden/angular/auth/components/sso.component"; @@ -92,6 +93,7 @@ export class SsoComponent extends BaseSsoComponent { if (qParams.identifier != null) { // SSO Org Identifier in query params takes precedence over claimed domains this.identifierFormControl.setValue(qParams.identifier); + await this.submit(); } else { // Note: this flow is written for web but both browser and desktop // redirect here on SSO button click. @@ -145,11 +147,21 @@ export class SsoComponent extends BaseSsoComponent { return; } + const autoSubmit = (await firstValueFrom(this.route.queryParams)).identifier != null; + this.identifier = this.identifierFormControl.value; await this.ssoLoginService.setOrganizationSsoIdentifier(this.identifier); if (this.clientId === "browser") { document.cookie = `ssoHandOffMessage=${this.i18nService.t("ssoHandOff")};SameSite=strict`; } - await Object.getPrototypeOf(this).submit.call(this); + try { + await Object.getPrototypeOf(this).submit.call(this); + } catch (error) { + if (autoSubmit) { + await this.router.navigate(["/login"]); + } else { + this.validationService.showError(error); + } + } }; }