mirror of
https://github.com/bitwarden/browser.git
synced 2025-04-13 19:58:00 +02:00
* 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>
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { ClientType } from "../../../../enums";
|
|
import { Utils } from "../../../../platform/misc/utils";
|
|
import { CaptchaProtectedRequest } from "../captcha-protected.request";
|
|
|
|
import { DeviceRequest } from "./device.request";
|
|
import { TokenTwoFactorRequest } from "./token-two-factor.request";
|
|
import { TokenRequest } from "./token.request";
|
|
|
|
export class PasswordTokenRequest extends TokenRequest implements CaptchaProtectedRequest {
|
|
constructor(
|
|
public email: string,
|
|
public masterPasswordHash: string,
|
|
public captchaResponse: string,
|
|
protected twoFactor: TokenTwoFactorRequest,
|
|
device?: DeviceRequest,
|
|
) {
|
|
super(twoFactor, device);
|
|
}
|
|
|
|
toIdentityToken(clientId: ClientType) {
|
|
const obj = super.toIdentityToken(clientId);
|
|
|
|
obj.grant_type = "password";
|
|
obj.username = this.email;
|
|
obj.password = this.masterPasswordHash;
|
|
|
|
if (this.captchaResponse != null) {
|
|
obj.captchaResponse = this.captchaResponse;
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
alterIdentityTokenHeaders(headers: Headers) {
|
|
headers.set("Auth-Email", Utils.fromUtf8ToUrlB64(this.email));
|
|
}
|
|
|
|
static fromJSON(json: any) {
|
|
return Object.assign(Object.create(PasswordTokenRequest.prototype), json, {
|
|
device: json.device ? DeviceRequest.fromJSON(json.device) : undefined,
|
|
twoFactor: json.twoFactor
|
|
? Object.assign(new TokenTwoFactorRequest(), json.twoFactor)
|
|
: undefined,
|
|
});
|
|
}
|
|
}
|