1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-24 16:49:26 +01:00

add two factor apis

This commit is contained in:
Kyle Spearrin 2018-06-26 15:17:14 -04:00
parent 32a636e5a5
commit c3b6baf726
19 changed files with 268 additions and 8 deletions

View File

@ -18,16 +18,31 @@ import { PasswordVerificationRequest } from '../models/request/passwordVerificat
import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest';
import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
import { TwoFactorProviderRequest } from '../models/request/twoFactorProviderRequest';
import { TwoFactorRecoveryRequest } from '../models/request/twoFactorRecoveryRequest';
import { UpdateDomainsRequest } from '../models/request/updateDomainsRequest';
import { UpdateProfileRequest } from '../models/request/updateProfileRequest';
import { UpdateTwoFactorAuthenticatorRequest } from '../models/request/updateTwoFactorAuthenticatorRequest';
import { UpdateTwoFactorDuoRequest } from '../models/request/updateTwoFactorDuoRequest';
import { UpdateTwoFactorEmailRequest } from '../models/request/updateTwoFactorEmailRequest';
import { UpdateTwoFactorU2fRequest } from '../models/request/updateTwoFactorU2fRequest';
import { UpdateTwoFactorYubioOtpRequest } from '../models/request/updateTwoFactorYubioOtpRequest';
import { CipherResponse } from '../models/response/cipherResponse';
import { DomainsResponse } from '../models/response/domainsResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { IdentityTokenResponse } from '../models/response/identityTokenResponse';
import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse';
import { ListResponse } from '../models/response/listResponse';
import { ProfileResponse } from '../models/response/profileResponse';
import { SyncResponse } from '../models/response/syncResponse';
import { TwoFactorAuthenticatorResponse } from '../models/response/twoFactorAuthenticatorResponse';
import { TwoFactorDuoResponse } from '../models/response/twoFactorDuoResponse';
import { TwoFactorEmailResponse } from '../models/response/twoFactorEmailResponse';
import { TwoFactorProviderResponse } from '../models/response/twoFactorProviderResponse';
import { TwoFactorRecoverResponse } from '../models/response/twoFactorRescoverResponse';
import { TwoFactorU2fResponse } from '../models/response/twoFactorU2fResponse';
import { TwoFactorYubiKeyResponse } from '../models/response/twoFactorYubiKeyResponse';
export abstract class ApiService {
urlsSet: boolean;
@ -70,4 +85,19 @@ export abstract class ApiService {
postImportDirectory: (organizationId: string, request: ImportDirectoryRequest) => Promise<any>;
getSettingsDomains: () => Promise<DomainsResponse>;
putSettingsDomains: (request: UpdateDomainsRequest) => Promise<DomainsResponse>;
getTwoFactorProviders: () => Promise<ListResponse<TwoFactorProviderResponse>>;
getTwoFactorAuthenticator: (request: PasswordVerificationRequest) => Promise<TwoFactorAuthenticatorResponse>;
getTwoFactorEmail: (request: PasswordVerificationRequest) => Promise<TwoFactorEmailResponse>;
getTwoFactorDuo: (request: PasswordVerificationRequest) => Promise<TwoFactorDuoResponse>;
getTwoFactorYubiKey: (request: PasswordVerificationRequest) => Promise<TwoFactorYubiKeyResponse>;
getTwoFactorU2f: (request: PasswordVerificationRequest) => Promise<TwoFactorU2fResponse>;
getTwoFactorRecover: (request: PasswordVerificationRequest) => Promise<TwoFactorRecoverResponse>;
putTwoFactorAuthenticator: (
request: UpdateTwoFactorAuthenticatorRequest) => Promise<TwoFactorAuthenticatorResponse>;
putTwoFactorEmail: (request: UpdateTwoFactorEmailRequest) => Promise<TwoFactorEmailResponse>;
putTwoFactorDuo: (request: UpdateTwoFactorDuoRequest) => Promise<TwoFactorDuoResponse>;
putTwoFactorYubiKey: (request: UpdateTwoFactorYubioOtpRequest) => Promise<TwoFactorYubiKeyResponse>;
putTwoFactorU2f: (request: UpdateTwoFactorU2fRequest) => Promise<TwoFactorU2fResponse>;
putTwoFactorDisable: (request: TwoFactorProviderRequest) => Promise<TwoFactorProviderResponse>;
postTwoFactorRecover: (request: TwoFactorRecoveryRequest) => Promise<any>;
}

View File

@ -1,9 +1,11 @@
export class TwoFactorEmailRequest {
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class TwoFactorEmailRequest extends PasswordVerificationRequest {
email: string;
masterPasswordHash: string;
constructor(email: string, masterPasswordHash: string) {
this.email = email;
super();
this.masterPasswordHash = masterPasswordHash;
this.email = email;
}
}

View File

@ -0,0 +1,7 @@
import { PasswordVerificationRequest } from './passwordVerificationRequest';
import { TwoFactorProviderType } from '../../enums/twoFactorProviderType';
export class TwoFactorProviderRequest extends PasswordVerificationRequest {
type: TwoFactorProviderType;
}

View File

@ -0,0 +1,6 @@
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class TwoFactorRecoveryRequest extends PasswordVerificationRequest {
recoveryCode: string;
email: string;
}

View File

@ -0,0 +1,6 @@
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class UpdateTwoFactorAuthenticatorRequest extends PasswordVerificationRequest {
token: string;
key: string;
}

View File

@ -0,0 +1,7 @@
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class UpdateTwoFactorDuoRequest extends PasswordVerificationRequest {
integrationKey: string;
secretKey: string;
host: string;
}

View File

@ -0,0 +1,6 @@
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class UpdateTwoFactorEmailRequest extends PasswordVerificationRequest {
token: string;
email: string;
}

View File

@ -0,0 +1,5 @@
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class UpdateTwoFactorU2fRequest extends PasswordVerificationRequest {
deviceResponse: string;
}

View File

@ -0,0 +1,10 @@
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class UpdateTwoFactorYubioOtpRequest extends PasswordVerificationRequest {
key1: string;
key2: string;
key3: string;
key4: string;
key5: string;
nfc: boolean;
}

View File

@ -1,7 +1,9 @@
export class ListResponse {
data: any;
export class ListResponse<T> {
data: T[];
continuationToken: string;
constructor(data: any) {
this.data = data;
constructor(response: any, t: new (dataResponse: any) => T) {
this.data = response.Data.map((dr) => new t(dr));
this.continuationToken = response.ContinuationToken;
}
}

View File

@ -0,0 +1,9 @@
export class TwoFactorAuthenticatorResponse {
enabled: boolean;
key: string;
constructor(response: any) {
this.enabled = response.Enabled;
this.key = response.Key;
}
}

View File

@ -0,0 +1,13 @@
export class TwoFactorDuoResponse {
enabled: boolean;
host: string;
secretKey: string;
integrationKey: string;
constructor(response: any) {
this.enabled = response.Enabled;
this.host = response.Host;
this.secretKey = response.SecretKey;
this.integrationKey = response.IntegrationKey;
}
}

View File

@ -0,0 +1,9 @@
export class TwoFactorEmailResponse {
enabled: boolean;
email: string;
constructor(response: any) {
this.enabled = response.Enabled;
this.email = response.Email;
}
}

View File

@ -0,0 +1,11 @@
import { TwoFactorProviderType } from '../../enums/twoFactorProviderType';
export class TwoFactorProviderResponse {
enabled: boolean;
type: TwoFactorProviderType;
constructor(response: any) {
this.enabled = response.Enabled;
this.type = response.Type;
}
}

View File

@ -0,0 +1,7 @@
export class TwoFactorRecoverResponse {
code: string;
constructor(response: any) {
this.code = response.Code;
}
}

View File

@ -0,0 +1,23 @@
export class TwoFactorU2fResponse {
enabled: boolean;
challenge: Challenge;
constructor(response: any) {
this.enabled = response.Enabled;
this.challenge = new Challenge(response.Challenge);
}
}
class Challenge {
userId: string;
appId: string;
challenge: string;
version: string;
constructor(response: any) {
this.userId = response.UserId;
this.appId = response.AppId;
this.challenge = response.Challenge;
this.version = response.Version;
}
}

View File

@ -0,0 +1,19 @@
export class TwoFactorYubiKeyResponse {
enabled: boolean;
key1: string;
key2: string;
key3: string;
key4: string;
key5: string;
nfc: boolean;
constructor(response: any) {
this.enabled = response.Enabled;
this.key1 = response.Key1;
this.key2 = response.Key2;
this.key3 = response.Key3;
this.key4 = response.Key4;
this.key5 = response.Key5;
this.nfc = response.Nfc;
}
}

View File

@ -24,8 +24,15 @@ import { PasswordVerificationRequest } from '../models/request/passwordVerificat
import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest';
import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
import { TwoFactorProviderRequest } from '../models/request/twoFactorProviderRequest';
import { TwoFactorRecoveryRequest } from '../models/request/twoFactorRecoveryRequest';
import { UpdateDomainsRequest } from '../models/request/updateDomainsRequest';
import { UpdateProfileRequest } from '../models/request/updateProfileRequest';
import { UpdateTwoFactorAuthenticatorRequest } from '../models/request/updateTwoFactorAuthenticatorRequest';
import { UpdateTwoFactorDuoRequest } from '../models/request/updateTwoFactorDuoRequest';
import { UpdateTwoFactorEmailRequest } from '../models/request/updateTwoFactorEmailRequest';
import { UpdateTwoFactorU2fRequest } from '../models/request/updateTwoFactorU2fRequest';
import { UpdateTwoFactorYubioOtpRequest } from '../models/request/updateTwoFactorYubioOtpRequest';
import { CipherResponse } from '../models/response/cipherResponse';
import { DomainsResponse } from '../models/response/domainsResponse';
@ -33,8 +40,16 @@ import { ErrorResponse } from '../models/response/errorResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { IdentityTokenResponse } from '../models/response/identityTokenResponse';
import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse';
import { ListResponse } from '../models/response/listResponse';
import { ProfileResponse } from '../models/response/profileResponse';
import { SyncResponse } from '../models/response/syncResponse';
import { TwoFactorAuthenticatorResponse } from '../models/response/twoFactorAuthenticatorResponse';
import { TwoFactorDuoResponse } from '../models/response/twoFactorDuoResponse';
import { TwoFactorEmailResponse } from '../models/response/twoFactorEmailResponse';
import { TwoFactorProviderResponse } from '../models/response/twoFactorProviderResponse';
import { TwoFactorRecoverResponse } from '../models/response/twoFactorRescoverResponse';
import { TwoFactorU2fResponse } from '../models/response/twoFactorU2fResponse';
import { TwoFactorYubiKeyResponse } from '../models/response/twoFactorYubiKeyResponse';
export class ApiService implements ApiServiceAbstraction {
urlsSet: boolean = false;
@ -280,6 +295,78 @@ export class ApiService implements ApiServiceAbstraction {
return new DomainsResponse(r);
}
// Two-factor
async getTwoFactorProviders(): Promise<ListResponse<TwoFactorProviderResponse>> {
const r = await this.send('GET', '/two-factor', null, true, true);
return new ListResponse(r, TwoFactorProviderResponse);
}
async getTwoFactorAuthenticator(request: PasswordVerificationRequest): Promise<TwoFactorAuthenticatorResponse> {
const r = await this.send('POST', '/two-factor/get-authenticator', request, true, true);
return new TwoFactorAuthenticatorResponse(r);
}
async getTwoFactorEmail(request: PasswordVerificationRequest): Promise<TwoFactorEmailResponse> {
const r = await this.send('POST', '/two-factor/get-email', request, true, true);
return new TwoFactorEmailResponse(r);
}
async getTwoFactorDuo(request: PasswordVerificationRequest): Promise<TwoFactorDuoResponse> {
const r = await this.send('POST', '/two-factor/get-duo', request, true, true);
return new TwoFactorDuoResponse(r);
}
async getTwoFactorYubiKey(request: PasswordVerificationRequest): Promise<TwoFactorYubiKeyResponse> {
const r = await this.send('POST', '/two-factor/get-yubikey', request, true, true);
return new TwoFactorYubiKeyResponse(r);
}
async getTwoFactorU2f(request: PasswordVerificationRequest): Promise<TwoFactorU2fResponse> {
const r = await this.send('POST', '/two-factor/get-u2f', request, true, true);
return new TwoFactorU2fResponse(r);
}
async getTwoFactorRecover(request: PasswordVerificationRequest): Promise<TwoFactorRecoverResponse> {
const r = await this.send('POST', '/two-factor/get-recover', request, true, true);
return new TwoFactorRecoverResponse(r);
}
async putTwoFactorAuthenticator(
request: UpdateTwoFactorAuthenticatorRequest): Promise<TwoFactorAuthenticatorResponse> {
const r = await this.send('PUT', '/two-factor/authenticator', request, true, true);
return new TwoFactorAuthenticatorResponse(r);
}
async putTwoFactorEmail(request: UpdateTwoFactorEmailRequest): Promise<TwoFactorEmailResponse> {
const r = await this.send('PUT', '/two-factor/email', request, true, true);
return new TwoFactorEmailResponse(r);
}
async putTwoFactorDuo(request: UpdateTwoFactorDuoRequest): Promise<TwoFactorDuoResponse> {
const r = await this.send('PUT', '/two-factor/duo', request, true, true);
return new TwoFactorDuoResponse(r);
}
async putTwoFactorYubiKey(request: UpdateTwoFactorYubioOtpRequest): Promise<TwoFactorYubiKeyResponse> {
const r = await this.send('PUT', '/two-factor/yubikey', request, true, true);
return new TwoFactorYubiKeyResponse(r);
}
async putTwoFactorU2f(request: UpdateTwoFactorU2fRequest): Promise<TwoFactorU2fResponse> {
const r = await this.send('PUT', '/two-factor/u2f', request, true, true);
return new TwoFactorU2fResponse(r);
}
async putTwoFactorDisable(request: TwoFactorProviderRequest): Promise<TwoFactorProviderResponse> {
const r = await this.send('PUT', '/two-factor/disable', request, true, true);
return new TwoFactorProviderResponse(r);
}
postTwoFactorRecover(request: TwoFactorRecoveryRequest): Promise<any> {
return this.send('POST', '/two-factor/recover', request, false, false);
}
// Helpers
private async send(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body: any,

View File

@ -48,6 +48,7 @@
"check-preblock",
"check-separator",
"check-type"
]
],
"max-classes-per-file": false
}
}