@codex-ts/core-lib 1.0.18 → 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.
- package/fesm2022/codex-ts-core-lib.mjs +87 -195
- package/fesm2022/codex-ts-core-lib.mjs.map +1 -1
- package/lib/keycloak/keycloak-config.interface.d.ts +15 -54
- package/lib/keycloak/keycloak.guard.d.ts +1 -0
- package/lib/keycloak/keycloak.interceptor.d.ts +2 -3
- package/lib/keycloak/keycloak.providers.d.ts +1 -2
- package/lib/keycloak/keycloak.service.d.ts +13 -53
- package/package.json +3 -2
|
@@ -1,43 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Keycloak
|
|
2
|
+
* Optional Keycloak configuration settings
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
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;
|
|
4
|
+
interface KeycloakOptions {
|
|
5
|
+
/** Enable/disable bearer token interceptor */
|
|
6
|
+
bearerToken?: boolean;
|
|
7
|
+
/** URLs to exclude from bearer token injection */
|
|
8
|
+
excludedUrls?: string[];
|
|
9
|
+
/** Where to redirect after login */
|
|
10
|
+
loginRedirect?: string;
|
|
11
|
+
/** Default roles to check */
|
|
12
|
+
roles?: string[];
|
|
13
|
+
/** Token validity threshold in seconds */
|
|
14
|
+
tokenValidityThreshold?: number;
|
|
41
15
|
}
|
|
42
16
|
/**
|
|
43
17
|
* Main Keycloak configuration
|
|
@@ -49,20 +23,7 @@ export interface KeycloakConfig {
|
|
|
49
23
|
realm: string;
|
|
50
24
|
/** Client ID */
|
|
51
25
|
clientId: string;
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
/** Enable/disable SSO */
|
|
55
|
-
useSSO?: boolean;
|
|
56
|
-
/** Enable/disable bearer token interceptor */
|
|
57
|
-
enableBearerInterceptor?: boolean;
|
|
58
|
-
/** Token validity threshold in seconds */
|
|
59
|
-
tokenValidityInSeconds?: number;
|
|
60
|
-
/** URLs to exclude from bearer token injection */
|
|
61
|
-
bearerExcludedUrls?: string[];
|
|
62
|
-
/** URL for silent SSO check */
|
|
63
|
-
silentCheckSsoRedirectUri?: string;
|
|
64
|
-
/** Login options */
|
|
65
|
-
loginOptions?: KeycloakLoginOptions;
|
|
66
|
-
/** Initialization options */
|
|
67
|
-
initOptions?: Partial<KeycloakInitOptions>;
|
|
26
|
+
/** Optional configuration settings */
|
|
27
|
+
options?: KeycloakOptions;
|
|
68
28
|
}
|
|
29
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
export declare class KeycloakAuthGuard {
|
|
5
5
|
private readonly keycloakService;
|
|
6
|
+
private readonly config;
|
|
6
7
|
private readonly router;
|
|
7
8
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree>;
|
|
8
9
|
private hasRequiredRoles;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { KeycloakService } from './keycloak.service';
|
|
4
3
|
import * as i0 from "@angular/core";
|
|
5
4
|
export declare class KeycloakAuthInterceptor implements HttpInterceptor {
|
|
6
|
-
private keycloakService;
|
|
7
|
-
|
|
5
|
+
private readonly keycloakService;
|
|
6
|
+
private readonly config;
|
|
8
7
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
|
|
9
8
|
static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakAuthInterceptor, never>;
|
|
10
9
|
static ɵprov: i0.ɵɵInjectableDeclaration<KeycloakAuthInterceptor>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { KeycloakConfig } from './keycloak-config.interface';
|
|
2
2
|
import { KeycloakService } from './keycloak.service';
|
|
3
3
|
import { KeycloakAuthInterceptor } from './keycloak.interceptor';
|
|
4
|
-
export declare function initializeKeycloak(keycloak: KeycloakService): () => Promise<boolean>;
|
|
5
4
|
/**
|
|
6
5
|
* Provides Keycloak authentication and authorization services
|
|
7
6
|
* @param config Keycloak configuration
|
|
@@ -16,7 +15,7 @@ export declare function provideKeycloak(config: KeycloakConfig): (typeof Keycloa
|
|
|
16
15
|
useClass?: undefined;
|
|
17
16
|
} | {
|
|
18
17
|
provide: import("@angular/core").InjectionToken<readonly (() => import("rxjs").Observable<unknown> | Promise<unknown> | void)[]>;
|
|
19
|
-
useFactory:
|
|
18
|
+
useFactory: (keycloak: KeycloakService) => () => Promise<boolean>;
|
|
20
19
|
multi: boolean;
|
|
21
20
|
deps: (typeof KeycloakService)[];
|
|
22
21
|
useValue?: undefined;
|
|
@@ -1,73 +1,33 @@
|
|
|
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
2
|
/**
|
|
16
3
|
* Service for handling Keycloak authentication and authorization
|
|
17
4
|
*/
|
|
18
5
|
export declare class KeycloakService {
|
|
19
6
|
#private;
|
|
20
|
-
private readonly http;
|
|
21
7
|
private readonly platformId;
|
|
22
8
|
private readonly config;
|
|
23
9
|
private readonly isBrowser;
|
|
24
10
|
readonly isAuthenticated$: import("@angular/core").Signal<boolean>;
|
|
25
11
|
readonly userProfile$: import("@angular/core").Signal<any>;
|
|
12
|
+
readonly token$: import("@angular/core").Signal<string | undefined>;
|
|
26
13
|
/** Check if URL should be excluded from bearer token */
|
|
27
14
|
isUrlExcluded(url: string): boolean;
|
|
28
|
-
/**
|
|
29
|
-
private validateConfig;
|
|
30
|
-
private loadKeycloakScript;
|
|
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
|
-
*/
|
|
15
|
+
/** Initialize Keycloak authentication */
|
|
37
16
|
initialize(): Promise<boolean>;
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
login(options?: any): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Logout the current user
|
|
46
|
-
* @returns Promise resolving when logout is complete
|
|
47
|
-
*/
|
|
17
|
+
/** Login with optional redirect URI */
|
|
18
|
+
login(options?: {
|
|
19
|
+
redirectUri?: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
/** Logout the current user */
|
|
48
22
|
logout(): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Get the current access token
|
|
51
|
-
* @returns Promise resolving to the access token or null
|
|
52
|
-
*/
|
|
53
|
-
getToken(): Promise<string | null>;
|
|
54
|
-
/**
|
|
55
|
-
* Get the current user's roles
|
|
56
|
-
* @returns Array of role names
|
|
57
|
-
*/
|
|
23
|
+
/** Get roles for the current user */
|
|
58
24
|
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
|
-
*/
|
|
25
|
+
/** Check if user has a specific role */
|
|
64
26
|
hasRole(role: string): boolean;
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*/
|
|
70
|
-
updateToken(minValidity?: number): Promise<boolean>;
|
|
27
|
+
/** Get the current access token */
|
|
28
|
+
getToken(): Promise<string | null>;
|
|
29
|
+
/** Update token if it's close to expiring */
|
|
30
|
+
private updateToken;
|
|
71
31
|
private loadUserProfile;
|
|
72
32
|
static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakService, never>;
|
|
73
33
|
static ɵprov: i0.ɵɵInjectableDeclaration<KeycloakService>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codex-ts/core-lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"peerDependencies": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"@angular/core": "^19.2.0",
|
|
9
9
|
"@ngx-formly/core": "^6.3.12",
|
|
10
10
|
"primeng": "^19.0.6",
|
|
11
|
-
"rxjs": "~7.8.0"
|
|
11
|
+
"rxjs": "~7.8.0",
|
|
12
|
+
"keycloak-js": "^22.0.0"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
15
|
"tslib": "^2.3.0"
|