diff --git a/angular/src/components/sso.component.ts b/angular/src/components/sso.component.ts index 8ca584beb8..51f2cb3b92 100644 --- a/angular/src/components/sso.component.ts +++ b/angular/src/components/sso.component.ts @@ -218,11 +218,13 @@ export class SsoComponent { } } catch (e) { this.logService.error(e); - if (e.message === "Unable to reach key connector") { + + // TODO: Key Connector Service should pass this error message to the logout callback instead of displaying here + if (e.message === "Key Connector error") { this.platformUtilsService.showToast( "error", null, - this.i18nService.t("ssoKeyConnectorUnavailable") + this.i18nService.t("ssoKeyConnectorError") ); } } diff --git a/angular/src/services/jslib-services.module.ts b/angular/src/services/jslib-services.module.ts index 900a38c048..ab4ca41eb2 100644 --- a/angular/src/services/jslib-services.module.ts +++ b/angular/src/services/jslib-services.module.ts @@ -399,6 +399,7 @@ export const SYSTEM_LANGUAGE = new InjectionToken("SYSTEM_LANGUAGE"); LogService, OrganizationServiceAbstraction, CryptoFunctionServiceAbstraction, + LOGOUT_CALLBACK, ], }, { diff --git a/common/src/services/keyConnector.service.ts b/common/src/services/keyConnector.service.ts index c7e8b991f8..8be5993528 100644 --- a/common/src/services/keyConnector.service.ts +++ b/common/src/services/keyConnector.service.ts @@ -22,7 +22,8 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { private tokenService: TokenService, private logService: LogService, private organizationService: OrganizationService, - private cryptoFunctionService: CryptoFunctionService + private cryptoFunctionService: CryptoFunctionService, + private logoutCallback: (expired: boolean, userId?: string) => void ) {} setUsesKeyConnector(usesKeyConnector: boolean) { @@ -52,7 +53,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { keyConnectorRequest ); } catch (e) { - throw new Error("Unable to reach key connector"); + this.handleKeyConnectorError(e); } await this.apiService.postConvertToKeyConnector(); @@ -65,8 +66,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { const k = new SymmetricCryptoKey(keyArr); await this.cryptoService.setKey(k); } catch (e) { - this.logService.error(e); - throw new Error("Unable to reach key connector"); + this.handleKeyConnectorError(e); } } @@ -102,7 +102,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { try { await this.apiService.postUserKeyToKeyConnector(keyConnectorUrl, keyConnectorRequest); } catch (e) { - throw new Error("Unable to reach key connector"); + this.handleKeyConnectorError(e); } const keys = new KeysRequest(pubKey, privKey.encryptedString); @@ -131,4 +131,12 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { async clear() { await this.removeConvertAccountRequired(); } + + private handleKeyConnectorError(e: any) { + this.logService.error(e); + if (this.logoutCallback != null) { + this.logoutCallback(false); + } + throw new Error("Key Connector error"); + } }