2019-03-07 17:18:45 +01:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2021-11-09 19:24:26 +01:00
|
|
|
import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service';
|
2019-03-07 17:18:45 +01:00
|
|
|
|
2021-11-09 19:24:26 +01:00
|
|
|
import { SecretVerificationRequest } from 'jslib-common/models/request/secretVerificationRequest';
|
2019-03-07 17:18:45 +01:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiKeyResponse } from 'jslib-common/models/response/apiKeyResponse';
|
2019-03-07 17:18:45 +01:00
|
|
|
|
2021-11-09 19:24:26 +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 {
|
2020-11-10 22:13:42 +01:00
|
|
|
keyType: string;
|
|
|
|
isRotation: boolean;
|
2021-11-09 19:24:26 +01:00
|
|
|
postKey: (entityId: string, request: SecretVerificationRequest) => Promise<ApiKeyResponse>;
|
2020-11-10 22:13:42 +01:00
|
|
|
entityId: string;
|
|
|
|
scope: string;
|
|
|
|
grantType: string;
|
|
|
|
apiKeyTitle: string;
|
|
|
|
apiKeyWarning: string;
|
|
|
|
apiKeyDescription: string;
|
2019-03-07 17:18:45 +01:00
|
|
|
|
2021-11-09 19:24:26 +01:00
|
|
|
masterPassword: Verification;
|
2019-03-07 17:18:45 +01:00
|
|
|
formPromise: Promise<ApiKeyResponse>;
|
|
|
|
clientId: string;
|
|
|
|
clientSecret: string;
|
|
|
|
|
2021-11-09 19:24:26 +01:00
|
|
|
constructor(private userVerificationService: UserVerificationService, private logService: LogService) { }
|
2019-03-07 17:18:45 +01:00
|
|
|
|
|
|
|
async submit() {
|
2021-11-09 19:24:26 +01:00
|
|
|
const request = await this.userVerificationService.buildRequest(this.masterPassword);
|
2019-03-07 17:18:45 +01:00
|
|
|
|
|
|
|
try {
|
2020-11-10 22:13:42 +01:00
|
|
|
this.formPromise = this.postKey(this.entityId, request);
|
2019-03-07 17:18:45 +01:00
|
|
|
const response = await this.formPromise;
|
|
|
|
this.clientSecret = response.apiKey;
|
2020-11-10 22:13:42 +01:00
|
|
|
this.clientId = `${this.keyType}.${this.entityId}`;
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
2019-03-07 17:18:45 +01:00
|
|
|
}
|
|
|
|
}
|