more apis for account settings

This commit is contained in:
Kyle Spearrin 2018-06-21 17:15:43 -04:00
parent 322dcf76ae
commit 2e486d5a7c
6 changed files with 82 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import { FolderRequest } from '../models/request/folderRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { PasswordRequest } from '../models/request/passwordRequest';
import { PasswordVerificationRequest } from '../models/request/passwordVerificationRequest';
import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest';
import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
@ -38,6 +39,8 @@ export abstract class ApiService {
postEmailToken: (request: EmailTokenRequest) => Promise<any>;
postEmail: (request: EmailRequest) => Promise<any>;
postPassword: (request: PasswordRequest) => Promise<any>;
postSecurityStamp: (request: PasswordVerificationRequest) => Promise<any>;
postDeleteAccount: (request: PasswordVerificationRequest) => Promise<any>;
getAccountRevisionDate: () => Promise<number>;
postPasswordHint: (request: PasswordHintRequest) => Promise<any>;
postRegister: (request: RegisterRequest) => Promise<any>;
@ -52,6 +55,7 @@ export abstract class ApiService {
putShareCipher: (id: string, request: CipherShareRequest) => Promise<any>;
putShareCiphers: (request: CipherBulkShareRequest) => Promise<any>;
putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise<any>;
postPurgeCiphers: (request: PasswordVerificationRequest) => Promise<any>;
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;
postShareCipherAttachment: (id: string, attachmentId: string, data: FormData,

View File

@ -1,6 +1,6 @@
export class EmailRequest {
newEmail: string;
masterPasswordHash: string;
import { EmailTokenRequest } from './emailTokenRequest';
export class EmailRequest extends EmailTokenRequest {
newMasterPasswordHash: string;
token: string;
key: string;

View File

@ -1,4 +1,6 @@
export class EmailTokenRequest {
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class EmailTokenRequest extends PasswordVerificationRequest {
newEmail: string;
masterPasswordHash: string;
}

View File

@ -1,5 +1,6 @@
export class PasswordRequest {
masterPasswordHash: string;
import { PasswordVerificationRequest } from './passwordVerificationRequest';
export class PasswordRequest extends PasswordVerificationRequest {
newMasterPasswordHash: string;
key: string;
}

View File

@ -0,0 +1,3 @@
export class PasswordVerificationRequest {
masterPasswordHash: string;
}

View File

@ -18,6 +18,7 @@ import { FolderRequest } from '../models/request/folderRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { PasswordRequest } from '../models/request/passwordRequest';
import { PasswordVerificationRequest } from '../models/request/passwordVerificationRequest';
import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest';
import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
@ -82,8 +83,8 @@ export class ApiService implements ApiServiceAbstraction {
// Production
if (this.isWebClient) {
this.apiBaseUrl = 'https://vault.bitwarden.com/api';
this.identityBaseUrl = 'https://vault.bitwarden.com/identity';
this.apiBaseUrl = 'https://api.bitwarden.com';
this.identityBaseUrl = 'https://identity.bitwarden.com';
} else {
this.apiBaseUrl = 'https://api.bitwarden.com';
this.identityBaseUrl = 'https://identity.bitwarden.com';
@ -263,6 +264,48 @@ export class ApiService implements ApiServiceAbstraction {
}
}
async postSecurityStamp(request: PasswordVerificationRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/accounts/security-stamp', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
async postDeleteAccount(request: PasswordVerificationRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/accounts/delete', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
async getAccountRevisionDate(): Promise<number> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/accounts/revision-date', {
@ -560,6 +603,27 @@ export class ApiService implements ApiServiceAbstraction {
}
}
async postPurgeCiphers(request: PasswordVerificationRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/ciphers/purge', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
// Attachments APIs
async postCipherAttachment(id: string, data: FormData): Promise<CipherResponse> {