@codex-ts/core-lib 1.0.19 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { InjectionToken, inject, PLATFORM_ID, signal, computed, Injectable, importProvidersFrom, APP_INITIALIZER, Component, NgModule, Directive, Input, ViewChild, Pipe } from '@angular/core';
|
|
3
3
|
import * as i1$2 from '@angular/common';
|
|
4
4
|
import { isPlatformBrowser, CommonModule, formatDate } from '@angular/common';
|
|
5
|
+
import Keycloak from 'keycloak-js';
|
|
5
6
|
import * as i1 from '@angular/common/http';
|
|
6
7
|
import { HTTP_INTERCEPTORS, HttpClientModule, HttpParams } from '@angular/common/http';
|
|
7
8
|
import { from, mergeMap, catchError, throwError, map, BehaviorSubject, finalize, Observable, forkJoin, of, isObservable, Subject, take as take$1, tap as tap$1, takeUntil as takeUntil$1, ReplaySubject, distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs';
|
|
@@ -159,34 +160,29 @@ class KeycloakService {
|
|
|
159
160
|
async initialize() {
|
|
160
161
|
if (!this.isBrowser)
|
|
161
162
|
return false;
|
|
162
|
-
await this.loadKeycloakScript();
|
|
163
163
|
const keycloak = new Keycloak({
|
|
164
164
|
url: this.config.authServerUrl,
|
|
165
165
|
realm: this.config.realm,
|
|
166
166
|
clientId: this.config.clientId
|
|
167
167
|
});
|
|
168
168
|
this.#keycloakInstance.set(keycloak);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
try {
|
|
170
|
+
const authenticated = await keycloak.init({
|
|
171
|
+
onLoad: 'login-required',
|
|
172
|
+
redirectUri: this.config.options?.loginRedirect || window.location.origin
|
|
173
|
+
});
|
|
174
|
+
this.#isAuthenticated.set(authenticated);
|
|
175
|
+
if (authenticated) {
|
|
176
|
+
await this.loadUserProfile();
|
|
177
|
+
}
|
|
178
|
+
return authenticated;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
console.error('Failed to initialize Keycloak:', error);
|
|
182
|
+
this.#keycloakInstance.set(null);
|
|
183
|
+
this.#isAuthenticated.set(false);
|
|
184
|
+
throw error;
|
|
176
185
|
}
|
|
177
|
-
return authenticated;
|
|
178
|
-
}
|
|
179
|
-
async loadKeycloakScript() {
|
|
180
|
-
if (typeof Keycloak !== 'undefined')
|
|
181
|
-
return;
|
|
182
|
-
const script = document.createElement('script');
|
|
183
|
-
script.src = `${this.config.authServerUrl}/js/keycloak.js`;
|
|
184
|
-
script.async = true;
|
|
185
|
-
await new Promise((resolve, reject) => {
|
|
186
|
-
script.onload = () => resolve();
|
|
187
|
-
script.onerror = () => reject(new Error('Failed to load Keycloak script'));
|
|
188
|
-
document.head.appendChild(script);
|
|
189
|
-
});
|
|
190
186
|
}
|
|
191
187
|
/** Login with optional redirect URI */
|
|
192
188
|
login(options = {}) {
|