diff --git a/common/src/abstractions/apiKey.service.ts b/common/src/abstractions/apiKey.service.ts index bc4b8a44..3d5b2a5e 100644 --- a/common/src/abstractions/apiKey.service.ts +++ b/common/src/abstractions/apiKey.service.ts @@ -6,4 +6,5 @@ export abstract class ApiKeyService { getEntityType: () => Promise; getEntityId: () => Promise; isAuthenticated: () => Promise; + migrateApiKeyStorage: () => Promise; } diff --git a/common/src/services/apiKey.service.ts b/common/src/services/apiKey.service.ts index 0b67781b..49dbb9d6 100644 --- a/common/src/services/apiKey.service.ts +++ b/common/src/services/apiKey.service.ts @@ -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(Keys.clientIdOld); + const oldClientSecret = await this.storageService.get(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;