keycloak-angular 19.0.2 → 20.0.0

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,74 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Mauricio Gemelli Vigolo All Rights Reserved.
4
- *
5
- * Use of this source code is governed by a MIT-style license that can be
6
- * found in the LICENSE file at https://github.com/mauriciovigolo/keycloak-angular/blob/main/LICENSE.md
7
- */
8
- import { KeycloakConfig, KeycloakInitOptions } from 'keycloak-js';
9
- import { EnvironmentProviders, Provider } from '@angular/core';
10
- import { KeycloakFeature } from './features/keycloak.feature';
11
- /**
12
- * Options for configuring Keycloak and additional providers.
13
- */
14
- export type ProvideKeycloakOptions = {
15
- /**
16
- * Keycloak configuration, including the server URL, realm, and client ID.
17
- */
18
- config: KeycloakConfig;
19
- /**
20
- * Optional initialization options for the Keycloak instance.
21
- * If not provided, Keycloak will not initialize automatically.
22
- */
23
- initOptions?: KeycloakInitOptions;
24
- /**
25
- * Optional array of additional Angular providers or environment providers.
26
- */
27
- providers?: Array<Provider | EnvironmentProviders>;
28
- /**
29
- * Optional array of Keycloak features to extend the functionality of the Keycloak integration.
30
- */
31
- features?: Array<KeycloakFeature>;
32
- };
33
- /**
34
- * Configures and provides Keycloak as a dependency in an Angular application.
35
- *
36
- * This function initializes a Keycloak instance with the provided configuration and
37
- * optional initialization options. It integrates Keycloak into Angular dependency
38
- * injection system, allowing easy consumption throughout the application. Additionally,
39
- * it supports custom providers and Keycloak Angular features.
40
- *
41
- * If `initOptions` is not provided, the Keycloak instance will not be automatically initialized.
42
- * In such cases, the application must call `keycloak.init()` explicitly.
43
- *
44
- * @param options - Configuration object for Keycloak:
45
- * - `config`: The Keycloak configuration, including the server URL, realm, and client ID.
46
- * - `initOptions` (Optional): Initialization options for the Keycloak instance.
47
- * - `providers` (Optional): Additional Angular providers to include.
48
- * - `features` (Optional): Keycloak Angular features to configure during initialization.
49
- *
50
- * @returns An `EnvironmentProviders` object integrating Keycloak setup and additional providers.
51
- *
52
- * @example
53
- * ```ts
54
- * import { provideKeycloak } from './keycloak.providers';
55
- * import { bootstrapApplication } from '@angular/platform-browser';
56
- * import { AppComponent } from './app/app.component';
57
- *
58
- * bootstrapApplication(AppComponent, {
59
- * providers: [
60
- * provideKeycloak({
61
- * config: {
62
- * url: 'https://auth-server.example.com',
63
- * realm: 'my-realm',
64
- * clientId: 'my-client',
65
- * },
66
- * initOptions: {
67
- * onLoad: 'login-required',
68
- * },
69
- * }),
70
- * ],
71
- * });
72
- * ```
73
- */
74
- export declare function provideKeycloak(options: ProvideKeycloakOptions): EnvironmentProviders;
@@ -1,47 +0,0 @@
1
- import Keycloak from 'keycloak-js';
2
- import { UserActivityService } from './user-activity.service';
3
- import * as i0 from "@angular/core";
4
- /**
5
- * Configuration options for the `AutoRefreshTokenService`.
6
- */
7
- type AutoRefreshTokenOptions = {
8
- /**
9
- * Maximum allowed inactivity duration in milliseconds before
10
- * the session times out. Default is `50000`.
11
- */
12
- sessionTimeout?: number;
13
- /**
14
- * Action to take when the session times out due to inactivity.
15
- * Options are:
16
- * - `'login'`: Redirect to the Keycloak login page.
17
- * - `'logout'`: Log the user out of the session.
18
- * - `'none'`: Do nothing.
19
- * Default is `'logout'`.
20
- */
21
- onInactivityTimeout?: 'login' | 'logout' | 'none';
22
- };
23
- /**
24
- * Service to automatically manage the Keycloak token refresh process
25
- * based on user activity and token expiration events. This service
26
- * integrates with Keycloak for session management and interacts with
27
- * user activity monitoring to determine the appropriate action when
28
- * the token expires.
29
- *
30
- * The service listens to `KeycloakSignal` for token-related events
31
- * (e.g., `TokenExpired`) and provides configurable options for
32
- * session timeout and inactivity handling.
33
- */
34
- export declare class AutoRefreshTokenService {
35
- private readonly keycloak;
36
- private readonly userActivity;
37
- private options;
38
- private initialized;
39
- constructor(keycloak: Keycloak, userActivity: UserActivityService);
40
- private get defaultOptions();
41
- private executeOnInactivityTimeout;
42
- private processTokenExpiredEvent;
43
- start(options?: AutoRefreshTokenOptions): void;
44
- static ɵfac: i0.ɵɵFactoryDeclaration<AutoRefreshTokenService, never>;
45
- static ɵprov: i0.ɵɵInjectableDeclaration<AutoRefreshTokenService>;
46
- }
47
- export {};
@@ -1,66 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Mauricio Gemelli Vigolo All Rights Reserved.
4
- *
5
- * Use of this source code is governed by a MIT-style license that can be
6
- * found in the LICENSE file at https://github.com/mauriciovigolo/keycloak-angular/blob/main/LICENSE.md
7
- */
8
- import { OnDestroy, NgZone } from '@angular/core';
9
- import * as i0 from "@angular/core";
10
- /**
11
- * Service to monitor user activity in an Angular application.
12
- * Tracks user interactions (e.g., mouse movement, touch, key presses, clicks, and scrolls)
13
- * and updates the last activity timestamp. Consumers can check for user inactivity
14
- * based on a configurable timeout.
15
- *
16
- * The service is supposed to be used in the client context and for safety, it checks during the startup
17
- * if it is a browser context.
18
- */
19
- export declare class UserActivityService implements OnDestroy {
20
- private ngZone;
21
- /**
22
- * Signal to store the timestamp of the last user activity.
23
- * The timestamp is represented as the number of milliseconds since epoch.
24
- */
25
- private lastActivity;
26
- /**
27
- * Subject to signal the destruction of the service.
28
- * Used to clean up RxJS subscriptions.
29
- */
30
- private destroy$;
31
- /**
32
- * Computed signal to expose the last user activity as a read-only signal.
33
- */
34
- readonly lastActivitySignal: import("@angular/core").Signal<number>;
35
- constructor(ngZone: NgZone);
36
- /**
37
- * Starts monitoring user activity events (`mousemove`, `touchstart`, `keydown`, `click`, `scroll`)
38
- * and updates the last activity timestamp using RxJS with debounce.
39
- * The events are processed outside Angular zone for performance optimization.
40
- */
41
- startMonitoring(): void;
42
- /**
43
- * Updates the last activity timestamp to the current time.
44
- * This method runs inside Angular's zone to ensure reactivity with Angular signals.
45
- */
46
- private updateLastActivity;
47
- /**
48
- * Retrieves the timestamp of the last recorded user activity.
49
- * @returns {number} The last activity timestamp in milliseconds since epoch.
50
- */
51
- get lastActivityTime(): number;
52
- /**
53
- * Determines whether the user interacted with the application, meaning it is activily using the application, based on
54
- * the specified duration.
55
- * @param timeout - The inactivity timeout in milliseconds.
56
- * @returns {boolean} `true` if the user is inactive, otherwise `false`.
57
- */
58
- isActive(timeout: number): boolean;
59
- /**
60
- * Cleans up RxJS subscriptions and resources when the service is destroyed.
61
- * This method is automatically called by Angular when the service is removed.
62
- */
63
- ngOnDestroy(): void;
64
- static ɵfac: i0.ɵɵFactoryDeclaration<UserActivityService, never>;
65
- static ɵprov: i0.ɵɵInjectableDeclaration<UserActivityService>;
66
- }
@@ -1,118 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Mauricio Gemelli Vigolo All Rights Reserved.
4
- *
5
- * Use of this source code is governed by a MIT-style license that can be
6
- * found in the LICENSE file at https://github.com/mauriciovigolo/keycloak-angular/blob/main/LICENSE.md
7
- */
8
- import Keycloak, { KeycloakError } from 'keycloak-js';
9
- import { Signal, InjectionToken } from '@angular/core';
10
- /**
11
- * Keycloak event types, as described at the keycloak-js documentation:
12
- * https://www.keycloak.org/docs/latest/securing_apps/index.html#callback-events
13
- */
14
- export declare enum KeycloakEventType {
15
- /**
16
- * Keycloak Angular is not initialized yet. This is the initial state applied to the Keycloak Event Signal.
17
- * Note: This event is only emitted in Keycloak Angular, it is not part of the keycloak-js.
18
- */
19
- KeycloakAngularNotInitialized = "KeycloakAngularNotInitialized",
20
- /**
21
- * Keycloak Angular is in the process of initializing the providers and Keycloak Instance.
22
- * Note: This event is only emitted in Keycloak Angular, it is not part of the keycloak-js.
23
- */
24
- KeycloakAngularInit = "KeycloakAngularInit",
25
- /**
26
- * Triggered if there is an error during authentication.
27
- */
28
- AuthError = "AuthError",
29
- /**
30
- * Triggered when the user logs out. This event will only be triggered
31
- * if the session status iframe is enabled or in Cordova mode.
32
- */
33
- AuthLogout = "AuthLogout",
34
- /**
35
- * Triggered if an error occurs while attempting to refresh the token.
36
- */
37
- AuthRefreshError = "AuthRefreshError",
38
- /**
39
- * Triggered when the token is successfully refreshed.
40
- */
41
- AuthRefreshSuccess = "AuthRefreshSuccess",
42
- /**
43
- * Triggered when a user is successfully authenticated.
44
- */
45
- AuthSuccess = "AuthSuccess",
46
- /**
47
- * Triggered when the Keycloak adapter has completed initialization.
48
- */
49
- Ready = "Ready",
50
- /**
51
- * Triggered when the access token expires. Depending on the flow, you may
52
- * need to use `updateToken` to refresh the token or redirect the user
53
- * to the login screen.
54
- */
55
- TokenExpired = "TokenExpired",
56
- /**
57
- * Triggered when an authentication action is requested by the application.
58
- */
59
- ActionUpdate = "ActionUpdate"
60
- }
61
- /**
62
- * Arguments for the `Ready` event, representing the authentication state.
63
- */
64
- export type ReadyArgs = boolean;
65
- /**
66
- * Arguments for the `ActionUpdate` event, providing information about the status
67
- * and optional details about the action.
68
- */
69
- export type ActionUpdateArgs = {
70
- /**
71
- * Status of the action, indicating whether it was successful, encountered an error,
72
- * or was cancelled.
73
- */
74
- status: 'success' | 'error' | 'cancelled';
75
- /**
76
- * Optional name or identifier of the action performed.
77
- */
78
- action?: string;
79
- };
80
- /**
81
- * Arguments for the `AuthError` event, providing detailed error information.
82
- */
83
- export type AuthErrorArgs = KeycloakError;
84
- type EventArgs = ReadyArgs | ActionUpdateArgs | AuthErrorArgs;
85
- /**
86
- * Helper function to typecast unknown arguments into a specific Keycloak event type.
87
- *
88
- * @template T - The expected argument type.
89
- * @param args - The arguments to be cast.
90
- * @returns The arguments typed as `T`.
91
- */
92
- export declare const typeEventArgs: <T extends EventArgs>(args: unknown) => T;
93
- /**
94
- * Structure of a Keycloak event, including its type and optional arguments.
95
- */
96
- export interface KeycloakEvent {
97
- /**
98
- * Event type as described at {@link KeycloakEventType}.
99
- */
100
- type: KeycloakEventType;
101
- /**
102
- * Arguments from the keycloak-js event function.
103
- */
104
- args?: unknown;
105
- }
106
- /**
107
- * Creates a signal to manage Keycloak events, initializing the signal with
108
- * appropriate default values or values from a given Keycloak instance.
109
- *
110
- * @param keycloak - An instance of the Keycloak client.
111
- * @returns A `Signal` that tracks the current Keycloak event state.
112
- */
113
- export declare const createKeycloakSignal: (keycloak?: Keycloak) => import("@angular/core").WritableSignal<KeycloakEvent>;
114
- /**
115
- * Injection token for the Keycloak events signal, used for dependency injection.
116
- */
117
- export declare const KEYCLOAK_EVENT_SIGNAL: InjectionToken<Signal<KeycloakEvent>>;
118
- export {};
package/public_api.d.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Mauricio Gemelli Vigolo All Rights Reserved.
4
- *
5
- * Use of this source code is governed by a MIT-style license that can be
6
- * found in the LICENSE file at https://github.com/mauriciovigolo/keycloak-angular/blob/main/LICENSE.md
7
- */
8
- export * from './lib/legacy/public_api';
9
- export * from './lib/directives/has-roles.directive';
10
- export * from './lib/features/keycloak.feature';
11
- export * from './lib/features/with-refresh-token.feature';
12
- export * from './lib/guards/auth.guard';
13
- export * from './lib/interceptors/custom-bearer-token.interceptor';
14
- export * from './lib/interceptors/include-bearer-token.interceptor';
15
- export * from './lib/interceptors/keycloak.interceptor';
16
- export * from './lib/services/user-activity.service';
17
- export * from './lib/services/auto-refresh-token.service';
18
- export * from './lib/signals/keycloak-events-signal';
19
- export * from './lib/provide-keycloak';