diff --git a/jslib b/jslib index 9950fb42..e595c054 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 9950fb42a15bad434a4b404419ff4a87af67a27b +Subproject commit e595c0548ed1a481dbd024ec66975e3a453bd471 diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 3a76e630..192b0286 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -30,7 +30,6 @@ import { NodeCryptoFunctionService } from "jslib-node/services/nodeCryptoFunctio import { StateService as StateServiceAbstraction } from "../../abstractions/state.service"; import { Account } from "../../models/account"; -import { refreshToken } from "../../services/api.service"; import { AuthService } from "../../services/auth.service"; import { I18nService } from "../../services/i18n.service"; import { NoopTwoFactorService } from "../../services/noop/noopTwoFactor.service"; @@ -41,14 +40,6 @@ import { SyncService } from "../../services/sync.service"; import { AuthGuardService } from "./auth-guard.service"; import { LaunchGuardService } from "./launch-guard.service"; -function refreshTokenCallback(injector: Injector) { - return () => { - const stateService = injector.get(StateServiceAbstraction); - const authService = injector.get(AuthServiceAbstraction); - return refreshToken(stateService, authService); - }; -} - export function initFactory( environmentService: EnvironmentServiceAbstraction, i18nService: I18nService, @@ -129,26 +120,26 @@ export function initFactory( platformUtilsService: PlatformUtilsServiceAbstraction, environmentService: EnvironmentServiceAbstraction, messagingService: MessagingServiceAbstraction, - injector: Injector + appIdService: AppIdServiceAbstraction ) => new NodeApiService( tokenService, platformUtilsService, environmentService, + appIdService, async (expired: boolean) => messagingService.send("logout", { expired: expired }), "Bitwarden_DC/" + platformUtilsService.getApplicationVersion() + " (" + platformUtilsService.getDeviceString().toUpperCase() + - ")", - refreshTokenCallback(injector) + ")" ), deps: [ TokenServiceAbstraction, PlatformUtilsServiceAbstraction, EnvironmentServiceAbstraction, MessagingServiceAbstraction, - Injector, + AppIdServiceAbstraction, ], }, { diff --git a/src/bwdc.ts b/src/bwdc.ts index ea7a5acb..568061f7 100644 --- a/src/bwdc.ts +++ b/src/bwdc.ts @@ -7,7 +7,6 @@ import { ClientType } from "jslib-common/enums/clientType"; import { LogLevelType } from "jslib-common/enums/logLevelType"; import { StateFactory } from "jslib-common/factories/stateFactory"; import { GlobalState } from "jslib-common/models/domain/globalState"; -import { ApiLogInCredentials } from "jslib-common/models/domain/logInCredentials"; import { AppIdService } from "jslib-common/services/appId.service"; import { CipherService } from "jslib-common/services/cipher.service"; import { CollectionService } from "jslib-common/services/collection.service"; @@ -149,18 +148,20 @@ export class Main { this.tokenService = new TokenService(this.stateService); this.messagingService = new NoopMessagingService(); this.environmentService = new EnvironmentService(this.stateService); + + const customUserAgent = + "Bitwarden_DC/" + + this.platformUtilsService.getApplicationVersion() + + " (" + + this.platformUtilsService.getDeviceString().toUpperCase() + + ")"; this.apiService = new NodeApiService( this.tokenService, this.platformUtilsService, this.environmentService, + this.appIdService, async (expired: boolean) => await this.logout(), - "Bitwarden_DC/" + - this.platformUtilsService.getApplicationVersion() + - " (" + - this.platformUtilsService.getDeviceString().toUpperCase() + - ")", - (clientId, clientSecret) => - this.authService.logIn(new ApiLogInCredentials(clientId, clientSecret)) + customUserAgent ); this.containerService = new ContainerService(this.cryptoService); diff --git a/src/services/api.service.ts b/src/services/api.service.ts deleted file mode 100644 index 6c0dc5d0..00000000 --- a/src/services/api.service.ts +++ /dev/null @@ -1,37 +0,0 @@ -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"; -import { ApiLogInCredentials } from "jslib-common/models/domain/logInCredentials"; -import { ApiService as ApiServiceBase } from "jslib-common/services/api.service"; - -import { StateService } from "../abstractions/state.service"; - -export async function refreshToken(stateService: StateService, authService: AuthService) { - try { - const clientId = await stateService.getApiKeyClientId(); - const clientSecret = await stateService.getApiKeyClientSecret(); - if (clientId != null && clientSecret != null) { - await authService.logIn(new ApiLogInCredentials(clientId, clientSecret)); - } - } catch (e) { - return Promise.reject(e); - } -} - -export class ApiService extends ApiServiceBase { - constructor( - tokenService: TokenService, - platformUtilsService: PlatformUtilsService, - environmentService: EnvironmentService, - private refreshTokenCallback: () => Promise, - logoutCallback: (expired: boolean) => Promise, - customUserAgent: string = null - ) { - super(tokenService, platformUtilsService, environmentService, logoutCallback, customUserAgent); - } - - doRefreshToken(): Promise { - return this.refreshTokenCallback(); - } -}