1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-19 17:53:48 +00:00

Break tokenRequest into subclasses

This commit is contained in:
Thomas Rittson
2021-12-16 15:32:44 +10:00
parent 6cb2b91fee
commit bd55e6ec81
10 changed files with 215 additions and 150 deletions

View File

@@ -0,0 +1,34 @@
import { TokenRequest } from './tokenRequest';
import { TwoFactorProviderType } from '../../../enums/twoFactorProviderType';
import { DeviceRequest } from '../deviceRequest';
import { Utils } from '../../../misc/utils';
export class PasswordTokenRequest extends TokenRequest {
email: string;
masterPasswordHash: string;
constructor(email: string, masterPasswordHash: string, public provider: TwoFactorProviderType, public token: string,
public remember: boolean, public captchaResponse: string, device?: DeviceRequest) {
super(provider, token, remember, captchaResponse, device);
this.email = email;
this.masterPasswordHash = masterPasswordHash;
}
toIdentityToken(clientId: string) {
const obj = super.toIdentityToken(clientId);
obj.grant_type = 'password';
obj.username = this.email;
obj.password = this.masterPasswordHash;
return obj;
}
alterIdentityTokenHeaders(headers: Headers) {
headers.set('Auth-Email', Utils.fromUtf8ToUrlB64(this.email));
}
}