mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
Implement User-based API Keys (#688)
* refactored api key modal for multiple key types * Added support for viewing and rotating user API keys * Fixed the API key component references in app.module * Implemented User ApiKey viewing/rotating * Changed ApiKey grant_type display to client_credentials * Hopefully put jslib back * Added new localization strings for user API keys * Toggled button text based on if viewing or rotating an api key * updated jslib * Reverted jslib * Trying to fix jslib * Reverted jslib from commit hash * Reupdated jslib
This commit is contained in:
53
src/app/settings/api-key.component.ts
Normal file
53
src/app/settings/api-key.component.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
import { ToasterService } from 'angular2-toaster';
|
||||
import { Angulartics2 } from 'angulartics2';
|
||||
|
||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
|
||||
import { PasswordVerificationRequest } from 'jslib/models/request/passwordVerificationRequest';
|
||||
|
||||
import { ApiKeyResponse } from 'jslib/models/response/apiKeyResponse';
|
||||
|
||||
@Component({
|
||||
selector: 'app-api-key',
|
||||
templateUrl: 'api-key.component.html',
|
||||
})
|
||||
export class ApiKeyComponent {
|
||||
keyType: string;
|
||||
isRotation: boolean;
|
||||
postKey: (entityId: string, request: PasswordVerificationRequest) => Promise<ApiKeyResponse>;
|
||||
entityId: string;
|
||||
scope: string;
|
||||
grantType: string;
|
||||
apiKeyTitle: string;
|
||||
apiKeyWarning: string;
|
||||
apiKeyDescription: string;
|
||||
|
||||
masterPassword: string;
|
||||
formPromise: Promise<ApiKeyResponse>;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
|
||||
constructor(private i18nService: I18nService, private analytics: Angulartics2,
|
||||
private toasterService: ToasterService, private cryptoService: CryptoService) { }
|
||||
|
||||
async submit() {
|
||||
if (this.masterPassword == null || this.masterPassword === '') {
|
||||
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
||||
this.i18nService.t('masterPassRequired'));
|
||||
return;
|
||||
}
|
||||
|
||||
const request = new PasswordVerificationRequest();
|
||||
request.masterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, null);
|
||||
try {
|
||||
this.formPromise = this.postKey(this.entityId, request);
|
||||
const response = await this.formPromise;
|
||||
this.clientSecret = response.apiKey;
|
||||
this.clientId = `${this.keyType}.${this.entityId}`;
|
||||
this.analytics.eventTrack.next({ action: `Viewed ${this.keyType} API Key` });
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user