2022-05-09 14:21:52 +02:00
|
|
|
import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-05-09 14:21:52 +02:00
|
|
|
|
|
|
|
import { ApiKeyComponent } from "./api-key.component";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-security-keys",
|
|
|
|
templateUrl: "security-keys.component.html",
|
|
|
|
})
|
|
|
|
export class SecurityKeysComponent implements OnInit {
|
|
|
|
@ViewChild("viewUserApiKeyTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
viewUserApiKeyModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("rotateUserApiKeyTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
rotateUserApiKeyModalRef: ViewContainerRef;
|
|
|
|
|
|
|
|
showChangeKdf = true;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private keyConnectorService: KeyConnectorService,
|
|
|
|
private stateService: StateService,
|
|
|
|
private modalService: ModalService,
|
|
|
|
private apiService: ApiService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
this.showChangeKdf = !(await this.keyConnectorService.getUsesKeyConnector());
|
|
|
|
}
|
|
|
|
|
|
|
|
async viewUserApiKey() {
|
|
|
|
const entityId = await this.stateService.getUserId();
|
|
|
|
await this.modalService.openViewRef(ApiKeyComponent, this.viewUserApiKeyModalRef, (comp) => {
|
|
|
|
comp.keyType = "user";
|
|
|
|
comp.entityId = entityId;
|
|
|
|
comp.postKey = this.apiService.postUserApiKey.bind(this.apiService);
|
|
|
|
comp.scope = "api";
|
|
|
|
comp.grantType = "client_credentials";
|
|
|
|
comp.apiKeyTitle = "apiKey";
|
|
|
|
comp.apiKeyWarning = "userApiKeyWarning";
|
|
|
|
comp.apiKeyDescription = "userApiKeyDesc";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async rotateUserApiKey() {
|
|
|
|
const entityId = await this.stateService.getUserId();
|
|
|
|
await this.modalService.openViewRef(ApiKeyComponent, this.rotateUserApiKeyModalRef, (comp) => {
|
|
|
|
comp.keyType = "user";
|
|
|
|
comp.isRotation = true;
|
|
|
|
comp.entityId = entityId;
|
|
|
|
comp.postKey = this.apiService.postUserRotateApiKey.bind(this.apiService);
|
|
|
|
comp.scope = "api";
|
|
|
|
comp.grantType = "client_credentials";
|
|
|
|
comp.apiKeyTitle = "apiKey";
|
|
|
|
comp.apiKeyWarning = "userApiKeyWarning";
|
|
|
|
comp.apiKeyDescription = "apiKeyRotateDesc";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|