mirror of
https://github.com/bitwarden/browser
synced 2026-02-25 09:03:28 +00:00
* feat(user-decryption-options) [PM-26413]: Update UserDecryptionOptionsService and tests to use UserId-only APIs. * feat(user-decryption-options) [PM-26413]: Update InternalUserDecryptionOptionsService call sites to use UserId-only API. * feat(user-decryption-options) [PM-26413] Update userDecryptionOptions$ call sites to use the UserId-only API. * feat(user-decryption-options) [PM-26413]: Update additional call sites. * feat(user-decryption-options) [PM-26413]: Update dependencies and an additional call site. * feat(user-verification-service) [PM-26413]: Replace where allowed by unrestricted imports invocation of UserVerificationService.hasMasterPassword (deprecated) with UserDecryptionOptions.hasMasterPasswordById$. Additional work to complete as tech debt tracked in PM-27009. * feat(user-decryption-options) [PM-26413]: Update for non-null strict adherence. * feat(user-decryption-options) [PM-26413]: Update type safety and defensive returns. * chore(user-decryption-options) [PM-26413]: Comment cleanup. * feat(user-decryption-options) [PM-26413]: Update tests. * feat(user-decryption-options) [PM-26413]: Standardize null-checking on active account id for new API consumption. * feat(vault-timeout-settings-service) [PM-26413]: Add test cases to illustrate null active account from AccountService. * fix(fido2-user-verification-service-spec) [PM-26413]: Update test harness to use FakeAccountService. * fix(downstream-components) [PM-26413]: Prefer use of the getUserId operator in all authenticated contexts for user id provided to UserDecryptionOptionsService. --------- Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import { Component, OnInit } from "@angular/core";
|
|
import { firstValueFrom, map } from "rxjs";
|
|
|
|
import { UserDecryptionOptionsServiceAbstraction } from "@bitwarden/auth/common";
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
|
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
|
import { DialogService } from "@bitwarden/components";
|
|
|
|
import { ChangeKdfModule } from "../../../key-management/change-kdf/change-kdf.module";
|
|
import { SharedModule } from "../../../shared";
|
|
|
|
import { ApiKeyComponent } from "./api-key.component";
|
|
|
|
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
|
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
|
@Component({
|
|
templateUrl: "security-keys.component.html",
|
|
imports: [SharedModule, ChangeKdfModule],
|
|
})
|
|
export class SecurityKeysComponent implements OnInit {
|
|
showChangeKdf = true;
|
|
|
|
constructor(
|
|
private userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
|
|
private accountService: AccountService,
|
|
private apiService: ApiService,
|
|
private dialogService: DialogService,
|
|
) {}
|
|
|
|
async ngOnInit() {
|
|
const userId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
|
this.showChangeKdf = await firstValueFrom(
|
|
this.userDecryptionOptionsService.hasMasterPasswordById$(userId),
|
|
);
|
|
}
|
|
|
|
async viewUserApiKey() {
|
|
const entityId = await firstValueFrom(
|
|
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
|
);
|
|
|
|
if (!entityId) {
|
|
throw new Error("Active account not found");
|
|
}
|
|
|
|
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 firstValueFrom(
|
|
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
|
);
|
|
|
|
if (!entityId) {
|
|
throw new Error("Active account not found");
|
|
}
|
|
|
|
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",
|
|
},
|
|
});
|
|
}
|
|
}
|