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:
parent
32a636e5a5
commit
c3b6baf726
@ -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>;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
7
src/models/request/twoFactorProviderRequest.ts
Normal file
7
src/models/request/twoFactorProviderRequest.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { PasswordVerificationRequest } from './passwordVerificationRequest';
|
||||
|
||||
import { TwoFactorProviderType } from '../../enums/twoFactorProviderType';
|
||||
|
||||
export class TwoFactorProviderRequest extends PasswordVerificationRequest {
|
||||
type: TwoFactorProviderType;
|
||||
}
|
6
src/models/request/twoFactorRecoveryRequest.ts
Normal file
6
src/models/request/twoFactorRecoveryRequest.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { PasswordVerificationRequest } from './passwordVerificationRequest';
|
||||
|
||||
export class TwoFactorRecoveryRequest extends PasswordVerificationRequest {
|
||||
recoveryCode: string;
|
||||
email: string;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
import { PasswordVerificationRequest } from './passwordVerificationRequest';
|
||||
|
||||
export class UpdateTwoFactorAuthenticatorRequest extends PasswordVerificationRequest {
|
||||
token: string;
|
||||
key: string;
|
||||
}
|
7
src/models/request/updateTwoFactorDuoRequest.ts
Normal file
7
src/models/request/updateTwoFactorDuoRequest.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { PasswordVerificationRequest } from './passwordVerificationRequest';
|
||||
|
||||
export class UpdateTwoFactorDuoRequest extends PasswordVerificationRequest {
|
||||
integrationKey: string;
|
||||
secretKey: string;
|
||||
host: string;
|
||||
}
|
6
src/models/request/updateTwoFactorEmailRequest.ts
Normal file
6
src/models/request/updateTwoFactorEmailRequest.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { PasswordVerificationRequest } from './passwordVerificationRequest';
|
||||
|
||||
export class UpdateTwoFactorEmailRequest extends PasswordVerificationRequest {
|
||||
token: string;
|
||||
email: string;
|
||||
}
|
5
src/models/request/updateTwoFactorU2fRequest.ts
Normal file
5
src/models/request/updateTwoFactorU2fRequest.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { PasswordVerificationRequest } from './passwordVerificationRequest';
|
||||
|
||||
export class UpdateTwoFactorU2fRequest extends PasswordVerificationRequest {
|
||||
deviceResponse: string;
|
||||
}
|
10
src/models/request/updateTwoFactorYubioOtpRequest.ts
Normal file
10
src/models/request/updateTwoFactorYubioOtpRequest.ts
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
9
src/models/response/twoFactorAuthenticatorResponse.ts
Normal file
9
src/models/response/twoFactorAuthenticatorResponse.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export class TwoFactorAuthenticatorResponse {
|
||||
enabled: boolean;
|
||||
key: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.enabled = response.Enabled;
|
||||
this.key = response.Key;
|
||||
}
|
||||
}
|
13
src/models/response/twoFactorDuoResponse.ts
Normal file
13
src/models/response/twoFactorDuoResponse.ts
Normal 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;
|
||||
}
|
||||
}
|
9
src/models/response/twoFactorEmailResponse.ts
Normal file
9
src/models/response/twoFactorEmailResponse.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export class TwoFactorEmailResponse {
|
||||
enabled: boolean;
|
||||
email: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.enabled = response.Enabled;
|
||||
this.email = response.Email;
|
||||
}
|
||||
}
|
11
src/models/response/twoFactorProviderResponse.ts
Normal file
11
src/models/response/twoFactorProviderResponse.ts
Normal 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;
|
||||
}
|
||||
}
|
7
src/models/response/twoFactorRescoverResponse.ts
Normal file
7
src/models/response/twoFactorRescoverResponse.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export class TwoFactorRecoverResponse {
|
||||
code: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.code = response.Code;
|
||||
}
|
||||
}
|
23
src/models/response/twoFactorU2fResponse.ts
Normal file
23
src/models/response/twoFactorU2fResponse.ts
Normal 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;
|
||||
}
|
||||
}
|
19
src/models/response/twoFactorYubiKeyResponse.ts
Normal file
19
src/models/response/twoFactorYubiKeyResponse.ts
Normal 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;
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
@ -48,6 +48,7 @@
|
||||
"check-preblock",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
],
|
||||
"max-classes-per-file": false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user