From e81342ff7fa74ea026a78c73da16b0279e93b663 Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Tue, 15 Oct 2024 11:59:57 +0100 Subject: [PATCH] Added fallback for injection --- lib/core/src/lib/auth/oidc/auth.module.ts | 5 +++-- lib/core/src/lib/auth/services/jwt-helper.service.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/core/src/lib/auth/oidc/auth.module.ts b/lib/core/src/lib/auth/oidc/auth.module.ts index 8aaaeb9192..fe7aecf50c 100644 --- a/lib/core/src/lib/auth/oidc/auth.module.ts +++ b/lib/core/src/lib/auth/oidc/auth.module.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { APP_INITIALIZER, inject, ModuleWithProviders, NgModule } from '@angular/core'; +import { APP_INITIALIZER, inject, ModuleWithProviders, NgModule, InjectionToken } from '@angular/core'; import { AUTH_CONFIG, OAuthModule, OAuthStorage } from 'angular-oauth2-oidc'; import { AuthenticationService } from '../services/authentication.service'; import { AuthModuleConfig, AUTH_MODULE_CONFIG } from './auth-config'; @@ -24,9 +24,10 @@ import { AuthRoutingModule } from './auth-routing.module'; import { AuthService } from './auth.service'; import { RedirectAuthService } from './redirect-auth.service'; import { AuthenticationConfirmationComponent } from './view/authentication-confirmation/authentication-confirmation.component'; -import { JWT_STORAGE_SERVICE } from '../services/jwt-helper.service'; import { StorageService } from '../../common/services/storage.service'; +export const JWT_STORAGE_SERVICE = new InjectionToken('JWT_STORAGE_SERVICE'); + /** * Create a Login Factory function * diff --git a/lib/core/src/lib/auth/services/jwt-helper.service.ts b/lib/core/src/lib/auth/services/jwt-helper.service.ts index 8dab41dc77..5dc1b15c28 100644 --- a/lib/core/src/lib/auth/services/jwt-helper.service.ts +++ b/lib/core/src/lib/auth/services/jwt-helper.service.ts @@ -15,11 +15,10 @@ * limitations under the License. */ -import { inject, Injectable, InjectionToken } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { OAuthStorage } from 'angular-oauth2-oidc'; import { StorageService } from '../../common/services/storage.service'; - -export const JWT_STORAGE_SERVICE = new InjectionToken('JWT_STORAGE_SERVICE'); +import { JWT_STORAGE_SERVICE } from '../oidc/auth.module'; @Injectable({ providedIn: 'root' @@ -36,7 +35,11 @@ export class JwtHelperService { static USER_PREFERRED_USERNAME = 'preferred_username'; static HXP_AUTHORIZATION = 'hxp_authorization'; - private storageService: OAuthStorage = inject(JWT_STORAGE_SERVICE) ?? inject(StorageService); + private storageService: OAuthStorage; + + constructor (@Inject(JWT_STORAGE_SERVICE) jwtStorageService: OAuthStorage, private defaultStorageService: StorageService) { + this.storageService = jwtStorageService ?? defaultStorageService; + } /** * Decodes a JSON web token into a JS object.