1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 19:53:43 +00:00

[PM-23243] In sync response and identity success response add MasterPasswordUnlockDataResponse in decryption options response model. (#15916)

* added master password unlock and decryption option fields into identity token connect response

* incorrect master password unlock response parsing

* use sdk

* use sdk

* better type checking on response parsing

* not using sdk

* revert of bad merge conflicts

* revert of bad merge conflicts

* master password unlock setter in state

* unit test coverage for responses processing

* master password unlock in identity user decryption options

* unit test coverage

* unit test coverage

* unit test coverage

* unit test coverage

* lint error

* set master password unlock data in state on identity response and sync response

* revert change in auth's user decryption options

* remove unnecessary cast

* better docs

* change to relative imports

* MasterPasswordUnlockData serialization issue

* explicit undefined type for `syncUserDecryption`

* incorrect identity token response tests
This commit is contained in:
Maciej Zieniuk
2025-09-05 16:13:56 +02:00
committed by GitHub
parent 6c5e15eb28
commit 203a24723b
24 changed files with 852 additions and 37 deletions

View File

@@ -12,8 +12,8 @@ import { UserDecryptionOptionsResponse } from "./user-decryption-options/user-de
export class IdentityTokenResponse extends BaseResponse {
accessToken: string;
expiresIn: number;
refreshToken: string;
expiresIn?: number;
refreshToken?: string;
tokenType: string;
resetMasterPassword: boolean;
@@ -26,14 +26,30 @@ export class IdentityTokenResponse extends BaseResponse {
apiUseKeyConnector: boolean;
keyConnectorUrl: string;
userDecryptionOptions: UserDecryptionOptionsResponse;
userDecryptionOptions?: UserDecryptionOptionsResponse;
constructor(response: any) {
constructor(response: unknown) {
super(response);
this.accessToken = response.access_token;
this.expiresIn = response.expires_in;
this.refreshToken = response.refresh_token;
this.tokenType = response.token_type;
const accessToken = this.getResponseProperty("access_token");
if (accessToken == null || typeof accessToken !== "string") {
throw new Error("Identity response does not contain a valid access token");
}
const tokenType = this.getResponseProperty("token_type");
if (tokenType == null || typeof tokenType !== "string") {
throw new Error("Identity response does not contain a valid token type");
}
this.accessToken = accessToken;
this.tokenType = tokenType;
const expiresIn = this.getResponseProperty("expires_in");
if (expiresIn != null && typeof expiresIn === "number") {
this.expiresIn = expiresIn;
}
const refreshToken = this.getResponseProperty("refresh_token");
if (refreshToken != null && typeof refreshToken === "string") {
this.refreshToken = refreshToken;
}
this.resetMasterPassword = this.getResponseProperty("ResetMasterPassword");
this.privateKey = this.getResponseProperty("PrivateKey");
@@ -57,10 +73,9 @@ export class IdentityTokenResponse extends BaseResponse {
this.getResponseProperty("MasterPasswordPolicy"),
);
if (response.UserDecryptionOptions) {
this.userDecryptionOptions = new UserDecryptionOptionsResponse(
this.getResponseProperty("UserDecryptionOptions"),
);
const userDecryptionOptions = this.getResponseProperty("UserDecryptionOptions");
if (userDecryptionOptions != null && typeof userDecryptionOptions === "object") {
this.userDecryptionOptions = new UserDecryptionOptionsResponse(userDecryptionOptions);
}
}