2021-12-17 15:57:11 +01:00
|
|
|
import { Component } from "@angular/core";
|
2019-03-07 17:18:45 +01:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification.service";
|
|
|
|
import { SecretVerificationRequest } from "@bitwarden/common/models/request/secretVerificationRequest";
|
|
|
|
import { ApiKeyResponse } from "@bitwarden/common/models/response/apiKeyResponse";
|
|
|
|
import { Verification } from "@bitwarden/common/types/verification";
|
2021-11-09 19:24:26 +01:00
|
|
|
|
2019-03-07 17:18:45 +01:00
|
|
|
@Component({
|
2021-12-17 15:57:11 +01:00
|
|
|
selector: "app-api-key",
|
|
|
|
templateUrl: "api-key.component.html",
|
2019-03-07 17:18:45 +01:00
|
|
|
})
|
|
|
|
export class ApiKeyComponent {
|
2021-12-17 15:57:11 +01:00
|
|
|
keyType: string;
|
|
|
|
isRotation: boolean;
|
|
|
|
postKey: (entityId: string, request: SecretVerificationRequest) => Promise<ApiKeyResponse>;
|
|
|
|
entityId: string;
|
|
|
|
scope: string;
|
|
|
|
grantType: string;
|
|
|
|
apiKeyTitle: string;
|
|
|
|
apiKeyWarning: string;
|
|
|
|
apiKeyDescription: string;
|
|
|
|
|
|
|
|
masterPassword: Verification;
|
|
|
|
formPromise: Promise<ApiKeyResponse>;
|
|
|
|
clientId: string;
|
|
|
|
clientSecret: string;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private userVerificationService: UserVerificationService,
|
|
|
|
private logService: LogService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
try {
|
|
|
|
this.formPromise = this.userVerificationService
|
|
|
|
.buildRequest(this.masterPassword)
|
|
|
|
.then((request) => this.postKey(this.entityId, request));
|
|
|
|
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
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2019-03-07 17:18:45 +01:00
|
|
|
}
|