mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
[PM-5255, PM-3339] Refactor login strategy to use state providers (#7821)
* add key definition and StrategyData classes * use state providers for login strategies * serialize login data for cache * use state providers for auth request notification * fix registrations * add docs to abstraction * fix sso strategy * fix password login strategy tests * fix base login strategy tests * fix user api login strategy tests * PM-3339 add tests for admin auth request in sso strategy * fix auth request login strategy tests * fix webauthn login strategy tests * create login strategy state * use barrel file in common/spec * test login strategy cache deserialization * use global state provider * add test for login strategy service * fix auth request storage * add recursive prototype checking and json deserializers to nested objects * fix CLI * Create wrapper for login strategy cache * use behavior subjects in strategies instead of global state * rename userApi to userApiKey * pr feedback * fix tests * fix deserialization tests * fix tests --------- Co-authored-by: rr-bw <102181210+rr-bw@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { AuthenticationType } from "@bitwarden/common/auth/enums/authentication-type";
|
||||
import { TokenTwoFactorRequest } from "@bitwarden/common/auth/models/request/identity-token/token-two-factor.request";
|
||||
import { WebAuthnLoginAssertionResponseRequest } from "@bitwarden/common/auth/services/webauthn-login/request/webauthn-login-assertion-response.request";
|
||||
@@ -28,7 +30,7 @@ export class SsoLoginCredentials {
|
||||
}
|
||||
|
||||
export class UserApiLoginCredentials {
|
||||
readonly type = AuthenticationType.UserApi;
|
||||
readonly type = AuthenticationType.UserApiKey;
|
||||
|
||||
constructor(
|
||||
public clientId: string,
|
||||
@@ -48,6 +50,30 @@ export class AuthRequestLoginCredentials {
|
||||
public decryptedMasterKeyHash: string,
|
||||
public twoFactor?: TokenTwoFactorRequest,
|
||||
) {}
|
||||
|
||||
static fromJSON(json: Jsonify<AuthRequestLoginCredentials>) {
|
||||
return Object.assign(
|
||||
new AuthRequestLoginCredentials(
|
||||
json.email,
|
||||
json.accessCode,
|
||||
json.authRequestId,
|
||||
null,
|
||||
null,
|
||||
json.decryptedMasterKeyHash,
|
||||
json.twoFactor
|
||||
? new TokenTwoFactorRequest(
|
||||
json.twoFactor.provider,
|
||||
json.twoFactor.token,
|
||||
json.twoFactor.remember,
|
||||
)
|
||||
: json.twoFactor,
|
||||
),
|
||||
{
|
||||
decryptedUserKey: SymmetricCryptoKey.fromJSON(json.decryptedUserKey) as UserKey,
|
||||
decryptedMasterKey: SymmetricCryptoKey.fromJSON(json.decryptedMasterKey) as MasterKey,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class WebAuthnLoginCredentials {
|
||||
@@ -58,4 +84,15 @@ export class WebAuthnLoginCredentials {
|
||||
public deviceResponse: WebAuthnLoginAssertionResponseRequest,
|
||||
public prfKey?: SymmetricCryptoKey,
|
||||
) {}
|
||||
|
||||
static fromJSON(json: Jsonify<WebAuthnLoginCredentials>) {
|
||||
return new WebAuthnLoginCredentials(
|
||||
json.token,
|
||||
Object.assign(
|
||||
Object.create(WebAuthnLoginAssertionResponseRequest.prototype),
|
||||
json.deviceResponse,
|
||||
),
|
||||
SymmetricCryptoKey.fromJSON(json.prfKey),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user