1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00
Files
browser/apps/web/src/app/auth/settings/security/security-keys.component.ts
vinith-kovan 1cec69e377 [PM 2164] api-key component migration (#8562)
* api-key component migration

* api-key component migration

* api-key component migration

* api-key component migration
2024-06-05 22:44:33 +05:30

66 lines
2.2 KiB
TypeScript

import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { DialogService } from "@bitwarden/components";
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 userVerificationService: UserVerificationService,
private stateService: StateService,
private apiService: ApiService,
private dialogService: DialogService,
) {}
async ngOnInit() {
this.showChangeKdf = await this.userVerificationService.hasMasterPassword();
}
async viewUserApiKey() {
const entityId = await this.stateService.getUserId();
await ApiKeyComponent.open(this.dialogService, {
data: {
keyType: "user",
entityId: entityId,
postKey: this.apiService.postUserApiKey.bind(this.apiService),
scope: "api",
grantType: "client_credentials",
apiKeyTitle: "apiKey",
apiKeyWarning: "userApiKeyWarning",
apiKeyDescription: "userApiKeyDesc",
},
});
}
async rotateUserApiKey() {
const entityId = await this.stateService.getUserId();
await ApiKeyComponent.open(this.dialogService, {
data: {
keyType: "user",
isRotation: true,
entityId: entityId,
postKey: this.apiService.postUserRotateApiKey.bind(this.apiService),
scope: "api",
grantType: "client_credentials",
apiKeyTitle: "apiKey",
apiKeyWarning: "userApiKeyWarning",
apiKeyDescription: "apiKeyRotateDesc",
},
});
}
}