@codex-ts/core-lib 1.0.16 → 1.0.18
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.
- package/fesm2022/codex-ts-core-lib.mjs +182 -35
- package/fesm2022/codex-ts-core-lib.mjs.map +1 -1
- package/lib/keycloak/keycloak-config.interface.d.ts +56 -7
- package/lib/keycloak/keycloak.interceptor.d.ts +11 -0
- package/lib/keycloak/keycloak.providers.d.ts +25 -0
- package/lib/keycloak/keycloak.service.d.ts +52 -0
- package/package.json +1 -1
- package/src/lib/assets/keycloak/silent-check-sso.html +0 -11
|
@@ -1,19 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keycloak initialization options
|
|
3
|
+
*/
|
|
4
|
+
export interface KeycloakInitOptions {
|
|
5
|
+
/** Authentication flow type */
|
|
6
|
+
onLoad: 'check-sso' | 'login-required' | 'check-sso-silent';
|
|
7
|
+
/** URL for silent SSO check */
|
|
8
|
+
silentCheckSsoRedirectUri?: string;
|
|
9
|
+
/** Enable/disable iframe check for SSO */
|
|
10
|
+
checkLoginIframe?: boolean;
|
|
11
|
+
/** Interval in seconds to check login state */
|
|
12
|
+
checkLoginIframeInterval?: number;
|
|
13
|
+
/** URI to redirect to after login */
|
|
14
|
+
redirectUri?: string;
|
|
15
|
+
/** OAuth2 flow type */
|
|
16
|
+
flow?: 'standard' | 'implicit' | 'hybrid';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Keycloak login options
|
|
20
|
+
*/
|
|
21
|
+
export interface KeycloakLoginOptions {
|
|
22
|
+
/** URI to redirect to after login */
|
|
23
|
+
redirectUri?: string;
|
|
24
|
+
/** Login prompt type */
|
|
25
|
+
prompt?: 'none' | 'login' | 'consent';
|
|
26
|
+
/** Maximum authentication age in seconds */
|
|
27
|
+
maxAge?: number;
|
|
28
|
+
/** Hint for the username/email field */
|
|
29
|
+
loginHint?: string;
|
|
30
|
+
/** Identity provider hint */
|
|
31
|
+
idpHint?: string;
|
|
32
|
+
/** OAuth2 scope */
|
|
33
|
+
scope?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Keycloak error response from server
|
|
37
|
+
*/
|
|
38
|
+
export interface KeycloakErrorResponse {
|
|
39
|
+
error: string;
|
|
40
|
+
error_description: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Main Keycloak configuration
|
|
44
|
+
*/
|
|
1
45
|
export interface KeycloakConfig {
|
|
46
|
+
/** Keycloak server URL (e.g., http://localhost:8180/auth) */
|
|
2
47
|
authServerUrl: string;
|
|
48
|
+
/** Realm name */
|
|
3
49
|
realm: string;
|
|
50
|
+
/** Client ID */
|
|
4
51
|
clientId: string;
|
|
52
|
+
/** OAuth2 scope */
|
|
5
53
|
scope?: string;
|
|
54
|
+
/** Enable/disable SSO */
|
|
6
55
|
useSSO?: boolean;
|
|
56
|
+
/** Enable/disable bearer token interceptor */
|
|
7
57
|
enableBearerInterceptor?: boolean;
|
|
58
|
+
/** Token validity threshold in seconds */
|
|
8
59
|
tokenValidityInSeconds?: number;
|
|
60
|
+
/** URLs to exclude from bearer token injection */
|
|
9
61
|
bearerExcludedUrls?: string[];
|
|
62
|
+
/** URL for silent SSO check */
|
|
10
63
|
silentCheckSsoRedirectUri?: string;
|
|
64
|
+
/** Login options */
|
|
11
65
|
loginOptions?: KeycloakLoginOptions;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
redirectUri?: string;
|
|
15
|
-
prompt?: 'none' | 'login' | 'consent';
|
|
16
|
-
maxAge?: number;
|
|
17
|
-
loginHint?: string;
|
|
18
|
-
idpHint?: string;
|
|
66
|
+
/** Initialization options */
|
|
67
|
+
initOptions?: Partial<KeycloakInitOptions>;
|
|
19
68
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { KeycloakService } from './keycloak.service';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export declare class KeycloakAuthInterceptor implements HttpInterceptor {
|
|
6
|
+
private keycloakService;
|
|
7
|
+
constructor(keycloakService: KeycloakService);
|
|
8
|
+
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
|
|
9
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakAuthInterceptor, never>;
|
|
10
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<KeycloakAuthInterceptor>;
|
|
11
|
+
}
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { KeycloakConfig } from './keycloak-config.interface';
|
|
2
2
|
import { KeycloakService } from './keycloak.service';
|
|
3
|
+
import { KeycloakAuthInterceptor } from './keycloak.interceptor';
|
|
4
|
+
export declare function initializeKeycloak(keycloak: KeycloakService): () => Promise<boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Provides Keycloak authentication and authorization services
|
|
7
|
+
* @param config Keycloak configuration
|
|
8
|
+
* @returns Array of providers for Keycloak integration
|
|
9
|
+
*/
|
|
3
10
|
export declare function provideKeycloak(config: KeycloakConfig): (typeof KeycloakService | import("@angular/core").EnvironmentProviders | {
|
|
4
11
|
provide: import("@angular/core").InjectionToken<KeycloakConfig>;
|
|
5
12
|
useValue: KeycloakConfig;
|
|
13
|
+
useFactory?: undefined;
|
|
14
|
+
multi?: undefined;
|
|
15
|
+
deps?: undefined;
|
|
16
|
+
useClass?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
provide: import("@angular/core").InjectionToken<readonly (() => import("rxjs").Observable<unknown> | Promise<unknown> | void)[]>;
|
|
19
|
+
useFactory: typeof initializeKeycloak;
|
|
20
|
+
multi: boolean;
|
|
21
|
+
deps: (typeof KeycloakService)[];
|
|
22
|
+
useValue?: undefined;
|
|
23
|
+
useClass?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
provide: import("@angular/core").InjectionToken<readonly import("@angular/common/http").HttpInterceptor[]>;
|
|
26
|
+
useClass: typeof KeycloakAuthInterceptor;
|
|
27
|
+
multi: boolean;
|
|
28
|
+
useValue?: undefined;
|
|
29
|
+
useFactory?: undefined;
|
|
30
|
+
deps?: undefined;
|
|
6
31
|
})[];
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
+
/** Keycloak error types */
|
|
3
|
+
export declare enum KeycloakErrorType {
|
|
4
|
+
SCRIPT_LOAD = "SCRIPT_LOAD_ERROR",
|
|
5
|
+
INIT = "INIT_ERROR",
|
|
6
|
+
TOKEN_REFRESH = "TOKEN_REFRESH_ERROR",
|
|
7
|
+
PROFILE_LOAD = "PROFILE_LOAD_ERROR"
|
|
8
|
+
}
|
|
9
|
+
/** Keycloak error with type and details */
|
|
10
|
+
export declare class KeycloakError extends Error {
|
|
11
|
+
type: KeycloakErrorType;
|
|
12
|
+
originalError?: any | undefined;
|
|
13
|
+
constructor(type: KeycloakErrorType, message: string, originalError?: any | undefined);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Service for handling Keycloak authentication and authorization
|
|
17
|
+
*/
|
|
2
18
|
export declare class KeycloakService {
|
|
3
19
|
#private;
|
|
4
20
|
private readonly http;
|
|
@@ -7,14 +23,50 @@ export declare class KeycloakService {
|
|
|
7
23
|
private readonly isBrowser;
|
|
8
24
|
readonly isAuthenticated$: import("@angular/core").Signal<boolean>;
|
|
9
25
|
readonly userProfile$: import("@angular/core").Signal<any>;
|
|
26
|
+
/** Check if URL should be excluded from bearer token */
|
|
27
|
+
isUrlExcluded(url: string): boolean;
|
|
28
|
+
/** Validate Keycloak configuration */
|
|
29
|
+
private validateConfig;
|
|
10
30
|
private loadKeycloakScript;
|
|
11
31
|
private getSilentCheckUrl;
|
|
32
|
+
/**
|
|
33
|
+
* Initialize Keycloak authentication
|
|
34
|
+
* @returns Promise resolving to true if initialization is successful
|
|
35
|
+
* @throws KeycloakError if initialization fails
|
|
36
|
+
*/
|
|
12
37
|
initialize(): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Redirect to Keycloak login page
|
|
40
|
+
* @param options Additional login options
|
|
41
|
+
* @returns Promise resolving when login is complete
|
|
42
|
+
*/
|
|
13
43
|
login(options?: any): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Logout the current user
|
|
46
|
+
* @returns Promise resolving when logout is complete
|
|
47
|
+
*/
|
|
14
48
|
logout(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Get the current access token
|
|
51
|
+
* @returns Promise resolving to the access token or null
|
|
52
|
+
*/
|
|
15
53
|
getToken(): Promise<string | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the current user's roles
|
|
56
|
+
* @returns Array of role names
|
|
57
|
+
*/
|
|
16
58
|
getRoles(): string[];
|
|
59
|
+
/**
|
|
60
|
+
* Check if the current user has a specific role
|
|
61
|
+
* @param role Role name to check
|
|
62
|
+
* @returns true if user has the role
|
|
63
|
+
*/
|
|
17
64
|
hasRole(role: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Update the access token if it's close to expiring
|
|
67
|
+
* @param minValidity Minimum validity time in seconds
|
|
68
|
+
* @returns Promise resolving to true if token was refreshed
|
|
69
|
+
*/
|
|
18
70
|
updateToken(minValidity?: number): Promise<boolean>;
|
|
19
71
|
private loadUserProfile;
|
|
20
72
|
static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakService, never>;
|
package/package.json
CHANGED