@codex-ts/core-lib 1.0.17 → 1.0.19

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.
@@ -1,43 +1,17 @@
1
1
  /**
2
- * Keycloak initialization options
2
+ * Optional Keycloak configuration settings
3
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;
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
- /** OAuth2 scope */
53
- scope?: string;
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
- constructor(keycloakService: KeycloakService);
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: typeof initializeKeycloak;
18
+ useFactory: (keycloak: KeycloakService) => () => Promise<boolean>;
20
19
  multi: boolean;
21
20
  deps: (typeof KeycloakService)[];
22
21
  useValue?: undefined;
@@ -1,73 +1,34 @@
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<any>;
26
13
  /** Check if URL should be excluded from bearer token */
27
14
  isUrlExcluded(url: string): boolean;
28
- /** Validate Keycloak configuration */
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
- * Redirect to Keycloak login page
40
- * @param options Additional login options
41
- * @returns Promise resolving when login is complete
42
- */
43
- login(options?: any): Promise<void>;
44
- /**
45
- * Logout the current user
46
- * @returns Promise resolving when logout is complete
47
- */
17
+ private loadKeycloakScript;
18
+ /** Login with optional redirect URI */
19
+ login(options?: {
20
+ redirectUri?: string;
21
+ }): Promise<void>;
22
+ /** Logout the current user */
48
23
  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
- */
24
+ /** Get roles for the current user */
58
25
  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
- */
26
+ /** Check if user has a specific role */
64
27
  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
- */
70
- updateToken(minValidity?: number): Promise<boolean>;
28
+ /** Get the current access token */
29
+ getToken(): Promise<string | null>;
30
+ /** Update token if it's close to expiring */
31
+ private updateToken;
71
32
  private loadUserProfile;
72
33
  static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakService, never>;
73
34
  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.17",
3
+ "version": "1.0.19",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "peerDependencies": {
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Silent SSO Check</title>
5
- </head>
6
- <body>
7
- <script>
8
- parent.postMessage(location.href, location.origin);
9
- </script>
10
- </body>
11
- </html>