@odx/auth 14.0.0 → 15.0.1

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/esm2022/lib/auth.component.mjs +9 -4
  3. package/esm2022/lib/auth.config.mjs +38 -1
  4. package/esm2022/lib/auth.directive.mjs +14 -4
  5. package/esm2022/lib/auth.guard.mjs +9 -1
  6. package/esm2022/lib/auth.interceptor.mjs +8 -1
  7. package/esm2022/lib/auth.module.mjs +4 -4
  8. package/esm2022/lib/auth.providers.mjs +35 -1
  9. package/esm2022/lib/auth.service.mjs +162 -4
  10. package/esm2022/lib/components/auth-actions/auth-actions.component.mjs +13 -4
  11. package/esm2022/lib/components/auth-loading-screen/auth-loading-screen.component.mjs +18 -6
  12. package/esm2022/lib/directives/auth-action.directive.mjs +10 -4
  13. package/esm2022/lib/directives/sign-in.directive.mjs +23 -4
  14. package/esm2022/lib/directives/sign-out.directive.mjs +23 -4
  15. package/esm2022/lib/helpers/create-auth-host-url.mjs +13 -1
  16. package/esm2022/lib/helpers/create-inititals.mjs +18 -1
  17. package/esm2022/lib/helpers/handle-auth-error.mjs +13 -3
  18. package/esm2022/lib/helpers/handle-oauth-event.mjs +9 -1
  19. package/esm2022/lib/helpers/resolve-email.mjs +21 -1
  20. package/esm2022/lib/helpers/resolve-username.mjs +22 -1
  21. package/esm2022/lib/helpers/set-http-auth-header.mjs +10 -1
  22. package/esm2022/lib/helpers/user-language-loader.mjs +8 -1
  23. package/esm2022/lib/models/auth-plugin-manager.mjs +3 -3
  24. package/esm2022/lib/plugins/core-debug.plugin.mjs +10 -1
  25. package/esm2022/lib/plugins/core-identity.plugin.mjs +8 -1
  26. package/esm2022/lib/plugins/user-profile-link.plugin.mjs +10 -1
  27. package/esm2022/lib/unauth.guard.mjs +9 -1
  28. package/esm2022/plugins/service-connect/lib/helpers/build-service-connect-url.mjs +8 -1
  29. package/esm2022/plugins/service-connect/lib/helpers/has-roles-or-rights-handler.mjs +8 -1
  30. package/esm2022/plugins/service-connect/lib/helpers/has-roles-or-rights.mjs +8 -1
  31. package/esm2022/plugins/service-connect/lib/helpers/service-connect-plugin-factory.mjs +7 -1
  32. package/esm2022/plugins/service-connect/lib/service-connect-rights.directive.mjs +16 -4
  33. package/esm2022/plugins/service-connect/lib/service-connect-rights.guard.mjs +9 -1
  34. package/esm2022/plugins/service-connect/lib/service-connect-rights.plugin.mjs +9 -1
  35. package/esm2022/plugins/service-connect/lib/service-connect-user-language.plugin.mjs +15 -1
  36. package/esm2022/plugins/service-connect/lib/service-connect-user-profile.plugin.mjs +9 -1
  37. package/fesm2022/odx-auth-plugins-service-connect.mjs +80 -3
  38. package/fesm2022/odx-auth-plugins-service-connect.mjs.map +1 -1
  39. package/fesm2022/odx-auth.mjs +497 -36
  40. package/fesm2022/odx-auth.mjs.map +1 -1
  41. package/lib/auth.component.d.ts +5 -0
  42. package/lib/auth.config.d.ts +43 -1
  43. package/lib/auth.directive.d.ts +10 -0
  44. package/lib/auth.guard.d.ts +8 -0
  45. package/lib/auth.interceptor.d.ts +7 -0
  46. package/lib/auth.providers.d.ts +34 -0
  47. package/lib/auth.service.d.ts +156 -0
  48. package/lib/components/auth-actions/auth-actions.component.d.ts +9 -0
  49. package/lib/components/auth-loading-screen/auth-loading-screen.component.d.ts +13 -0
  50. package/lib/directives/auth-action.directive.d.ts +6 -0
  51. package/lib/directives/sign-in.directive.d.ts +19 -0
  52. package/lib/directives/sign-out.directive.d.ts +19 -0
  53. package/lib/helpers/create-auth-host-url.d.ts +12 -0
  54. package/lib/helpers/create-inititals.d.ts +17 -0
  55. package/lib/helpers/handle-auth-error.d.ts +10 -0
  56. package/lib/helpers/handle-oauth-event.d.ts +8 -0
  57. package/lib/helpers/resolve-email.d.ts +20 -0
  58. package/lib/helpers/resolve-username.d.ts +21 -0
  59. package/lib/helpers/set-http-auth-header.d.ts +9 -0
  60. package/lib/helpers/user-language-loader.d.ts +7 -0
  61. package/lib/plugins/core-debug.plugin.d.ts +9 -0
  62. package/lib/plugins/core-identity.plugin.d.ts +7 -0
  63. package/lib/plugins/user-profile-link.plugin.d.ts +9 -0
  64. package/lib/unauth.guard.d.ts +8 -0
  65. package/package.json +2 -2
  66. package/plugins/service-connect/lib/helpers/build-service-connect-url.d.ts +7 -0
  67. package/plugins/service-connect/lib/helpers/has-roles-or-rights-handler.d.ts +7 -0
  68. package/plugins/service-connect/lib/helpers/has-roles-or-rights.d.ts +7 -0
  69. package/plugins/service-connect/lib/helpers/service-connect-plugin-factory.d.ts +6 -0
  70. package/plugins/service-connect/lib/service-connect-rights.directive.d.ts +12 -0
  71. package/plugins/service-connect/lib/service-connect-rights.guard.d.ts +8 -0
  72. package/plugins/service-connect/lib/service-connect-rights.plugin.d.ts +8 -0
  73. package/plugins/service-connect/lib/service-connect-user-language.plugin.d.ts +14 -0
  74. package/plugins/service-connect/lib/service-connect-user-profile.plugin.d.ts +8 -0
