1
0
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:
Thomas Rittson
2021-12-20 12:34:57 +10:00
parent 9c22bfd1e8
commit c2f21e03a9
3 changed files with 14 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;