mirror of
https://github.com/bitwarden/jslib
synced 2025-12-17 00:33:17 +00:00
Add helper methods to authResult
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import { TwoFactorProviderType } from "../../enums/twoFactorProviderType";
|
||||
|
||||
import { Utils } from "../../misc/utils";
|
||||
|
||||
export class AuthResult {
|
||||
twoFactor: boolean = false;
|
||||
captchaSiteKey: string = "";
|
||||
resetMasterPassword: boolean = false;
|
||||
forcePasswordReset: boolean = false;
|
||||
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string }> = null;
|
||||
|
||||
get requiresCaptcha() {
|
||||
return !Utils.isNullOrWhitespace(this.captchaSiteKey);
|
||||
}
|
||||
|
||||
get requiresTwoFactor() {
|
||||
return this.twoFactor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,12 +270,12 @@ export class AuthService implements AuthServiceAbstraction {
|
||||
const result = new AuthResult();
|
||||
|
||||
result.captchaSiteKey = (response as any).siteKey;
|
||||
if (!!result.captchaSiteKey) {
|
||||
if (result.requiresCaptcha) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result.twoFactor = !!(response as any).twoFactorProviders2;
|
||||
if (result.twoFactor) {
|
||||
result.twoFactor = (response as any).twoFactorProviders2 != null;
|
||||
if (result.requiresTwoFactor) {
|
||||
result.twoFactorProviders = (response as IdentityTwoFactorResponse).twoFactorProviders2;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ describe("Cipher Service", () => {
|
||||
|
||||
function newTokenResponse() {
|
||||
const tokenResponse = new IdentityTokenResponse({});
|
||||
(tokenResponse as any).twoFactorProviders2 = false;
|
||||
(tokenResponse as any).twoFactorProviders2 = null;
|
||||
(tokenResponse as any).siteKey = undefined;
|
||||
tokenResponse.resetMasterPassword = false;
|
||||
tokenResponse.forcePasswordReset = false;
|
||||
|
||||
Reference in New Issue
Block a user