mirror of
https://github.com/bitwarden/jslib
synced 2025-12-26 05:03:41 +00:00
Add token migrator
This commit is contained in:
@@ -6,4 +6,5 @@ export abstract class ApiKeyService {
|
||||
getEntityType: () => Promise<string>;
|
||||
getEntityId: () => Promise<string>;
|
||||
isAuthenticated: () => Promise<boolean>;
|
||||
migrateApiKeyStorage: () => Promise<any>;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import { TokenService } from '../abstractions/token.service';
|
||||
import { Utils } from '../misc/utils';
|
||||
|
||||
const Keys = {
|
||||
clientId: 'clientId',
|
||||
clientSecret: 'clientSecret',
|
||||
clientIdOld: 'clientId', // TODO: remove this migration when we are confident existing api keys are all migrated. Probably 1-2 releases.
|
||||
clientId: 'apikey_clientId',
|
||||
clientSecretOld: 'clientSecret', // TODO: remove this migration when we are confident existing api keys are all migrated. Probably 1-2 releases.
|
||||
clientSecret: 'apikey_clientSecret',
|
||||
entityType: 'entityType',
|
||||
entityId: 'entityId',
|
||||
};
|
||||
@@ -20,6 +22,22 @@ export class ApiKeyService implements ApiKeyServiceAbstraction {
|
||||
|
||||
constructor(private tokenService: TokenService, private storageService: StorageService) { }
|
||||
|
||||
// TODO: remove this migration when we are confident existing api keys are all migrated. Probably 1-2 releases.
|
||||
async migrateApiKeyStorage() {
|
||||
const oldClientId = await this.storageService.get<string>(Keys.clientIdOld);
|
||||
const oldClientSecret = await this.storageService.get<string>(Keys.clientSecretOld);
|
||||
|
||||
if (oldClientId != null) {
|
||||
await this.storageService.save(Keys.clientId, oldClientId);
|
||||
await this.storageService.remove(Keys.clientIdOld);
|
||||
}
|
||||
|
||||
if (oldClientSecret != null) {
|
||||
await this.storageService.save(Keys.clientSecret, oldClientSecret);
|
||||
await this.storageService.remove(Keys.clientSecretOld);
|
||||
}
|
||||
}
|
||||
|
||||
async setInformation(clientId: string, clientSecret: string) {
|
||||
this.clientId = clientId;
|
||||
this.clientSecret = clientSecret;
|
||||
|
||||
Reference in New Issue
Block a user