@@ -3,6 +3,30 @@ import { AuthConfig, OAuthErrorEvent, TokenResponse } from 'angular-oauth2-oidc'
3
3
  import { Observable } from 'rxjs';
4
4
  import { AuthorizedHandler } from './models';
5
5
  import * as i0 from "@angular/core";
6
+ /**
7
+ * The `AuthService` class provides authentication functionality for an Angular application.
8
+ * It handles OAuth2/OIDC authentication, token management, and user identity claims.
9
+ *
10
+ * Key responsibilities include:
11
+ * - Initializing authentication with a provided configuration.
12
+ * - Managing tokens (access, refresh, and ID tokens).
13
+ * - Checking and emitting authentication and authorization states.
14
+ * - Handling user login and logout flows.
15
+ * - Supporting silent refresh and offline authentication scenarios.
16
+ * - Integrating authentication plugins via `AuthPluginManager`.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Injecting the AuthService
21
+ * constructor(private authService: AuthService) {}
22
+ *
23
+ * // Using the AuthService to initialize authentication
24
+ * async ngOnInit() {
25
+ * const config: AuthConfig = { clientId: 'your-client-id', discoveryUrl: 'https://example.com/.well-known/openid-configuration' };
26
+ * await this.authService.initialize(config);
27
+ * }
28
+ * ```
29
+ */
6
30
  export declare class AuthService {
7
31
  private readonly authConfig;
8
32
  private readonly authPluginManager;
@@ -14,29 +38,161 @@ export declare class AuthService {
14
38
  private readonly onAccessTokenUpdate$;
15
39
  private readonly silentRefreshHandler$;
16
40
  private readonly onAuthStateChange$;
41
+ /**
42
+ * Emits `true` when the service has completed initialization.
43
+ * Emits `false` until the initialization is complete.
44
+ *
45
+ * @type {Observable<boolean>}
46
+ */
17
47
  readonly isInitialized$: Observable<true>;
48
+ /**
49
+ * Emits `true` when the user is being redirected to the login page.
50
+ * Emits `false` when there is no redirection in progress.
51
+ *
52
+ * @type {Observable<boolean>}
53
+ */
18
54
  readonly isRedirecting$: Observable<boolean>;
55
+ /**
56
+ * Emits `true` when the application is in a loading state (e.g., during redirection or plugin initialization).
57
+ * Emits `false` when there is no ongoing loading activity.
58
+ *
59
+ * @type {Observable<boolean>}
60
+ */
19
61
  readonly isLoading$: Observable<boolean>;
62
+ /**
63
+ * Emits `true` when the user is authenticated.
64
+ * Emits `false` when the user is not authenticated.
65
+ *
66
+ * @type {Observable<boolean>}
67
+ */
20
68
  readonly isAuthenticated$: Observable<boolean>;
69
+ /**
70
+ * Emits the identity claims of the authenticated user.
71
+ * If the user is not authenticated, emits `null`.
72
+ *
73
+ * @type {Observable<OdxAuth.IdentityClaims | null>}
74
+ */
21
75
  readonly identityClaims$: Observable<OdxAuth.IdentiyClaims | null>;
76
+ /**
77
+ * Emits OAuth error events.
78
+ *
79
+ * @type {Observable<OAuthErrorEvent>}
80
+ */
22
81
  readonly errors$: Observable<OAuthErrorEvent>;
82
+ /**
83
+ * Emits events when an OAuth token is successfully received.
84
+ *
85
+ * @type {Observable<Event>}
86
+ */
23
87
  readonly onTokenReceived$: Observable<import("angular-oauth2-oidc").OAuthEvent>;
88
+ /**
89
+ * Emits whenever the `access_token` in local storage is updated or cleared.
90
+ * Provides an observable for tracking token updates.
91
+ *
92
+ * @type {Observable<StorageEvent | null>}
93
+ */
94
+ get accessTokenUpdate$(): Observable<StorageEvent | null>;
24
95
  constructor();
96
+ /**
97
+ * Initializes the authentication service with the provided configuration.
98
+ *
99
+ * @param {AuthConfig} config - The authentication configuration object.
100
+ * @returns {Promise<void>} Resolves when initialization is complete.
101
+ */
25
102
  initialize(config: AuthConfig): Promise<void>;
103
+ /**
104
+ * Runs all authentication plugins registered in the `AuthPluginManager`.
105
+ */
26
106
  runPlugins(): void;
107
+ /**
108
+ * Returns the issuer URL for the OAuth server.
109
+ *
110
+ * @returns {URL} The issuer URL.
111
+ */
27
112
  getIssuer(): URL;
113
+ /**
114
+ * Initiates the login flow for the user. Redirects to the login page.
115
+ *
116
+ * @param {string} [url] - The URL to redirect back to after login.
117
+ */
28
118
  signIn(url?: string): void;
119
+ /**
120
+ * Logs the user out and clears their tokens.
121
+ *
122
+ * @param {boolean} [noRedirect] - If `true`, no redirection occurs after logout.
123
+ */
29
124
  signOut(noRedirect?: boolean): void;
125
+ /**
126
+ * Attempts to refresh the user's tokens.
127
+ *
128
+ * @returns {Promise<TokenResponse>} Resolves with the new token response.
129
+ */
30
130
  refreshTokens(): Promise<TokenResponse>;
131
+ /**
132
+ * Retrieves the current access token, if available.
133
+ *
134
+ * @returns {string | null} The access token, or `null` if not available.
135
+ */
31
136
  getAccessToken(): string | null;
137
+ /**
138
+ * Retrieves the current refresh token, if available.
139
+ *
140
+ * @returns {string | null} The refresh token, or `null` if not available.
141
+ */
32
142
  getRefreshToken(): string | null;
143
+ /**
144
+ * Retrieves the current ID token, if available.
145
+ *
146
+ * @returns {string | null} The ID token, or `null` if not available.
147
+ */
33
148
  getIdToken(): string | null;
149
+ /**
150
+ * Retrieves the identity claims of the authenticated user.
151
+ *
152
+ * @returns {OdxAuth.IdentityClaims | null} The identity claims, or `null` if not available.
153
+ */
34
154
  getIdentityClaims(): OdxAuth.IdentiyClaims | null;
155
+ /**
156
+ * Retrieves the raw identity claims of the authenticated user.
157
+ *
158
+ * @returns {OdxAuth.RawIdentityClaims | null} The raw identity claims, or `null` if not available.
159
+ */
35
160
  getRawIdentityClaims(): OdxAuth.RawIdentityClaims | null;
161
+ /**
162
+ * Checks if the user is currently authenticated.
163
+ *
164
+ * @returns {boolean} `true` if authenticated, otherwise `false`.
165
+ */
36
166
  isAuthenticated(): boolean;
167
+ /**
168
+ * Checks if the user is authorized based on the provided handler.
169
+ *
170
+ * @param {AuthorizedHandler | null} [authorizedHandler] - A handler to determine authorization.
171
+ * @returns {boolean} `true` if authorized, otherwise `false`.
172
+ */
37
173
  isAuthorized(authorizedHandler?: AuthorizedHandler | null): boolean;
174
+ /**
175
+ * Emits whether the user is authorized based on the provided handler.
176
+ *
177
+ * @param {AuthorizedHandler | null} [authorizedHandler] - A handler to determine authorization.
178
+ * @returns {Observable<boolean>} An observable emitting the authorization status.
179
+ */
38
180
  isAuthorized$(authorizedHandler?: AuthorizedHandler | null): Observable<boolean>;
181
+ /**
182
+ * Prepares an HTTP request by adding the access token to its headers.
183
+ *
184
+ * @param {HttpRequest<T> | Request} req - The HTTP request to prepare.
185
+ * @param {boolean} requireSignIn - Whether to require the user to sign in if no token is available.
186
+ * @returns {Observable<R>} An observable emitting the prepared request.
187
+ * @template R, T
188
+ */
39
189
  prepareAuthRequest$<R extends HttpRequest<T> | Request, T>(req: R, requireSignIn?: boolean): Observable<R>;
190
+ /**
191
+ * Waits for a valid access token to become available.
192
+ *
193
+ * @param {boolean} requireSignIn - Whether to require the user to sign in if no token is available.
194
+ * @returns {Observable<string | null>} An observable emitting the access token.
195
+ */
40
196
  waitForAccessToken$(requireSignIn: boolean): Observable<string | null>;
41
197
  private routeToRequestedUrl;
42
198
  private hasValidOfflineToken;
@@ -1,6 +1,15 @@
1
1
  import * as i0 from "@angular/core";
2
+ /**
3
+ * Displays authentication actions.
4
+ */
2
5
  export declare class AuthActionsComponent {
3
6
  readonly element: import("@angular/core").ElementRef<HTMLElement>;
7
+ /**
8
+ * The identity claims.
9
+ *
10
+ * @type {OdxAuth.IdentiyClaims | null}
11
+ * @default null
12
+ */
4
13
  claims: OdxAuth.IdentiyClaims | null;
5
14
  static ɵfac: i0.ɵɵFactoryDeclaration<AuthActionsComponent, never>;
6
15
  static ɵcmp: i0.ɵɵComponentDeclaration<AuthActionsComponent, "odx-auth-actions", never, { "claims": { "alias": "claims"; "required": false; }; }, {}, never, never, true, never>;
@@ -1,10 +1,23 @@
1
1
  import { DynamicViewService } from '@odx/angular/cdk/dynamic-view';
2
2
  import { AuthService } from '../../auth.service';
3
3
  import * as i0 from "@angular/core";
4
+ /**
5
+ * Authentication loading screen.
6
+ *
7
+ * This component displays a loading screen with animations and dynamic content
8
+ * based on the authentication state.
9
+ */
4
10
  export declare class AuthLoadingScreenComponent {
5
11
  private static instance;
6
12
  protected readonly authConfig: import("../../auth.config").AuthConfig;
7
13
  protected readonly icon$: import("rxjs").Observable<"link-external" | "user">;
14
+ /**
15
+ * Initializes the authentication loading screen.
16
+ *
17
+ * @param {AuthService} authService - The authentication service.
18
+ * @param {DynamicViewService} dynamicViewService - The dynamic view service used to create the loading screen.
19
+ * @static
20
+ */
8
21
  static initialize(authService: AuthService, dynamicViewService: DynamicViewService): void;
9
22
  static ɵfac: i0.ɵɵFactoryDeclaration<AuthLoadingScreenComponent, never>;
10
23
  static ɵcmp: i0.ɵɵComponentDeclaration<AuthLoadingScreenComponent, "div.odx-auth-loading-screen", never, {}, {}, never, never, true, never>;
@@ -1,6 +1,12 @@
1
1
  import { AfterViewInit } from '@angular/core';
2
2
  import { AuthService } from '../auth.service';
3
3
  import * as i0 from "@angular/core";
4
+ /**
5
+ * An abstract directive that integrates with the `LoadingSpinnerDirective` and `AuthService` to manage loading states based on authentication redirection.
6
+ *
7
+ * This directive automatically sets the `autoColor` property of the `LoadingSpinnerDirective` to `true` and subscribes to the `isRedirecting$` observable from the `AuthService`.
8
+ * When `isRedirecting$` emits a value, it updates the `isLoading` property of the `LoadingSpinnerDirective`.
9
+ */
4
10
  export declare abstract class AuthActionDirective implements AfterViewInit {
5
11
  private readonly takeUntilDestroyed;
6
12
  private readonly loadingSpinnerDirective;
@@ -1,8 +1,27 @@
1
+ /**
2
+ * A directive that handles the sign-in action for a button element.
3
+ *
4
+ * This directive extends the `AuthActionDirective` and uses the `LoadingSpinnerDirective`
5
+ * to show a loading spinner during the sign-in process.
6
+ *
7
+ * @see {AuthActionDirective}
8
+ * @see {LoadingSpinnerDirective}
9
+ *
10
+ * @example
11
+ * ```html
12
+ * <button odxButton odxAuthSignIn (odxAuthSignIn)="onSignIn()">Sign In</button>
13
+ * ```
14
+ */
1
15
  import { EventEmitter } from '@angular/core';
2
16
  import { AuthActionDirective } from './auth-action.directive';
3
17
  import * as i0 from "@angular/core";
4
18
  import * as i1 from "@odx/angular/components/loading-spinner";
5
19
  export declare class SignInDirective extends AuthActionDirective {
20
+ /**
21
+ * Emits an event after the sign-in action is completed.
22
+ *
23
+ * @type {EventEmitter<void>}
24
+ */
6
25
  afterSignIn: EventEmitter<void>;
7
26
  protected handleClick(): void;
8
27
  static ɵfac: i0.ɵɵFactoryDeclaration<SignInDirective, never>;
@@ -2,7 +2,26 @@ import { EventEmitter } from '@angular/core';
2
2
  import { AuthActionDirective } from './auth-action.directive';
3
3
  import * as i0 from "@angular/core";
4
4
  import * as i1 from "@odx/angular/components/loading-spinner";
5
+ /**
6
+ * A directive that handles the sign-out action for a button element.
7
+ *
8
+ * This directive extends the `AuthActionDirective` and uses the `LoadingSpinnerDirective`
9
+ * to show a loading spinner during the sign-out process.
10
+ *
11
+ * @see {AuthActionDirective}
12
+ * @see {LoadingSpinnerDirective}
13
+ *
14
+ * @example
15
+ * ```html
16
+ * <button odxButton odxAuthSignOut (odxAuthSignOut)="onSignOut()">Sign Out</button>
17
+ * ```
18
+ */
5
19
  export declare class SignOutDirective extends AuthActionDirective {
20
+ /**
21
+ * Emits an event after the sign-out action is completed.
22
+ *
23
+ * @type {EventEmitter<void>}
24
+ */
6
25
  afterSignOut: EventEmitter<void>;
7
26
  protected handleClick(): void;
8
27
  static ɵfac: i0.ɵɵFactoryDeclaration<SignOutDirective, never>;
@@ -1,2 +1,14 @@
1
1
  import { AuthEnvironment } from '../models';
2
+ /**
3
+ * Creates an authentication host URL based on the provided environment and URL segments.
4
+ *
5
+ * @param {AuthEnvironment} environment - The authentication environment (e.g., 'development', 'production').
6
+ * @param {string[]} segments - Additional URL segments to append to the base URL.
7
+ * @returns {string} The constructed authentication host URL.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * createAuthHostUrl('dev', 'api', 'v1', 'users'); // returns 'https://dev-auth.odx.com/api/v1/users'
12
+ * ```
13
+ */
2
14
  export declare function createAuthHostUrl(environment: AuthEnvironment, ...segments: string[]): string;
@@ -1 +1,18 @@
1
+ /**
2
+ * Creates initials from a given string.
3
+ *
4
+ * This function takes a string input, removes any text within parentheses,
5
+ * trims any leading or trailing whitespace, and then splits the string into
6
+ * parts based on spaces. It then constructs initials using the first letter
7
+ * of the first and last parts of the string, converting them to uppercase.
8
+ *
9
+ * @param {string | null} value - The input string from which to create initials. It can be
10
+ * undefined or null, in which case an empty string is returned.
11
+ * @returns {string} - A string containing the initials derived from the input string.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * createInitials('John Smith'); // returns 'JS'
16
+ * ```
17
+ */
1
18
  export declare function createInitials(value?: string | null): string;
@@ -1,3 +1,13 @@
1
1
  import { OAuthErrorEvent } from 'angular-oauth2-oidc';
2
2
  import { AuthErrorHandlerFn } from '../auth.config';
3
+ /**
4
+ * Handles authentication errors by executing a series of error handler functions.
5
+ *
6
+ * @param {AuthErrorHandlerFn[]} handlers - An array of functions that handle authentication errors.
7
+ * Each function is expected to take an `OAuthErrorEvent` as an argument.
8
+ *
9
+ * @returns A function that takes an `OAuthErrorEvent` and processes it using the provided handlers.
10
+ * The function will stop processing once a handler successfully handles the error without throwing.
11
+ * If a handler throws an error that is not an instance of `OAuthErrorEvent`, the original error is re-thrown.
12
+ */
3
13
  export declare function handleAuthError(handlers: AuthErrorHandlerFn[]): (error: OAuthErrorEvent) => void;
@@ -1,3 +1,11 @@
1
1
  import { OAuthEvent } from 'angular-oauth2-oidc';
2
2
  import { OperatorFunction } from 'rxjs';
3
+ /**
4
+ * Handles OAuth events of a specific type by applying a provided handler function.
5
+ *
6
+ * @template {T} - The type of OAuth event.
7
+ * @param {T['type']} type - The type of the OAuth event to handle.
8
+ * @param {(event: T) => Promise<void>} handler - A function that takes an event of type T and returns a Promise that resolves to void.
9
+ * @returns {OperatorFunction<T, void>} - An OperatorFunction that filters events of the specified type and applies the handler function.
10
+ */
3
11
  export declare function handleOAuthEvent<T extends OAuthEvent>(type: T['type'], handler: (event: T) => Promise<void>): OperatorFunction<T, void>;
@@ -1 +1,21 @@
1
+ /**
2
+ * Resolves the email address from the given identity claims.
3
+ *
4
+ * This function attempts to extract an email address from the provided
5
+ * `OdxAuth.RawIdentityClaims` object by checking the following properties
6
+ * in order:
7
+ * 1. `email` - if it is a string, it is returned.
8
+ * 2. `email_address` - if it is a string, it is returned.
9
+ * 3. `emails` - if it is an array and the first element is a string, the first element is returned.
10
+ *
11
+ * If none of these properties contain a valid string email address, an empty string is returned.
12
+ *
13
+ * @param {OdxAuth.RawIdentityClaims} claims - The identity claims object from which to resolve the email address.
14
+ * @returns {string} - The resolved email address as a string, or an empty string if no valid email address is found.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * resolveEmail({ email_address: 'email.address@mdn.com' }) // returns 'email.address@mdn.com';
19
+ * ```
20
+ */
1
21
  export declare function resolveEmail(claims: OdxAuth.RawIdentityClaims): string;
@@ -1 +1,22 @@
1
+ /**
2
+ * Resolves the username from the provided identity claims.
3
+ *
4
+ * The function attempts to construct a username from the claims in the following order:
5
+ * 1. If both 'firstname' and 'lastname' are strings, it returns them concatenated with a space.
6
+ * 2. If both 'given_name' and 'family_name' are strings, it returns them concatenated with a space.
7
+ * 3. If 'name' is a string, it returns the 'name'.
8
+ * 4. If 'displayname' is a string, it returns the 'displayname'.
9
+ * 5. If none of the above conditions are met, it returns an empty string.
10
+ *
11
+ * @param {OdxAuth.RawIdentityClaims} claims - The raw identity claims from which to resolve the username.
12
+ * @returns {string} - The resolved username as a string.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * resolveUsername({ firstname: 'John', lastname: 'Doe' }) // returns 'John Doe';
17
+ * resolveUsername({ given_name: 'John', family_name: 'Doe' }) // returns 'John Doe';
18
+ * resolveUsername({ name: 'John Doe' }) // returns 'John Doe';
19
+ * resolveUsername({ displayname: 'John Doe' }) // returns 'John Doe';
20
+ * ```
21
+ */
1
22
  export declare function resolveUsername(claims: OdxAuth.RawIdentityClaims): string;
@@ -1,2 +1,11 @@
1
1
  import { HttpRequest } from '@angular/common/http';
2
+ /**
3
+ * Sets the HTTP Authorization header for a given request.
4
+ *
5
+ * @template R - The type of the request, which extends HttpRequest<T> or Request.
6
+ * @template T - The type of the request body.
7
+ * @param {R} req - The HTTP request to which the Authorization header will be added.
8
+ * @param {string | null} [token] - The token to be used in the Authorization header. If no token is provided, the request is returned unchanged.
9
+ * @returns {R} - The modified HTTP request with the Authorization header set, or the original request if no token is provided.
10
+ */
2
11
  export declare function setHttpAuthHeader<R extends HttpRequest<T> | Request, T>(req: R, token?: string | null): R;
@@ -1,4 +1,11 @@
1
1
  import { LanguageLoaderFn } from '@odx/angular/localization';
2
2
  type LanguageSelector = (claims?: OdxAuth.IdentiyClaims | null) => string | null | undefined;
3
+ /**
4
+ * A function that creates a language loader function for user authentication.
5
+ *
6
+ * @param {LanguageSelector} languageSelector - A function that takes optional identity claims and returns a language string, null, or undefined.
7
+ * Defaults to a function that returns the preferred language from the claims.
8
+ * @returns {LanguageLoaderFn} - A function that retrieves the user's preferred language from the identity claims.
9
+ */
3
10
  export declare function userLanguageLoader(languageSelector?: LanguageSelector): LanguageLoaderFn;
4
11
  export {};
@@ -1,2 +1,11 @@
1
1
  import { AuthPluginFactory } from '../models';
2
+ /**
3
+ * A factory function that creates a core debug plugin for the authentication service.
4
+ * This plugin logs detailed information about the user's identity claims and tokens.
5
+ *
6
+ * @remarks
7
+ * This plugin is intended for debugging purposes only and should not be used in production environments.
8
+ *
9
+ * @returns {AuthPluginFactory} A function that takes an authentication service and sets up logging for identity claims and tokens.
10
+ */
2
11
  export declare const coreDebugPlugin: AuthPluginFactory;
@@ -8,4 +8,11 @@ declare global {
8
8
  }
9
9
  }
10
10
  }
11
+ /**
12
+ * Core identity plugin for authentication.
13
+ *
14
+ * This plugin extracts and processes identity claims from the authentication service.
15
+ *
16
+ * @returns {AuthPluginFactory} A factory function that returns an observable with the processed identity claims.
17
+ */
11
18
  export declare const coreIdentityPlugin: AuthPluginFactory;
@@ -6,4 +6,13 @@ declare global {
6
6
  }
7
7
  }
8
8
  }
9
+ /**
10
+ * A plugin factory that generates a user profile URL plugin.
11
+ *
12
+ * This plugin retrieves the user profile URL from the authentication configuration.
13
+ * If the user profile URL is not specified in the configuration, it falls back to
14
+ * using the default URL for the current environment from `ODX_AUTH_USER_PROFILE_HOSTS`.
15
+ *
16
+ * @returns A function that returns an observable emitting an object containing the user profile URL.
17
+ */
9
18
  export declare const userProfileUrlPlugin: AuthPluginFactory;
@@ -1,3 +1,11 @@
1
1
  import { CanActivateFn } from '@angular/router';
2
2
  import { AuthorizedHandler } from './models';
3
+ /**
4
+ * Guard function to prevent unauthorized access to routes.
5
+ *
6
+ * @param {AuthorizedHandler} authorizedHandler - Optional handler to check if the user is authorized.
7
+ * @param {any[] | string} redirectTo - Optional URL or route to redirect unauthorized users to. Can be a string or an array of strings.
8
+ * @param {boolean} isExternal - Optional flag to indicate if the redirection should be external. Defaults to false.
9
+ * @returns {CanActivateFn} - A function that implements the CanActivateFn interface.
10
+ */
3
11
  export declare function unauthGuard(authorizedHandler?: AuthorizedHandler, redirectTo?: any[] | string, isExternal?: boolean): CanActivateFn;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@odx/auth",
3
- "version": "14.0.0",
3
+ "version": "15.0.1",
4
4
  "author": "Drägerwerk AG & Co.KGaA",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "peerDependencies": {
7
- "@odx/angular": "^11.0.0"
7
+ "@odx/angular": "^12.0.0"
8
8
  },
9
9
  "dependencies": {
10
10
  "angular-oauth2-oidc": "^15.0.1",
@@ -1,3 +1,10 @@
1
1
  import { AuthEnvironment } from '@odx/auth';
2
2
  import { ServiceConnectEnvironment } from '../service-connect.config';
3
+ /**
4
+ * Builds a service connect URL based on the provided environment and endpoints.
5
+ *
6
+ * @param {ServiceConnectEnvironment | AuthEnvironment} environment - The environment configuration which can be either a `ServiceConnectEnvironment` or `AuthEnvironment`.
7
+ * @param {string[]} endpoints - A list of endpoint strings to be appended to the base URL.
8
+ * @returns {string} - The constructed service connect URL as a string.
9
+ */
3
10
  export declare function buildServiceConnectUrl(environment: ServiceConnectEnvironment | AuthEnvironment, ...endpoints: string[]): string;
@@ -1,3 +1,10 @@
1
1
  import { AuthorizedHandler } from '@odx/auth';
2
2
  import { RolesOrRights } from './has-roles-or-rights';
3
+ /**
4
+ * Creates an authorized handler that checks if the user has the specified roles or rights.
5
+ *
6
+ * @param {RolesOrRights} rolesOrRights - The roles or rights to check against the user's claims.
7
+ * @returns {AuthorizedHandler} - An handler function that takes user claims and returns a boolean indicating
8
+ * whether the user has the required roles or rights.
9
+ */
3
10
  export declare function hasRolesOrRightsHandler(rolesOrRights: RolesOrRights): AuthorizedHandler;
@@ -1,4 +1,11 @@
1
1
  export type Right = string | number;
2
2
  export type Role = Right[];
3
3
  export type RolesOrRights = Array<Role | Right>;
4
+ /**
5
+ * Checks if the user has any of the specified roles or rights.
6
+ *
7
+ * @param {Right[]} userRights - An array of rights that the user possesses.
8
+ * @param {RolesOrRights} rolesOrRights - An array of roles or rights to check against. A role is represented as an array of rights.
9
+ * @returns {boolean} - `true` if the user has any of the specified roles or rights, otherwise `false`.
10
+ */
4
11
  export declare function hasRolesOrRights(userRights: Right[], rolesOrRights: RolesOrRights): boolean;
@@ -10,4 +10,10 @@ export interface ServiceConnectPluginFactoryOptions<Dto> {
10
10
  setup?: (pluginOptions?: ServiceConnectPluginOptions) => void;
11
11
  }
12
12
  export type ServiceConnectPluginFactory = (pluginOptions?: ServiceConnectPluginOptions) => AuthPluginFactory;
13
+ /**
14
+ * Creates a plugin factory for fetching and parsing service connect data.
15
+ *
16
+ * @param {ServiceConnectPluginFactoryOptions<Dto>} options - The options for the service connect plugin factory.
17
+ * @returns {ServiceConnectPluginFactory} - A function that creates an auth plugin factory for fetching and parsing service connect data.
18
+ */
13
19
  export declare function serviceConnectPluginFactory<Dto = unknown>(options: ServiceConnectPluginFactoryOptions<Dto>): ServiceConnectPluginFactory;
@@ -1,8 +1,20 @@
1
1
  import { RolesOrRights } from './helpers';
2
2
  import * as i0 from "@angular/core";
3
3
  import * as i1 from "@odx/auth";
4
+ /**
5
+ * A directive that extends the functionality of the `AuthDirective` to handle
6
+ * roles or rights for service connection authorization.
7
+ *
8
+ * @see AuthDirective
9
+ *
10
+ * This directive should be used on an `ng-template` element with the selector
11
+ * `odxAuthServiceConnectRights`.
12
+ */
4
13
  export declare class ServiceConnectRightsDirective {
5
14
  private readonly authDirective;
15
+ /**
16
+ * Sets the roles or rights that the user must have to display the content.
17
+ */
6
18
  set rolesOrRights(value: RolesOrRights | null | undefined);
7
19
  static ɵfac: i0.ɵɵFactoryDeclaration<ServiceConnectRightsDirective, never>;
8
20
  static ɵdir: i0.ɵɵDirectiveDeclaration<ServiceConnectRightsDirective, "ng-template[odxAuthServiceConnectRights]", never, { "rolesOrRights": { "alias": "odxAuthServiceConnectRights"; "required": false; }; }, {}, never, never, true, [{ directive: typeof i1.AuthDirective; inputs: { "odxAuthElse": "odxAuthServiceConnectRightsElse"; }; outputs: {}; }]>;
@@ -1,3 +1,11 @@
1
1
  import { CanActivateFn } from '@angular/router';
2
2
  import { RolesOrRights } from './helpers';
3
+ /**
4
+ * A guard function to check if the user has the required roles or rights to access a route.
5
+ *
6
+ * @param {RolesOrRights} rolesOrRights - The roles or rights required to access the route.
7
+ * @param {string | any[]} redirectTo - (Optional) The route to redirect to if the user does not have the required roles or rights.
8
+ * @param {boolean} isExternal - (Optional) A flag indicating if the redirection is to an external URL. Defaults to `false`.
9
+ * @returns {CanActivateFn} - A function that checks the user's roles or rights and handles redirection if necessary.
10
+ */
3
11
  export declare function serviceConnectRightsGuard(rolesOrRights: RolesOrRights, redirectTo?: string | any[], isExternal?: boolean): CanActivateFn;
@@ -6,4 +6,12 @@ declare global {
6
6
  }
7
7
  }
8
8
  }
9
+ /**
10
+ * A plugin for fetching and parsing service connect rights.
11
+ *
12
+ * This plugin uses the `serviceConnectPluginFactory` to create a plugin that fetches user rights
13
+ * from the specified endpoint and parses the response to extract the rights.
14
+ *
15
+ * @see {serviceConnectPluginFactory}
16
+ */
9
17
  export declare const serviceConnectRightsPlugin: import("./helpers").ServiceConnectPluginFactory;
@@ -1,3 +1,17 @@
1
1
  import { GetServiceConnectUserResponseDto } from './dtos';
2
+ /**
3
+ * Gets the language code from a service connect user response.
4
+ *
5
+ * @param {GetServiceConnectUserResponseDto | null} res - The service connect user response.
6
+ * @returns {string | undefined} - The language code or undefined.
7
+ */
2
8
  export declare function getServiceConnectUserLanguage(res?: GetServiceConnectUserResponseDto | null): string | undefined;
9
+ /**
10
+ * A plugin for fetching and parsing the user's preferred language from service connect.
11
+ *
12
+ * This plugin uses the `serviceConnectPluginFactory` to create a plugin that fetches the user's preferred language
13
+ * from the user endpoint and parses the response to extract the preferred language.
14
+ *
15
+ * @see {serviceConnectPluginFactory}
16
+ */
3
17
  export declare const serviceConnectUserLanguagePlugin: import("./helpers").ServiceConnectPluginFactory;
@@ -8,4 +8,12 @@ declare global {
8
8
  }
9
9
  }
10
10
  }
11
+ /**
12
+ * A plugin for fetching and parsing the user's profile from service connect.
13
+ *
14
+ * This plugin uses the `serviceConnectPluginFactory` to create a plugin that fetches the user's profile
15
+ * from the user endpoint and parses the response to extract the user's profile information.
16
+ *
17
+ * @see {serviceConnectPluginFactory}
18
+ */
11
19
  export declare const serviceConnectUserProfilePlugin: import("./helpers").ServiceConnectPluginFactory;