bitwarden-estensione-browser/src/app/settings/api-key.component.ts

46 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-03-07 17:18:45 +01:00
import { Component } from '@angular/core';
import { LogService } from 'jslib-common/abstractions/log.service';
import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service';
2019-03-07 17:18:45 +01:00
import { SecretVerificationRequest } from 'jslib-common/models/request/secretVerificationRequest';
2019-03-07 17:18:45 +01:00
import { ApiKeyResponse } from 'jslib-common/models/response/apiKeyResponse';
2019-03-07 17:18:45 +01:00
import { Verification } from 'jslib-common/types/verification';
2019-03-07 17:18:45 +01:00
@Component({
selector: 'app-api-key',
templateUrl: 'api-key.component.html',
})
export class ApiKeyComponent {
keyType: string;
isRotation: boolean;
postKey: (entityId: string, request: SecretVerificationRequest) => Promise<ApiKeyResponse>;
entityId: string;
scope: string;
grantType: string;
apiKeyTitle: string;
apiKeyWarning: string;
apiKeyDescription: string;
2019-03-07 17:18:45 +01:00
masterPassword: Verification;
2019-03-07 17:18:45 +01:00
formPromise: Promise<ApiKeyResponse>;
clientId: string;
clientSecret: string;
constructor(private userVerificationService: UserVerificationService, private logService: LogService) { }
2019-03-07 17:18:45 +01:00
async submit() {
try {
this.formPromise = this.userVerificationService.buildRequest(this.masterPassword)
.then(request => this.postKey(this.entityId, request));
2019-03-07 17:18:45 +01:00
const response = await this.formPromise;
this.clientSecret = response.apiKey;
this.clientId = `${this.keyType}.${this.entityId}`;
} catch (e) {
this.logService.error(e);
}
2019-03-07 17:18:45 +01:00
}
}