mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
fix(sso-config): (Auth) [PM-26927] Bugfix for Key Connector URL (#16863)
The Key Connector URL was getting overwritten back to the default URL on `submit()` because `valueChanges` gets triggered during `submit()`. This fix adds a check to make sure we only set the default URL when changing TO Key Connector from a different decryption option. In other words, don't overwrite back to the default URL during `submit()`. Also removes the trailing slash `/` from the default URL.
This commit is contained in:
@@ -9,7 +9,15 @@ import {
|
|||||||
Validators,
|
Validators,
|
||||||
} from "@angular/forms";
|
} from "@angular/forms";
|
||||||
import { ActivatedRoute } from "@angular/router";
|
import { ActivatedRoute } from "@angular/router";
|
||||||
import { concatMap, firstValueFrom, Subject, switchMap, takeUntil } from "rxjs";
|
import {
|
||||||
|
concatMap,
|
||||||
|
firstValueFrom,
|
||||||
|
pairwise,
|
||||||
|
startWith,
|
||||||
|
Subject,
|
||||||
|
switchMap,
|
||||||
|
takeUntil,
|
||||||
|
} from "rxjs";
|
||||||
|
|
||||||
import { ControlsOf } from "@bitwarden/angular/types/controls-of";
|
import { ControlsOf } from "@bitwarden/angular/types/controls-of";
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
@@ -263,18 +271,27 @@ export class SsoComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listenForKeyConnectorSelection() {
|
listenForKeyConnectorSelection() {
|
||||||
|
const memberDecryptionTypeOnInit = this.ssoConfigForm?.controls?.memberDecryptionType.value;
|
||||||
|
|
||||||
this.ssoConfigForm?.controls?.memberDecryptionType.valueChanges
|
this.ssoConfigForm?.controls?.memberDecryptionType.valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(async (memberDecryptionType) => {
|
startWith(memberDecryptionTypeOnInit),
|
||||||
if (memberDecryptionType === MemberDecryptionType.KeyConnector) {
|
pairwise(),
|
||||||
|
switchMap(async ([prevMemberDecryptionType, newMemberDecryptionType]) => {
|
||||||
|
// Only pre-populate a default URL when changing TO Key Connector from a different decryption type.
|
||||||
|
// ValueChanges gets re-triggered during the submit() call, so we need a !== check
|
||||||
|
// to prevent a custom URL from getting overwritten back to the default on a submit().
|
||||||
|
if (
|
||||||
|
prevMemberDecryptionType !== MemberDecryptionType.KeyConnector &&
|
||||||
|
newMemberDecryptionType === MemberDecryptionType.KeyConnector
|
||||||
|
) {
|
||||||
// Pre-populate a default key connector URL (user can still change it)
|
// Pre-populate a default key connector URL (user can still change it)
|
||||||
const env = await firstValueFrom(this.environmentService.environment$);
|
const env = await firstValueFrom(this.environmentService.environment$);
|
||||||
const webVaultUrl = env.getWebVaultUrl();
|
const webVaultUrl = env.getWebVaultUrl();
|
||||||
const defaultKeyConnectorUrl = webVaultUrl + "/key-connector/";
|
const defaultKeyConnectorUrl = webVaultUrl + "/key-connector";
|
||||||
|
|
||||||
this.ssoConfigForm.controls.keyConnectorUrl.setValue(defaultKeyConnectorUrl);
|
this.ssoConfigForm.controls.keyConnectorUrl.setValue(defaultKeyConnectorUrl);
|
||||||
} else {
|
} else if (newMemberDecryptionType !== MemberDecryptionType.KeyConnector) {
|
||||||
// Otherwise clear the key connector URL
|
|
||||||
this.ssoConfigForm.controls.keyConnectorUrl.setValue("");
|
this.ssoConfigForm.controls.keyConnectorUrl.setValue("");
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user