1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Add support for crypto agent (#520)

This commit is contained in:
Oscar Hinton
2021-10-25 18:21:40 +02:00
committed by GitHub
parent bc55557052
commit 71f8ef601f
10 changed files with 158 additions and 13 deletions

View File

@@ -166,6 +166,9 @@ import { ChallengeResponse } from '../models/response/twoFactorWebAuthnResponse'
import { TwoFactorYubiKeyResponse } from '../models/response/twoFactorYubiKeyResponse';
import { UserKeyResponse } from '../models/response/userKeyResponse';
import { SetCryptoAgentKeyRequest } from '../models/request/account/setCryptoAgentKeyRequest';
import { CryptoAgentUserKeyRequest } from '../models/request/cryptoAgentUserKeyRequest';
import { CryptoAgentUserKeyResponse } from '../models/response/cryptoAgentUserKeyResponse';
import { SendAccessView } from '../models/view/sendAccessView';
export class ApiService implements ApiServiceAbstraction {
@@ -289,6 +292,10 @@ export class ApiService implements ApiServiceAbstraction {
return this.send('POST', '/accounts/set-password', request, true, false);
}
postSetCryptoAgentKey(request: SetCryptoAgentKeyRequest): Promise<any> {
return this.send('POST', '/accounts/set-crypto-agent-key', request, true, false);
}
postSecurityStamp(request: PasswordVerificationRequest): Promise<any> {
return this.send('POST', '/accounts/security-stamp', request, true, false);
}
@@ -1429,6 +1436,49 @@ export class ApiService implements ApiServiceAbstraction {
return r as string;
}
// Crypto Agent
async getUserKeyFromCryptoAgent(cryptoAgentUrl: string): Promise<CryptoAgentUserKeyResponse> {
const authHeader = await this.getActiveBearerToken();
const response = await this.fetch(new Request(cryptoAgentUrl + '/user-keys', {
cache: 'no-store',
method: 'GET',
headers: new Headers({
'Accept': 'application/json',
'Authorization': 'Bearer ' + authHeader,
}),
}));
if (response.status !== 200) {
const error = await this.handleError(response, false, true);
return Promise.reject(error);
}
return new CryptoAgentUserKeyResponse(await response.json());
}
async postUserKeyToCryptoAgent(cryptoAgentUrl: string, request: CryptoAgentUserKeyRequest): Promise<void> {
const authHeader = await this.getActiveBearerToken();
const response = await this.fetch(new Request(cryptoAgentUrl + '/user-keys', {
cache: 'no-store',
method: 'POST',
headers: new Headers({
'Accept': 'application/json',
'Authorization': 'Bearer ' + authHeader,
'Content-Type': 'application/json; charset=utf-8',
}),
body: JSON.stringify(request),
}));
if (response.status !== 200) {
const error = await this.handleError(response, false, true);
return Promise.reject(error);
}
}
// Helpers
async getActiveBearerToken(): Promise<string> {