Add auto submit on identifier query parameter (#9803)

This commit is contained in:
Bernd Schoolmann 2024-06-28 15:35:10 +02:00 committed by GitHub
parent 09c6995e10
commit 383a4851b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

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