From 7cf3166169465b51387a38eacabda024b5f4429c Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 23 Jul 2021 23:15:35 +0200 Subject: [PATCH] Add support for helpers in environment service (#139) * Add support for helpers in environment service * Bump jslib --- jslib | 2 +- src/app/services/services.module.ts | 6 +++--- src/bwdc.ts | 8 ++++---- src/services/api.service.ts | 5 +++-- src/services/auth.service.ts | 2 +- src/services/nodeApi.service.ts | 5 +++-- src/services/sync.service.ts | 8 +++++--- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/jslib b/jslib index 78ae9383..ecdd0862 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 78ae9383fbc1035bd27c022756cfa1f510ae16c9 +Subproject commit ecdd08624f61ccff8128b7cb3241f39e664e1c7f diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index c71602f7..95bfc0bd 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -70,9 +70,9 @@ const cryptoService = new CryptoService(storageService, secureStorageService, cr platformUtilsService, logService); const appIdService = new AppIdService(storageService); const tokenService = new TokenService(storageService); -const apiService = new ApiService(tokenService, platformUtilsService, refreshTokenCallback, +const environmentService = new EnvironmentService(storageService); +const apiService = new ApiService(tokenService, platformUtilsService, environmentService, refreshTokenCallback, async (expired: boolean) => messagingService.send('logout', { expired: expired })); -const environmentService = new EnvironmentService(apiService, storageService, null); const userService = new UserService(tokenService, storageService); const apiKeyService = new ApiKeyService(tokenService, storageService); const containerService = new ContainerService(cryptoService); @@ -80,7 +80,7 @@ const authService = new AuthService(cryptoService, apiService, userService, toke i18nService, platformUtilsService, messagingService, null, logService, apiKeyService, false); const configurationService = new ConfigurationService(storageService, secureStorageService); const syncService = new SyncService(configurationService, logService, cryptoFunctionService, apiService, - messagingService, i18nService); + messagingService, i18nService, environmentService); const passwordGenerationService = new PasswordGenerationService(cryptoService, storageService, null); const policyService = new PolicyService(userService, storageService); diff --git a/src/bwdc.ts b/src/bwdc.ts index 730e095b..ffcfda95 100644 --- a/src/bwdc.ts +++ b/src/bwdc.ts @@ -91,9 +91,9 @@ export class Main { this.appIdService = new AppIdService(this.storageService); this.tokenService = new TokenService(this.storageService); this.messagingService = new NoopMessagingService(); - this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService, this.refreshTokenCallback, - async (expired: boolean) => await this.logout()); - this.environmentService = new EnvironmentService(this.apiService, this.storageService, null); + this.environmentService = new EnvironmentService(this.storageService); + this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService, this.environmentService, + this.refreshTokenCallback, async (expired: boolean) => await this.logout()); this.apiKeyService = new ApiKeyService(this.tokenService, this.storageService); this.userService = new UserService(this.tokenService, this.storageService); this.containerService = new ContainerService(this.cryptoService); @@ -103,7 +103,7 @@ export class Main { this.configurationService = new ConfigurationService(this.storageService, this.secureStorageService, process.env.BITWARDENCLI_CONNECTOR_PLAINTEXT_SECRETS !== 'true'); this.syncService = new SyncService(this.configurationService, this.logService, this.cryptoFunctionService, - this.apiService, this.messagingService, this.i18nService); + this.apiService, this.messagingService, this.i18nService, this.environmentService); this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService, null); this.program = new Program(this); } diff --git a/src/services/api.service.ts b/src/services/api.service.ts index ef34dd0b..a0bf8ddc 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -1,5 +1,6 @@ import { ApiKeyService } from 'jslib-common/abstractions/apiKey.service'; import { AuthService } from 'jslib-common/abstractions/auth.service'; +import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { TokenService } from 'jslib-common/abstractions/token.service'; @@ -18,10 +19,10 @@ export async function refreshToken(apiKeyService: ApiKeyService, authService: Au } export class ApiService extends ApiServiceBase { - constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService, + constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService, private refreshTokenCallback: () => Promise, logoutCallback: (expired: boolean) => Promise, customUserAgent: string = null) { - super(tokenService, platformUtilsService, logoutCallback, customUserAgent); + super(tokenService, platformUtilsService, environmentService, logoutCallback, customUserAgent); } doRefreshToken(): Promise { diff --git a/src/services/auth.service.ts b/src/services/auth.service.ts index 638d5658..d7b0c7f1 100644 --- a/src/services/auth.service.ts +++ b/src/services/auth.service.ts @@ -45,7 +45,7 @@ export class AuthService extends AuthServiceBase { const appId = await this.appIdService.getAppId(); const deviceRequest = new DeviceRequest(appId, this.platformUtilsService); const request = new TokenRequest(null, null, [clientId, clientSecret], null, - null, false, deviceRequest); + null, false, null, deviceRequest); const response = await this.apiService.postIdentityToken(request); const result = new AuthResult(); diff --git a/src/services/nodeApi.service.ts b/src/services/nodeApi.service.ts index 2e3f9bfe..ccd2b1d8 100644 --- a/src/services/nodeApi.service.ts +++ b/src/services/nodeApi.service.ts @@ -1,13 +1,14 @@ +import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { TokenService } from 'jslib-common/abstractions/token.service'; import { NodeApiService as NodeApiServiceBase } from 'jslib-node/services/nodeApi.service'; export class NodeApiService extends NodeApiServiceBase { - constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService, + constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService, private refreshTokenCallback: () => Promise, logoutCallback: (expired: boolean) => Promise, customUserAgent: string = null) { - super(tokenService, platformUtilsService, logoutCallback, customUserAgent); + super(tokenService, platformUtilsService, environmentService, logoutCallback, customUserAgent); } doRefreshToken(): Promise { diff --git a/src/services/sync.service.ts b/src/services/sync.service.ts index ce59e880..7675ceb9 100644 --- a/src/services/sync.service.ts +++ b/src/services/sync.service.ts @@ -8,6 +8,7 @@ import { OrganizationImportRequest } from 'jslib-common/models/request/organizat import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; +import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; @@ -27,7 +28,8 @@ export class SyncService { constructor(private configurationService: ConfigurationService, private logService: LogService, private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService, - private messagingService: MessagingService, private i18nService: I18nService) { } + private messagingService: MessagingService, private i18nService: I18nService, + private environmentService: EnvironmentService) { } async sync(force: boolean, test: boolean): Promise<[GroupEntry[], UserEntry[]]> { this.dirType = await this.configurationService.getDirectoryType(); @@ -83,12 +85,12 @@ export class SyncService { // TODO: Remove hashLegacy once we're sure clients have had time to sync new hashes let hashLegacy: string = null; - const hashBuffLegacy = await this.cryptoFunctionService.hash(this.apiService.apiBaseUrl + reqJson, 'sha256'); + const hashBuffLegacy = await this.cryptoFunctionService.hash(this.environmentService.getApiUrl() + reqJson, 'sha256'); if (hashBuffLegacy != null) { hashLegacy = Utils.fromBufferToB64(hashBuffLegacy); } let hash: string = null; - const hashBuff = await this.cryptoFunctionService.hash(this.apiService.apiBaseUrl + orgId + reqJson, 'sha256'); + const hashBuff = await this.cryptoFunctionService.hash(this.environmentService.getApiUrl() + orgId + reqJson, 'sha256'); if (hashBuff != null) { hash = Utils.fromBufferToB64(hashBuff); }