From 13a07aec6d4aef42397de43bc2d4c255310aa834 Mon Sep 17 00:00:00 2001
From: Annika Nowak <annika.nowak@capgemini.com>
Date: Wed, 5 Jun 2024 09:34:51 +0200
Subject: [PATCH 1/4] feat: angular custom auth

---
 .../src/lib/auth-service-wrapper.ts           | 45 ++++++++++++-------
 libs/angular-auth/src/lib/auth.service.ts     |  1 +
 .../src/lib/model/config-key.model.ts         |  1 +
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/libs/angular-auth/src/lib/auth-service-wrapper.ts b/libs/angular-auth/src/lib/auth-service-wrapper.ts
index c64670c9..c773c5ef 100644
--- a/libs/angular-auth/src/lib/auth-service-wrapper.ts
+++ b/libs/angular-auth/src/lib/auth-service-wrapper.ts
@@ -5,6 +5,7 @@ import { AppStateService, CONFIG_KEY, ConfigurationService } from '@onecx/angula
 import { Injectable, Injector } from '@angular/core'
 import { KeycloakAuthService } from './auth_services/keycloak-auth.service'
 import { loadRemoteModule } from '@angular-architects/module-federation'
+import { Config } from '@onecx/integration-interface'
 
 @Injectable()
 export class AuthServiceWrapper {
@@ -41,32 +42,42 @@ export class AuthServiceWrapper {
 
   async initializeAuthService(): Promise<void> {
     const serviceTypeConfig = this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE) ?? 'keycloak'
-    let factory
-    let module
-    const customUrl = this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)
+
     switch (serviceTypeConfig) {
       case 'keycloak':
         this.authService = this.injector.get(KeycloakAuthService)
         break
-      case 'custom':
-        if (!customUrl) {
-          throw new Error('URL of the custom auth service is not defined')
-        }
-        module = await loadRemoteModule({
-          type: 'module',
-          remoteEntry: customUrl,
-          exposedModule: './CustomAuth',
-        })
-        factory = module.default as AuthServiceFactory
+      case 'custom': {
+        let factory = await this.getAuthServiceFactory(this.configService)
         this.authService = factory((injectable: Injectables) => {
-          if (injectable === Injectables.KEYCLOAK_AUTH_SERVICE) {
-            return this.injector.get(KeycloakAuthService)
-          }
-          throw new Error('unknown injectable type')
+          return this.retrieveInjectables(injectable)
         })
         break
+      }
       default:
         throw new Error('Configured AuthService not found')
     }
   }
+
+  retrieveInjectables(injectable: Injectables): KeycloakAuthService | Config | undefined {
+    if (injectable === Injectables.KEYCLOAK_AUTH_SERVICE) {
+      return this.injector.get(KeycloakAuthService)
+    } else if (injectable === Injectables.CONFIG) {
+      return this.configService.getConfig()
+    }
+    throw new Error('unknown injectable type')
+  }
+
+  async getAuthServiceFactory(configService: ConfigurationService): Promise<AuthServiceFactory> {
+    if (!configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) {
+      throw new Error('URL of the custom auth service is not defined')
+    }
+    let module = await loadRemoteModule({
+      type: 'module',
+      remoteEntry: this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL) ?? '',
+      exposedModule: this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_MODULE_NAME) ?? './CustomAuth',
+    })
+    let factory = module.default as AuthServiceFactory
+    return factory
+  }
 }
