1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00
Files
browser/apps/web/src/app/auth/settings/security/api-key.component.ts
Oscar Hinton ac49e594c1 Add standalone false to all non migrated (#14797)
Adds standalone: false to all components since Angular is changing the default to true and we'd rather not have the angular PR change 300+ files.
2025-05-15 10:44:07 -04:00

61 lines
2.2 KiB
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Component, Inject } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
import { SecretVerificationRequest } from "@bitwarden/common/auth/models/request/secret-verification.request";
import { ApiKeyResponse } from "@bitwarden/common/auth/models/response/api-key.response";
import { Verification } from "@bitwarden/common/auth/types/verification";
import { DIALOG_DATA, DialogConfig, DialogService } from "@bitwarden/components";
export type ApiKeyDialogData = {
keyType: string;
isRotation?: boolean;
entityId: string;
postKey: (entityId: string, request: SecretVerificationRequest) => Promise<ApiKeyResponse>;
scope: string;
grantType: string;
apiKeyTitle: string;
apiKeyWarning: string;
apiKeyDescription: string;
};
@Component({
selector: "app-api-key",
templateUrl: "api-key.component.html",
standalone: false,
})
export class ApiKeyComponent {
clientId: string;
clientSecret: string;
formGroup = this.formBuilder.group({
masterPassword: [null as Verification, [Validators.required]],
});
constructor(
@Inject(DIALOG_DATA) protected data: ApiKeyDialogData,
private formBuilder: FormBuilder,
private userVerificationService: UserVerificationService,
) {}
submit = async () => {
if (this.formGroup.invalid) {
this.formGroup.markAllAsTouched();
return;
}
const response = await this.userVerificationService
.buildRequest(this.formGroup.value.masterPassword)
.then((request) => this.data.postKey(this.data.entityId, request));
this.clientSecret = response.apiKey;
this.clientId = `${this.data.keyType}.${this.data.entityId}`;
};
/**
* Strongly typed helper to open a ApiKeyComponent
* @param dialogService Instance of the dialog service that will be used to open the dialog
* @param config Configuration for the dialog
*/
static open = (dialogService: DialogService, config: DialogConfig<ApiKeyDialogData>) => {
return dialogService.open(ApiKeyComponent, config);
};
}