diff --git a/libs/angular-auth/src/lib/auth.service.ts b/libs/angular-auth/src/lib/auth.service.ts
index 3fb1b8ce..27413c09 100644
--- a/libs/angular-auth/src/lib/auth.service.ts
+++ b/libs/angular-auth/src/lib/auth.service.ts
@@ -8,6 +8,7 @@ export interface AuthService {
 
 export enum Injectables {
   KEYCLOAK_AUTH_SERVICE = 'KEYCLOAK_AUTH_SERVICE',
+  CONFIG = 'CONFIG',
 }
 
 export type AuthServiceFactory = (injectorFunction: (injectable: Injectables) => unknown) => AuthService
diff --git a/libs/angular-integration-interface/src/lib/model/config-key.model.ts b/libs/angular-integration-interface/src/lib/model/config-key.model.ts
index 0146be2c..4c14ebaf 100644
--- a/libs/angular-integration-interface/src/lib/model/config-key.model.ts
+++ b/libs/angular-integration-interface/src/lib/model/config-key.model.ts
@@ -24,4 +24,5 @@ export enum CONFIG_KEY {
   IS_SHELL = 'IS_SHELL',
   AUTH_SERVICE = 'AUTH_SERVICE',
   AUTH_SERVICE_CUSTOM_URL = 'AUTH_SERVICE_CUSTOM_URL',
+  AUTH_SERVICE_CUSTOM_MODULE_NAME = 'AUTH_SERVICE_CUSTOM_MODULE_NAME',
 }

From 2522804661ae5f798eea403deb4eeafef6551081 Mon Sep 17 00:00:00 2001
From: Annika Nowak <annika.nowak@capgemini.com>
Date: Wed, 5 Jun 2024 09:46:56 +0200
Subject: [PATCH 2/4] fix: fix lint

---
 libs/angular-auth/src/lib/auth-service-wrapper.ts | 7 +++----
 package-lock.json                                 | 4 ++--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libs/angular-auth/src/lib/auth-service-wrapper.ts b/libs/angular-auth/src/lib/auth-service-wrapper.ts
index c773c5ef..22ecb7f2 100644
--- a/libs/angular-auth/src/lib/auth-service-wrapper.ts
+++ b/libs/angular-auth/src/lib/auth-service-wrapper.ts
@@ -48,7 +48,7 @@ export class AuthServiceWrapper {
         this.authService = this.injector.get(KeycloakAuthService)
         break
       case 'custom': {
-        let factory = await this.getAuthServiceFactory(this.configService)
+        const factory = await this.getAuthServiceFactory(this.configService)
         this.authService = factory((injectable: Injectables) => {
           return this.retrieveInjectables(injectable)
         })
@@ -72,12 +72,11 @@ export class AuthServiceWrapper {
     if (!configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) {
       throw new Error('URL of the custom auth service is not defined')
     }
-    let module = await loadRemoteModule({
+    const module = await loadRemoteModule({
       type: 'module',
       remoteEntry: this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL) ?? '',
       exposedModule: this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_MODULE_NAME) ?? './CustomAuth',
     })
-    let factory = module.default as AuthServiceFactory
-    return factory
+    return module.default as AuthServiceFactory
   }
 }
diff --git a/package-lock.json b/package-lock.json
index 6bf61240..4023c763 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "@onecx/onecx-portal-ui-libs",
-  "version": "4.24.0",
+  "version": "4.28.0",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "@onecx/onecx-portal-ui-libs",
-      "version": "4.24.0",
+      "version": "4.28.0",
       "hasInstallScript": true,
       "license": "Apache-2.0",
       "dependencies": {

From 0ce0b0f14b4499343b42d3e60d7d2c061267e4ad Mon Sep 17 00:00:00 2001
From: Annika Nowak <annika.nowak@capgemini.com>
Date: Wed, 5 Jun 2024 11:02:23 +0200
Subject: [PATCH 3/4] feat: package-lock.json updated after npm i save

---
 package-lock.json | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 4023c763..76e24ca0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "@onecx/onecx-portal-ui-libs",
-  "version": "4.28.0",
+  "version": "4.29.0",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "@onecx/onecx-portal-ui-libs",
-      "version": "4.28.0",
+      "version": "4.29.0",
       "hasInstallScript": true,
       "license": "Apache-2.0",
       "dependencies": {

From 0c0d08a292632159dd0b3d2bb4b2f361e0fc4a7a Mon Sep 17 00:00:00 2001
From: Annika Nowak <annika.nowak@capgemini.com>
Date: Wed, 5 Jun 2024 11:32:15 +0200
Subject: [PATCH 4/4] feat: changes from review

---
 libs/angular-auth/src/lib/auth-service-wrapper.ts | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libs/angular-auth/src/lib/auth-service-wrapper.ts b/libs/angular-auth/src/lib/auth-service-wrapper.ts
index 22ecb7f2..3a3c4966 100644
--- a/libs/angular-auth/src/lib/auth-service-wrapper.ts
+++ b/libs/angular-auth/src/lib/auth-service-wrapper.ts
@@ -48,10 +48,8 @@ export class AuthServiceWrapper {
         this.authService = this.injector.get(KeycloakAuthService)
         break
       case 'custom': {
-        const factory = await this.getAuthServiceFactory(this.configService)
-        this.authService = factory((injectable: Injectables) => {
-          return this.retrieveInjectables(injectable)
-        })
+        const factory = await this.getAuthServiceFactory()
+        this.authService = factory((injectable: Injectables) => this.retrieveInjectables(injectable))
         break
       }
       default:
@@ -68,8 +66,8 @@ export class AuthServiceWrapper {
     throw new Error('unknown injectable type')
   }
 
-  async getAuthServiceFactory(configService: ConfigurationService): Promise<AuthServiceFactory> {
-    if (!configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) {
+  async getAuthServiceFactory(): Promise<AuthServiceFactory> {
+    if (!this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) {
       throw new Error('URL of the custom auth service is not defined')
     }
     const module = await loadRemoteModule({