@odx/auth 17.2.0 → 18.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/fesm2022/odx-auth-plugins-service-connect.mjs +3 -3
  3. package/fesm2022/odx-auth-plugins-service-connect.mjs.map +1 -1
  4. package/fesm2022/odx-auth.mjs +41 -41
  5. package/fesm2022/odx-auth.mjs.map +1 -1
  6. package/index.d.ts +744 -15
  7. package/package.json +4 -8
  8. package/plugins/service-connect/index.d.ts +184 -8
  9. package/esm2022/index.mjs +0 -16
  10. package/esm2022/lib/auth.component.mjs +0 -50
  11. package/esm2022/lib/auth.config.mjs +0 -71
  12. package/esm2022/lib/auth.directive.mjs +0 -51
  13. package/esm2022/lib/auth.guard.mjs +0 -44
  14. package/esm2022/lib/auth.i18n.mjs +0 -13
  15. package/esm2022/lib/auth.interceptor.mjs +0 -23
  16. package/esm2022/lib/auth.logger.mjs +0 -3
  17. package/esm2022/lib/auth.module.mjs +0 -19
  18. package/esm2022/lib/auth.providers.mjs +0 -136
  19. package/esm2022/lib/auth.service.mjs +0 -317
  20. package/esm2022/lib/auth.typings.mjs +0 -2
  21. package/esm2022/lib/components/auth-actions/auth-actions.component.mjs +0 -40
  22. package/esm2022/lib/components/auth-loading-screen/auth-loading-screen.component.mjs +0 -53
  23. package/esm2022/lib/components/index.mjs +0 -3
  24. package/esm2022/lib/directives/auth-action.directive.mjs +0 -30
  25. package/esm2022/lib/directives/index.mjs +0 -4
  26. package/esm2022/lib/directives/sign-in.directive.mjs +0 -52
  27. package/esm2022/lib/directives/sign-out.directive.mjs +0 -50
  28. package/esm2022/lib/helpers/create-auth-host-url.mjs +0 -18
  29. package/esm2022/lib/helpers/create-inititals.mjs +0 -32
  30. package/esm2022/lib/helpers/handle-auth-error.mjs +0 -31
  31. package/esm2022/lib/helpers/handle-oauth-event.mjs +0 -13
  32. package/esm2022/lib/helpers/index.mjs +0 -9
  33. package/esm2022/lib/helpers/resolve-email.mjs +0 -34
  34. package/esm2022/lib/helpers/resolve-username.mjs +0 -38
  35. package/esm2022/lib/helpers/set-http-auth-header.mjs +0 -22
  36. package/esm2022/lib/helpers/user-language-loader.mjs +0 -17
  37. package/esm2022/lib/models/auth-environment.mjs +0 -3
  38. package/esm2022/lib/models/auth-plugin-manager.mjs +0 -49
  39. package/esm2022/lib/models/authorized-handler.mjs +0 -2
  40. package/esm2022/lib/models/index.mjs +0 -5
  41. package/esm2022/lib/models/offline-auth-error-handler.mjs +0 -7
  42. package/esm2022/lib/plugins/core-debug.plugin.mjs +0 -29
  43. package/esm2022/lib/plugins/core-identity.plugin.mjs +0 -20
  44. package/esm2022/lib/plugins/index.mjs +0 -4
  45. package/esm2022/lib/plugins/user-profile-link.plugin.mjs +0 -18
  46. package/esm2022/lib/unauth.guard.mjs +0 -38
  47. package/esm2022/odx-auth.mjs +0 -5
  48. package/esm2022/plugins/service-connect/index.mjs +0 -9
  49. package/esm2022/plugins/service-connect/lib/dtos/get-service-connect-rights-response.dto.mjs +0 -2
  50. package/esm2022/plugins/service-connect/lib/dtos/get-service-connect-user-response.dto.mjs +0 -2
  51. package/esm2022/plugins/service-connect/lib/dtos/index.mjs +0 -3
  52. package/esm2022/plugins/service-connect/lib/helpers/build-service-connect-url.mjs +0 -16
  53. package/esm2022/plugins/service-connect/lib/helpers/has-roles-or-rights-handler.mjs +0 -12
  54. package/esm2022/plugins/service-connect/lib/helpers/has-roles-or-rights.mjs +0 -11
  55. package/esm2022/plugins/service-connect/lib/helpers/index.mjs +0 -5
  56. package/esm2022/plugins/service-connect/lib/helpers/service-connect-plugin-factory.mjs +0 -25
  57. package/esm2022/plugins/service-connect/lib/service-connect-rights.directive.mjs +0 -44
  58. package/esm2022/plugins/service-connect/lib/service-connect-rights.guard.mjs +0 -15
  59. package/esm2022/plugins/service-connect/lib/service-connect-rights.plugin.mjs +0 -16
  60. package/esm2022/plugins/service-connect/lib/service-connect-user-language.plugin.mjs +0 -34
  61. package/esm2022/plugins/service-connect/lib/service-connect-user-profile.plugin.mjs +0 -28
  62. package/esm2022/plugins/service-connect/lib/service-connect.config.mjs +0 -17
  63. package/esm2022/plugins/service-connect/odx-auth-plugins-service-connect.mjs +0 -5
  64. package/lib/auth.component.d.ts +0 -20
  65. package/lib/auth.config.d.ts +0 -84
  66. package/lib/auth.directive.d.ts +0 -25
  67. package/lib/auth.guard.d.ts +0 -11
  68. package/lib/auth.i18n.d.ts +0 -3
  69. package/lib/auth.interceptor.d.ts +0 -10
  70. package/lib/auth.logger.d.ts +0 -3
  71. package/lib/auth.module.d.ts +0 -10
  72. package/lib/auth.providers.d.ts +0 -46
  73. package/lib/auth.service.d.ts +0 -206
  74. package/lib/auth.typings.d.ts +0 -27
  75. package/lib/components/auth-actions/auth-actions.component.d.ts +0 -16
  76. package/lib/components/auth-loading-screen/auth-loading-screen.component.d.ts +0 -24
  77. package/lib/components/index.d.ts +0 -2
  78. package/lib/directives/auth-action.directive.d.ts +0 -18
  79. package/lib/directives/index.d.ts +0 -3
  80. package/lib/directives/sign-in.directive.d.ts +0 -29
  81. package/lib/directives/sign-out.directive.d.ts +0 -28
  82. package/lib/helpers/create-auth-host-url.d.ts +0 -14
  83. package/lib/helpers/create-inititals.d.ts +0 -18
  84. package/lib/helpers/handle-auth-error.d.ts +0 -13
  85. package/lib/helpers/handle-oauth-event.d.ts +0 -11
  86. package/lib/helpers/index.d.ts +0 -8
  87. package/lib/helpers/resolve-email.d.ts +0 -21
  88. package/lib/helpers/resolve-username.d.ts +0 -22
  89. package/lib/helpers/set-http-auth-header.d.ts +0 -11
  90. package/lib/helpers/user-language-loader.d.ts +0 -11
  91. package/lib/models/auth-environment.d.ts +0 -6
  92. package/lib/models/auth-plugin-manager.d.ts +0 -21
  93. package/lib/models/authorized-handler.d.ts +0 -3
  94. package/lib/models/index.d.ts +0 -4
  95. package/lib/models/offline-auth-error-handler.d.ts +0 -2
  96. package/lib/plugins/core-debug.plugin.d.ts +0 -11
  97. package/lib/plugins/core-identity.plugin.d.ts +0 -18
  98. package/lib/plugins/index.d.ts +0 -3
  99. package/lib/plugins/user-profile-link.plugin.d.ts +0 -18
  100. package/lib/unauth.guard.d.ts +0 -11
  101. package/plugins/service-connect/lib/dtos/get-service-connect-rights-response.dto.d.ts +0 -3
  102. package/plugins/service-connect/lib/dtos/get-service-connect-user-response.dto.d.ts +0 -14
  103. package/plugins/service-connect/lib/dtos/index.d.ts +0 -2
  104. package/plugins/service-connect/lib/helpers/build-service-connect-url.d.ts +0 -10
  105. package/plugins/service-connect/lib/helpers/has-roles-or-rights-handler.d.ts +0 -10
  106. package/plugins/service-connect/lib/helpers/has-roles-or-rights.d.ts +0 -11
  107. package/plugins/service-connect/lib/helpers/index.d.ts +0 -4
  108. package/plugins/service-connect/lib/helpers/service-connect-plugin-factory.d.ts +0 -20
  109. package/plugins/service-connect/lib/service-connect-rights.directive.d.ts +0 -21
  110. package/plugins/service-connect/lib/service-connect-rights.guard.d.ts +0 -11
  111. package/plugins/service-connect/lib/service-connect-rights.plugin.d.ts +0 -18
  112. package/plugins/service-connect/lib/service-connect-user-language.plugin.d.ts +0 -24
  113. package/plugins/service-connect/lib/service-connect-user-profile.plugin.d.ts +0 -23
  114. package/plugins/service-connect/lib/service-connect.config.d.ts +0 -15
package/index.d.ts CHANGED
@@ -1,15 +1,744 @@
1
- export * from './lib/auth.component';
2
- export * from './lib/auth.config';
3
- export * from './lib/auth.directive';
4
- export * from './lib/auth.guard';
5
- export * from './lib/auth.interceptor';
6
- export * from './lib/auth.module';
7
- export * from './lib/auth.providers';
8
- export * from './lib/auth.service';
9
- export * from './lib/auth.typings';
10
- export * from './lib/components';
11
- export * from './lib/directives';
12
- export * from './lib/helpers';
13
- export * from './lib/models';
14
- export * from './lib/plugins';
15
- export * from './lib/unauth.guard';
1
+ import * as i0 from '@angular/core';
2
+ import { AfterViewInit, TemplateRef, EventEmitter, InjectionToken, Provider, EnvironmentProviders } from '@angular/core';
3
+ import * as rxjs from 'rxjs';
4
+ import { Observable, OperatorFunction } from 'rxjs';
5
+ import * as _odx_auth from '@odx/auth';
6
+ import { DropdownOptions } from '@odx/angular/components/dropdown';
7
+ import * as angular_oauth2_oidc from 'angular-oauth2-oidc';
8
+ import { OAuthErrorEvent, OAuthStorage, AuthConfig as AuthConfig$1, TokenResponse, OAuthEvent } from 'angular-oauth2-oidc';
9
+ import { HttpRequest, HttpContextToken, HttpInterceptorFn } from '@angular/common/http';
10
+ import { Router, CanActivateFn } from '@angular/router';
11
+ import * as _odx_angular_utils from '@odx/angular/utils';
12
+ import { ConfigDependencies, ConfigProvider } from '@odx/angular/utils';
13
+ import { DynamicTextContent, DynamicViewService } from '@odx/angular/cdk/dynamic-view';
14
+ import * as i1 from '@angular/common';
15
+ import { NgIfContext } from '@angular/common';
16
+ import * as i1$1 from '@odx/angular/components/loading-spinner';
17
+ import { LanguageLoaderFn } from '@odx/angular/localization';
18
+
19
+ type AuthEnvironment = (typeof AuthEnvironment)[keyof typeof AuthEnvironment];
20
+ declare const AuthEnvironment: {
21
+ readonly DEV: "dev";
22
+ readonly STAGE: "stage";
23
+ readonly PROD: "prod";
24
+ };
25
+
26
+ type AuthPlugin = (authService: AuthService) => Observable<Partial<OdxAuth.AuthPluginResult>>;
27
+ type AuthPluginFactory = () => AuthPlugin;
28
+ type AuthPluginError = unknown;
29
+ type AuthPluginErrorHandler = (error: AuthPluginError) => void;
30
+ declare class AuthPluginManager {
31
+ private readonly authConfig;
32
+ private readonly pluginsErrorHandler;
33
+ private readonly plugins;
34
+ private readonly result$$;
35
+ readonly pluginsReady$: Observable<boolean>;
36
+ readonly pluginsLoading$: Observable<boolean>;
37
+ runPlugins(authService: AuthService): Observable<OdxAuth.AuthPluginResult>;
38
+ getResult(): OdxAuth.AuthPluginResult;
39
+ private handlePluginError;
40
+ private runPlugin;
41
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthPluginManager, never>;
42
+ static ɵprov: i0.ɵɵInjectableDeclaration<AuthPluginManager>;
43
+ }
44
+
45
+ type AuthorizedHandler = (identityClaims: OdxAuth.IdentityClaims | null, authService: AuthService, router?: Router | null) => boolean;
46
+
47
+ declare const AUTH_HTTP_HEADER = "Authorization";
48
+ declare const ODX_AUTH_DEFAULT_SCOPES: string[];
49
+ declare const ODX_AUTH_HOSTS: Record<AuthEnvironment, string>;
50
+ declare const ODX_AUTH_USER_PROFILE_HOSTS: Record<AuthEnvironment, string>;
51
+ type AuthErrorHandlerFn = (error: OAuthErrorEvent) => void;
52
+ type ResolveUsernameFn = (rawClaims: OdxAuth.RawIdentityClaims) => string;
53
+ type ResolveEmailFn = (rawClaims: OdxAuth.RawIdentityClaims) => string;
54
+ type CreateInitialsFn = (value: string) => string;
55
+ /**
56
+ * Tools for injecting and providing the auth configuration with default configuration for the authentication.
57
+ *
58
+ * @example
59
+ * // Providing custom authentication configuration.
60
+ * ```ts
61
+ * import { createInitials, resolveEmail, resolveUsername } from './helpers';
62
+ *
63
+ * providers: [provideAuthConfig({
64
+ * environment: 'dev',
65
+ * redirectPath: 'login/callback',
66
+ * allowedUrls: [],
67
+ * timeoutFactor: 0.75,
68
+ * maxOfflineTime: 60 * 60, // 1 hour
69
+ * loadUserProfile: false,
70
+ * errorHandler: (error) => {
71
+ * throw error;
72
+ * },
73
+ * createInitials,
74
+ * resolveEmail,
75
+ * resolveUsername,
76
+ * plugins: [],
77
+ * defaultAuthorizedHandler: null,
78
+ * enableLoadingScreen: true,
79
+ * loadingScreenMessage: 'Loading...',
80
+ * waitForTokenInMs: 500,
81
+ *
82
+ * })],
83
+ *
84
+ * // Injecting the datepicker configuration.
85
+ * ```ts
86
+ * @Component({})
87
+ * export class MyComponent {
88
+ * constructor(@Inject(injectAuthConfig()) private readonly authConfig: AuthConfig) {}
89
+ * }
90
+ * ```
91
+ */
92
+ declare const AuthDefaultConfig: AuthConfig;
93
+ /**
94
+ * Configuration options for the authentication module.
95
+ *
96
+ * @interface AuthConfig
97
+ */
98
+ interface AuthConfig {
99
+ environment: AuthEnvironment;
100
+ clientId?: string;
101
+ issuer?: string;
102
+ redirectPath: string;
103
+ allowedUrls: Array<string | RegExp>;
104
+ timeoutFactor: number;
105
+ maxOfflineTime: number;
106
+ loadUserProfile: boolean;
107
+ postLogoutRedirectUrl?: string;
108
+ scopes?: string[];
109
+ discoveryUrl?: string;
110
+ errorHandler: AuthErrorHandlerFn;
111
+ createInitials: CreateInitialsFn;
112
+ resolveEmail: ResolveEmailFn;
113
+ resolveUsername: ResolveUsernameFn;
114
+ storage?: OAuthStorage;
115
+ plugins: AuthPluginFactory[];
116
+ pluginsErrorHandler?: (error: unknown) => void;
117
+ defaultAuthorizedHandler?: AuthorizedHandler | null;
118
+ enableLoadingScreen: boolean;
119
+ refreshTokenOnInit?: boolean;
120
+ loadingScreenMessage?: DynamicTextContent | null;
121
+ userProfileUrl?: string;
122
+ requireSignIn?: boolean;
123
+ requireSignInForRequests?: boolean;
124
+ waitForTokenInMs?: number;
125
+ showDebugInformation?: boolean;
126
+ pluginTimeout?: number;
127
+ }
128
+ declare const AuthConfig: i0.InjectionToken<Partial<AuthConfig>>;
129
+ declare const injectAuthConfig: () => AuthConfig;
130
+ declare const provideAuthConfig: <D extends _odx_angular_utils.ConfigDependencies = _odx_angular_utils.ConfigDependencies<Partial<AuthConfig>>>(config: _odx_angular_utils.ConfigProvider<Partial<AuthConfig>, D>) => i0.FactoryProvider | i0.ValueProvider;
131
+
132
+ declare const offlineAuthErrorHandler: AuthErrorHandlerFn;
133
+
134
+ /**
135
+ * The `AuthService` class provides authentication functionality for an Angular application.
136
+ * It handles OAuth2/OIDC authentication, token management, and user identity claims.
137
+ *
138
+ * Key responsibilities include:
139
+ * - Initializing authentication with a provided configuration.
140
+ * - Managing tokens (access, refresh, and ID tokens).
141
+ * - Checking and emitting authentication and authorization states.
142
+ * - Handling user login and logout flows.
143
+ * - Supporting silent refresh and offline authentication scenarios.
144
+ * - Integrating authentication plugins via `AuthPluginManager`.
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Injecting the AuthService
149
+ * constructor(private authService: AuthService) {}
150
+ *
151
+ * // Using the AuthService to initialize authentication
152
+ * async ngOnInit() {
153
+ * const config: AuthConfig = { clientId: 'your-client-id', discoveryUrl: 'https://example.com/.well-known/openid-configuration' };
154
+ * await this.authService.initialize(config);
155
+ * }
156
+ * ```
157
+ */
158
+ declare class AuthService {
159
+ private readonly authConfig;
160
+ private readonly authPluginManager;
161
+ private readonly oauthService;
162
+ private readonly router;
163
+ private readonly windowRef;
164
+ private readonly isInitialized$$;
165
+ private readonly isRedirecting$$;
166
+ private readonly onAccessTokenUpdate$;
167
+ private readonly silentRefreshHandler$;
168
+ private readonly onAuthStateChange$;
169
+ /**
170
+ * Emits `true` when the service has completed initialization.
171
+ * Emits `false` until the initialization is complete.
172
+ *
173
+ * @type {Observable<boolean>}
174
+ */
175
+ readonly isInitialized$: Observable<true>;
176
+ /**
177
+ * Emits `true` when the user is being redirected to the login page.
178
+ * Emits `false` when there is no redirection in progress.
179
+ *
180
+ * @type {Observable<boolean>}
181
+ */
182
+ readonly isRedirecting$: Observable<boolean>;
183
+ /**
184
+ * Emits `true` when the application is in a loading state (e.g., during redirection or plugin initialization).
185
+ * Emits `false` when there is no ongoing loading activity.
186
+ *
187
+ * @type {Observable<boolean>}
188
+ */
189
+ readonly isLoading$: Observable<boolean>;
190
+ /**
191
+ * Emits `true` when the user is authenticated.
192
+ * Emits `false` when the user is not authenticated.
193
+ *
194
+ * @type {Observable<boolean>}
195
+ */
196
+ readonly isAuthenticated$: Observable<boolean>;
197
+ /**
198
+ * Emits the identity claims of the authenticated user.
199
+ * If the user is not authenticated, emits `null`.
200
+ *
201
+ * @type {Observable<OdxAuth.IdentityClaims | null>}
202
+ */
203
+ readonly identityClaims$: Observable<OdxAuth.IdentityClaims | null>;
204
+ /**
205
+ * Emits OAuth error events.
206
+ *
207
+ * @type {Observable<OAuthErrorEvent>}
208
+ */
209
+ readonly errors$: Observable<OAuthErrorEvent>;
210
+ /**
211
+ * Emits events when an OAuth token is successfully received.
212
+ *
213
+ * @type {Observable<Event>}
214
+ */
215
+ readonly onTokenReceived$: Observable<angular_oauth2_oidc.OAuthEvent>;
216
+ /**
217
+ * Emits whenever the `access_token` in local storage is updated or cleared.
218
+ * Provides an observable for tracking token updates.
219
+ *
220
+ * @type {Observable<StorageEvent | null>}
221
+ */
222
+ get accessTokenUpdate$(): Observable<StorageEvent | null>;
223
+ constructor();
224
+ /**
225
+ * Initializes the authentication service with the provided configuration.
226
+ *
227
+ * @param {AuthConfig} config - The authentication configuration object.
228
+ * @returns {Promise<void>} Resolves when initialization is complete.
229
+ */
230
+ initialize(config: AuthConfig$1): Promise<void>;
231
+ /**
232
+ * Runs all authentication plugins registered in the `AuthPluginManager`.
233
+ */
234
+ runPlugins(): void;
235
+ /**
236
+ * Returns the issuer URL for the OAuth server.
237
+ *
238
+ * @returns {URL} The issuer URL.
239
+ */
240
+ getIssuer(): URL;
241
+ /**
242
+ * Initiates the login flow for the user. Redirects to the login page.
243
+ *
244
+ * @param {string} [url] - The URL to redirect back to after login.
245
+ */
246
+ signIn(url?: string): void;
247
+ /**
248
+ * Logs the user out and clears their tokens.
249
+ *
250
+ * @param {boolean} [noRedirect] - If `true`, no redirection occurs after logout.
251
+ */
252
+ signOut(noRedirect?: boolean): void;
253
+ /**
254
+ * Attempts to refresh the user's tokens.
255
+ *
256
+ * @returns {Promise<TokenResponse>} Resolves with the new token response.
257
+ */
258
+ refreshTokens(): Promise<TokenResponse>;
259
+ /**
260
+ * Retrieves the current access token, if available.
261
+ *
262
+ * @returns {string | null} The access token, or `null` if not available.
263
+ */
264
+ getAccessToken(): string | null;
265
+ /**
266
+ * Retrieves the current refresh token, if available.
267
+ *
268
+ * @returns {string | null} The refresh token, or `null` if not available.
269
+ */
270
+ getRefreshToken(): string | null;
271
+ /**
272
+ * Retrieves the current ID token, if available.
273
+ *
274
+ * @returns {string | null} The ID token, or `null` if not available.
275
+ */
276
+ getIdToken(): string | null;
277
+ /**
278
+ * Retrieves the identity claims of the authenticated user.
279
+ *
280
+ * @returns {OdxAuth.IdentityClaims | null} The identity claims, or `null` if not available.
281
+ */
282
+ getIdentityClaims(): OdxAuth.IdentityClaims | null;
283
+ /**
284
+ * Retrieves the raw identity claims of the authenticated user.
285
+ *
286
+ * @returns {OdxAuth.RawIdentityClaims | null} The raw identity claims, or `null` if not available.
287
+ */
288
+ getRawIdentityClaims(): OdxAuth.RawIdentityClaims | null;
289
+ /**
290
+ * Checks if the user is currently authenticated.
291
+ *
292
+ * @returns {boolean} `true` if authenticated, otherwise `false`.
293
+ */
294
+ isAuthenticated(): boolean;
295
+ /**
296
+ * Checks if the user is authorized based on the provided handler.
297
+ *
298
+ * @param {AuthorizedHandler | null} [authorizedHandler] - A handler to determine authorization.
299
+ * @returns {boolean} `true` if authorized, otherwise `false`.
300
+ */
301
+ isAuthorized(authorizedHandler?: AuthorizedHandler | null): boolean;
302
+ /**
303
+ * Emits whether the user is authorized based on the provided handler.
304
+ *
305
+ * @param {AuthorizedHandler | null} [authorizedHandler] - A handler to determine authorization.
306
+ * @returns {Observable<boolean>} An observable emitting the authorization status.
307
+ */
308
+ isAuthorized$(authorizedHandler?: AuthorizedHandler | null): Observable<boolean>;
309
+ /**
310
+ * Prepares an HTTP request by adding the access token to its headers.
311
+ *
312
+ * @param {HttpRequest<T> | Request} req - The HTTP request to prepare.
313
+ * @param {boolean} requireSignIn - Whether to require the user to sign in if no token is available.
314
+ * @returns {Observable<R>} An observable emitting the prepared request.
315
+ * @template R, T
316
+ */
317
+ prepareAuthRequest$<R extends HttpRequest<T> | Request, T>(req: R, requireSignIn?: boolean): Observable<R>;
318
+ /**
319
+ * Waits for a valid access token to become available.
320
+ *
321
+ * @param {boolean} requireSignIn - Whether to require the user to sign in if no token is available.
322
+ * @returns {Observable<string | null>} An observable emitting the access token.
323
+ */
324
+ waitForAccessToken$(requireSignIn: boolean): Observable<string | null>;
325
+ private routeToRequestedUrl;
326
+ private hasValidOfflineToken;
327
+ private redirectToLogin;
328
+ private tryLoadUserProfile;
329
+ private tryRefreshToken;
330
+ private assertAudience;
331
+ private updateSilentRefresh;
332
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, never>;
333
+ static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
334
+ }
335
+
336
+ declare class AuthComponent {
337
+ protected readonly authConfig: _odx_auth.AuthConfig;
338
+ protected readonly authService: AuthService;
339
+ protected readonly dropdownOptions: Partial<DropdownOptions>;
340
+ protected readonly vm$: rxjs.Observable<{
341
+ idClaims: OdxAuth.IdentityClaims | null;
342
+ isAuthenticated: boolean;
343
+ }>;
344
+ /**
345
+ * Whether to hide the institution information.
346
+ *
347
+ * @type {InputSignal<boolean>}
348
+ */
349
+ readonly hideInstitution: i0.InputSignal<boolean>;
350
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthComponent, never>;
351
+ static ɵcmp: i0.ɵɵComponentDeclaration<AuthComponent, "odx-auth", never, { "hideInstitution": { "alias": "hideInstitution"; "required": false; "isSignal": true; }; }, {}, never, ["*"], true, never>;
352
+ }
353
+
354
+ declare class AuthDirective implements AfterViewInit {
355
+ private readonly authService;
356
+ private readonly ngIfDirective;
357
+ private readonly takeUntilDestroyed;
358
+ /**
359
+ * The authorization handler or a string representing the handler.
360
+ *
361
+ * @type {AuthorizedHandler | null | string}
362
+ */
363
+ authorizationHandler?: AuthorizedHandler | null | string;
364
+ /**
365
+ * Sets the template to be displayed when the authorization check fails.
366
+ *
367
+ * @param {TemplateRef<NgIfContext<unknown>>} value - The template reference.
368
+ */
369
+ set elseTemplate(value: TemplateRef<NgIfContext<unknown>>);
370
+ ngAfterViewInit(): void;
371
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthDirective, never>;
372
+ static ɵdir: i0.ɵɵDirectiveDeclaration<AuthDirective, "ng-template[odxAuth]", never, { "authorizationHandler": { "alias": "odxAuth"; "required": false; }; "elseTemplate": { "alias": "odxAuthElse"; "required": false; }; }, {}, never, never, true, [{ directive: typeof i1.NgIf; inputs: {}; outputs: {}; }]>;
373
+ }
374
+
375
+ /**
376
+ * Guard function to protect routes from unauthorized access.
377
+ *
378
+ * @param {AuthorizedHandler} [authorizedHandler] - Optional handler to check if the user is authorized.
379
+ * @param {string | any[]} [redirectTo] - Optional URL or route to redirect unauthorized users to. Can be a string or an array of strings.
380
+ * @param {boolean} [isExternal=false] - Optional flag to indicate if the redirection should be external. Defaults to false.
381
+ * @returns {CanActivateFn} A function that implements the CanActivateFn interface.
382
+ */
383
+ declare function authGuard(authorizedHandler?: AuthorizedHandler, redirectTo?: any[] | string, isExternal?: boolean): CanActivateFn;
384
+
385
+ declare const requireAuthentication: HttpContextToken<boolean>;
386
+ /**
387
+ * Interceptor to handle authentication for HTTP requests.
388
+ *
389
+ * This interceptor checks if the request URL is allowed or if the request requires authentication.
390
+ * If the URL is not allowed and the request does not require authentication, it simply forwards the request.
391
+ * Otherwise, it prepares the authentication request using the AuthService.
392
+ */
393
+ declare const authInterceptor: HttpInterceptorFn;
394
+
395
+ /**
396
+ * An abstract directive that integrates with the `LoadingSpinnerDirective` and `AuthService` to manage loading states based on authentication redirection.
397
+ *
398
+ * This directive automatically sets the `autoColor` property of the `LoadingSpinnerDirective` to `true` and subscribes to the `isRedirecting$` observable from the `AuthService`.
399
+ * When `isRedirecting$` emits a value, it updates the `isLoading` property of the `LoadingSpinnerDirective`.
400
+ */
401
+ declare abstract class AuthActionDirective implements AfterViewInit {
402
+ private readonly takeUntilDestroyed;
403
+ private readonly loadingSpinnerDirective;
404
+ protected readonly authService: AuthService;
405
+ ngAfterViewInit(): void;
406
+ protected abstract handleClick(): void;
407
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthActionDirective, never>;
408
+ static ɵdir: i0.ɵɵDirectiveDeclaration<AuthActionDirective, never, never, {}, {}, never, never, true, never>;
409
+ }
410
+
411
+ /**
412
+ * A directive that handles the sign-in action for a button element.
413
+ *
414
+ * This directive extends the `AuthActionDirective` and uses the `LoadingSpinnerDirective`
415
+ * to show a loading spinner during the sign-in process.
416
+ *
417
+ * @see {AuthActionDirective}
418
+ * @see {LoadingSpinnerDirective}
419
+ *
420
+ * @example
421
+ * ```html
422
+ * <button odxButton odxAuthSignIn (odxAuthSignIn)="onSignIn()">Sign In</button>
423
+ * ```
424
+ */
425
+
426
+ declare class SignInDirective extends AuthActionDirective {
427
+ /**
428
+ * Emits an event after the sign-in action is completed.
429
+ *
430
+ * @type {EventEmitter<void>}
431
+ */
432
+ afterSignIn: EventEmitter<void>;
433
+ protected handleClick(): void;
434
+ static ɵfac: i0.ɵɵFactoryDeclaration<SignInDirective, never>;
435
+ static ɵdir: i0.ɵɵDirectiveDeclaration<SignInDirective, "[odxButton][odxAuthSignIn]", never, {}, { "afterSignIn": "odxAuthSignIn"; }, never, never, true, [{ directive: typeof i1$1.LoadingSpinnerDirective; inputs: {}; outputs: {}; }]>;
436
+ }
437
+
438
+ /**
439
+ * A directive that handles the sign-out action for a button element.
440
+ *
441
+ * This directive extends the `AuthActionDirective` and uses the `LoadingSpinnerDirective`
442
+ * to show a loading spinner during the sign-out process.
443
+ *
444
+ * @see {AuthActionDirective}
445
+ * @see {LoadingSpinnerDirective}
446
+ *
447
+ * @example
448
+ * ```html
449
+ * <button odxButton odxAuthSignOut (odxAuthSignOut)="onSignOut()">Sign Out</button>
450
+ * ```
451
+ */
452
+ declare class SignOutDirective extends AuthActionDirective {
453
+ /**
454
+ * Emits an event after the sign-out action is completed.
455
+ *
456
+ */
457
+ afterSignOut: EventEmitter<void>;
458
+ protected handleClick(): void;
459
+ static ɵfac: i0.ɵɵFactoryDeclaration<SignOutDirective, never>;
460
+ static ɵdir: i0.ɵɵDirectiveDeclaration<SignOutDirective, "[odxAuthSignOut]", never, {}, { "afterSignOut": "odxAuthSignOut"; }, never, never, true, [{ directive: typeof i1$1.LoadingSpinnerDirective; inputs: {}; outputs: {}; }]>;
461
+ }
462
+
463
+ declare class AuthModule {
464
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthModule, never>;
465
+ static ɵmod: i0.ɵɵNgModuleDeclaration<AuthModule, never, [typeof AuthComponent, typeof AuthDirective, typeof SignInDirective, typeof SignOutDirective], [typeof AuthComponent, typeof AuthDirective, typeof SignInDirective, typeof SignOutDirective]>;
466
+ static ɵinj: i0.ɵɵInjectorDeclaration<AuthModule>;
467
+ }
468
+
469
+ declare const ODX_AUTH_ERROR_HANDLERS: InjectionToken<AuthErrorHandlerFn[]>;
470
+ declare const ODX_AUTH_PLUGINS_ERROR_HANDLER: InjectionToken<AuthPluginErrorHandler | null>;
471
+ declare const ODX_AUTH_CORE_PLUGINS: InjectionToken<AuthPluginFactory[]>;
472
+ declare const ODX_AUTH_PLUGINS: InjectionToken<AuthPlugin[]>;
473
+ /**
474
+ * Provides a logger for the authentication module.
475
+ *
476
+ * @returns {Provider} - The provider for the logger.
477
+ */
478
+ declare function provideAuthLogger(): Provider;
479
+ /**
480
+ * Initializes the authentication error handlers.
481
+ */
482
+ declare function initializeAuthErrorHandlers(): void;
483
+ /**
484
+ * Initializes the authentication configuration.
485
+ *
486
+ * @returns {() => Promise<void>} - A function that returns a promise resolving when the configuration is initialized.
487
+ */
488
+ declare function initalizeAuthConfig(): () => Promise<void>;
489
+ /**
490
+ * Provides the authentication configuration and dependencies.
491
+ *
492
+ * @param {ConfigProvider<Partial<AuthConfig>, D>} config - The configuration provider.
493
+ * @returns {EnvironmentProviders} The environment providers for authentication.
494
+ * @template D
495
+ *
496
+ * @example Provide the authentication configuration and dependencies
497
+ * ```ts
498
+ * providers: [
499
+ * provideAuth({
500
+ * useFactory: ({ environment, auth: { clientId, loadUserProfile } }: ApplicationEnvironment) => ({
501
+ * environment,
502
+ * clientId,
503
+ * loadUserProfile,
504
+ * }),
505
+ * deps: [APPLICATION_ENVIRONMENT],
506
+ * }),
507
+ * ],
508
+ * ```
509
+ */
510
+ declare function provideAuth<D extends ConfigDependencies>(config: ConfigProvider<Partial<AuthConfig>, D>): EnvironmentProviders;
511
+
512
+ declare global {
513
+ namespace OdxAuth {
514
+ type RawIdentityClaims = Record<string, unknown>;
515
+ interface AuthPluginResult {
516
+ email?: string;
517
+ initials?: string;
518
+ institutionName?: string;
519
+ languageCode?: string;
520
+ preferredLanguage?: string;
521
+ userProfileUrl?: string;
522
+ username?: string;
523
+ }
524
+ interface IdentityClaims extends AuthPluginResult {
525
+ sub: string;
526
+ oktaid: string;
527
+ iat: number;
528
+ aud: string;
529
+ name: string;
530
+ firstname: string;
531
+ lastname: string;
532
+ displayname: string;
533
+ preferred_username: string;
534
+ email: string;
535
+ initials: string;
536
+ organization: string;
537
+ locale?: string;
538
+ zoneinfo?: string;
539
+ }
540
+ }
541
+ }
542
+
543
+ /**
544
+ * Displays authentication actions.
545
+ */
546
+ declare class AuthActionsComponent {
547
+ readonly element: i0.ElementRef<HTMLElement>;
548
+ /**
549
+ * The identity claims.
550
+ *
551
+ * @type {OdxAuth.IdentityClaims | null}
552
+ * @default null
553
+ */
554
+ claims: OdxAuth.IdentityClaims | null;
555
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthActionsComponent, never>;
556
+ static ɵcmp: i0.ɵɵComponentDeclaration<AuthActionsComponent, "odx-auth-actions", never, { "claims": { "alias": "claims"; "required": false; }; }, {}, never, never, true, never>;
557
+ }
558
+
559
+ /**
560
+ * Authentication loading screen.
561
+ *
562
+ * This component displays a loading screen with animations and dynamic content
563
+ * based on the authentication state.
564
+ */
565
+ declare class AuthLoadingScreenComponent {
566
+ private static instance;
567
+ protected readonly authConfig: _odx_auth.AuthConfig;
568
+ protected readonly icon$: rxjs.Observable<"core::link-external" | "core::user">;
569
+ /**
570
+ * Initializes the authentication loading screen.
571
+ *
572
+ * @param {AuthService} authService - The authentication service.
573
+ * @param {DynamicViewService} dynamicViewService - The dynamic view service used to create the loading screen.
574
+ * @static
575
+ */
576
+ static initialize(authService: AuthService, dynamicViewService: DynamicViewService): void;
577
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthLoadingScreenComponent, never>;
578
+ static ɵcmp: i0.ɵɵComponentDeclaration<AuthLoadingScreenComponent, "div.odx-auth-loading-screen", never, {}, {}, never, never, true, never>;
579
+ }
580
+
581
+ /**
582
+ * Creates an authentication host URL based on the provided environment and URL segments.
583
+ *
584
+ * @param {AuthEnvironment} environment - The authentication environment (e.g., 'development', 'production').
585
+ * @param {string[]} segments - Additional URL segments to append to the base URL.
586
+ * @returns {string} The constructed authentication host URL.
587
+ *
588
+ * @example
589
+ * ```ts
590
+ * createAuthHostUrl('dev', 'api', 'v1', 'users'); // returns 'https://dev-auth.odx.com/api/v1/users'
591
+ * ```
592
+ */
593
+ declare function createAuthHostUrl(environment: AuthEnvironment, ...segments: string[]): string;
594
+
595
+ /**
596
+ * Creates initials from a given string.
597
+ *
598
+ * This function takes a string input, removes any text within parentheses,
599
+ * trims any leading or trailing whitespace, and then splits the string into
600
+ * parts based on spaces. It then constructs initials using the first letter
601
+ * of the first and last parts of the string, converting them to uppercase.
602
+ *
603
+ * @param {string | null} value - The input string from which to create initials. It can be
604
+ * undefined or null, in which case an empty string is returned.
605
+ * @returns {string} - A string containing the initials derived from the input string.
606
+ *
607
+ * @example
608
+ * ```ts
609
+ * createInitials('John Smith'); // returns 'JS'
610
+ * ```
611
+ */
612
+ declare function createInitials(value?: string | null): string;
613
+
614
+ /**
615
+ * Handles authentication errors by executing a series of error handler functions.
616
+ *
617
+ * @param {AuthErrorHandlerFn[]} handlers - An array of functions that handle authentication errors.
618
+ * Each function is expected to take an `OAuthErrorEvent` as an argument.
619
+ *
620
+ * @returns A function that takes an `OAuthErrorEvent` and processes it using the provided handlers.
621
+ * The function will stop processing once a handler successfully handles the error without throwing.
622
+ * If a handler throws an error that is not an instance of `OAuthErrorEvent`, the original error is re-thrown.
623
+ */
624
+ declare function handleAuthError(handlers: AuthErrorHandlerFn[]): (error: OAuthErrorEvent) => void;
625
+
626
+ /**
627
+ * Handles OAuth events of a specific type by applying a provided handler function.
628
+ *
629
+ * @template {T} - The type of OAuth event.
630
+ * @param {T['type']} type - The type of the OAuth event to handle.
631
+ * @param {(event: T) => Promise<void>} handler - A function that takes an event of type T and returns a Promise that resolves to void.
632
+ * @returns {OperatorFunction<T, void>} - An OperatorFunction that filters events of the specified type and applies the handler function.
633
+ */
634
+ declare function handleOAuthEvent<T extends OAuthEvent>(type: T['type'], handler: (event: T) => Promise<void>): OperatorFunction<T, void>;
635
+
636
+ /**
637
+ * Resolves the email address from the given identity claims.
638
+ *
639
+ * This function attempts to extract an email address from the provided
640
+ * `OdxAuth.RawIdentityClaims` object by checking the following properties
641
+ * in order:
642
+ * 1. `email` - if it is a string, it is returned.
643
+ * 2. `email_address` - if it is a string, it is returned.
644
+ * 3. `emails` - if it is an array and the first element is a string, the first element is returned.
645
+ *
646
+ * If none of these properties contain a valid string email address, an empty string is returned.
647
+ *
648
+ * @param {OdxAuth.RawIdentityClaims} claims - The identity claims object from which to resolve the email address.
649
+ * @returns {string} - The resolved email address as a string, or an empty string if no valid email address is found.
650
+ *
651
+ * @example
652
+ * ```ts
653
+ * resolveEmail({ email_address: 'email.address@mdn.com' }) // returns 'email.address@mdn.com';
654
+ * ```
655
+ */
656
+ declare function resolveEmail(claims: OdxAuth.RawIdentityClaims): string;
657
+
658
+ /**
659
+ * Resolves the username from the provided identity claims.
660
+ *
661
+ * The function attempts to construct a username from the claims in the following order:
662
+ * 1. If both 'firstname' and 'lastname' are strings, it returns them concatenated with a space.
663
+ * 2. If both 'given_name' and 'family_name' are strings, it returns them concatenated with a space.
664
+ * 3. If 'name' is a string, it returns the 'name'.
665
+ * 4. If 'displayname' is a string, it returns the 'displayname'.
666
+ * 5. If none of the above conditions are met, it returns an empty string.
667
+ *
668
+ * @param {OdxAuth.RawIdentityClaims} claims - The raw identity claims from which to resolve the username.
669
+ * @returns {string} - The resolved username as a string.
670
+ *
671
+ * @example
672
+ * ```ts
673
+ * resolveUsername({ firstname: 'John', lastname: 'Doe' }) // returns 'John Doe';
674
+ * resolveUsername({ given_name: 'John', family_name: 'Doe' }) // returns 'John Doe';
675
+ * resolveUsername({ name: 'John Doe' }) // returns 'John Doe';
676
+ * resolveUsername({ displayname: 'John Doe' }) // returns 'John Doe';
677
+ * ```
678
+ */
679
+ declare function resolveUsername(claims: OdxAuth.RawIdentityClaims): string;
680
+
681
+ /**
682
+ * Sets the HTTP Authorization header for a given request.
683
+ *
684
+ * @template R - The type of the request, which extends HttpRequest<T> or Request.
685
+ * @template T - The type of the request body.
686
+ * @param {R} req - The HTTP request to which the Authorization header will be added.
687
+ * @param {string | null} [token] - The token to be used in the Authorization header. If no token is provided, the request is returned unchanged.
688
+ * @returns {R} - The modified HTTP request with the Authorization header set, or the original request if no token is provided.
689
+ */
690
+ declare function setHttpAuthHeader<R extends HttpRequest<T> | Request, T>(req: R, token?: string | null): R;
691
+
692
+ type LanguageSelector = (claims?: OdxAuth.IdentityClaims | null) => string | null | undefined;
693
+ /**
694
+ * A function that creates a language loader function for user authentication.
695
+ *
696
+ * @param {LanguageSelector} languageSelector - A function that takes optional identity claims and returns a language string, null, or undefined.
697
+ * Defaults to a function that returns the preferred language from the claims.
698
+ * @returns {LanguageLoaderFn} - A function that retrieves the user's preferred language from the identity claims.
699
+ */
700
+ declare function userLanguageLoader(languageSelector?: LanguageSelector): LanguageLoaderFn;
701
+
702
+ /**
703
+ * A factory function that creates a core debug plugin for the authentication service.
704
+ * This plugin logs detailed information about the user's identity claims and tokens.
705
+ *
706
+ * @remarks
707
+ * This plugin is intended for debugging purposes only and should not be used in production environments.
708
+ *
709
+ * @returns {AuthPluginFactory} A function that takes an authentication service and sets up logging for identity claims and tokens.
710
+ */
711
+ declare const coreDebugPlugin: AuthPluginFactory;
712
+
713
+ /**
714
+ * Core identity plugin for authentication.
715
+ *
716
+ * This plugin extracts and processes identity claims from the authentication service.
717
+ *
718
+ * @returns {AuthPluginFactory} A factory function that returns an observable with the processed identity claims.
719
+ */
720
+ declare const coreIdentityPlugin: AuthPluginFactory;
721
+
722
+ /**
723
+ * A plugin factory that generates a user profile URL plugin.
724
+ *
725
+ * This plugin retrieves the user profile URL from the authentication configuration.
726
+ * If the user profile URL is not specified in the configuration, it falls back to
727
+ * using the default URL for the current environment from `ODX_AUTH_USER_PROFILE_HOSTS`.
728
+ *
729
+ * @returns A function that returns an observable emitting an object containing the user profile URL.
730
+ */
731
+ declare const userProfileUrlPlugin: AuthPluginFactory;
732
+
733
+ /**
734
+ * Guard function to prevent unauthorized access to routes.
735
+ *
736
+ * @param {AuthorizedHandler} authorizedHandler - Optional handler to check if the user is authorized.
737
+ * @param {any[] | string} redirectTo - Optional URL or route to redirect unauthorized users to. Can be a string or an array of strings.
738
+ * @param {boolean} isExternal - Optional flag to indicate if the redirection should be external. Defaults to false.
739
+ * @returns {CanActivateFn} - A function that implements the CanActivateFn interface.
740
+ */
741
+ declare function unauthGuard(authorizedHandler?: AuthorizedHandler, redirectTo?: any[] | string, isExternal?: boolean): CanActivateFn;
742
+
743
+ export { AUTH_HTTP_HEADER, AuthActionDirective, AuthActionsComponent, AuthComponent, AuthConfig, AuthDefaultConfig, AuthDirective, AuthEnvironment, AuthLoadingScreenComponent, AuthModule, AuthPluginManager, AuthService, ODX_AUTH_CORE_PLUGINS, ODX_AUTH_DEFAULT_SCOPES, ODX_AUTH_ERROR_HANDLERS, ODX_AUTH_HOSTS, ODX_AUTH_PLUGINS, ODX_AUTH_PLUGINS_ERROR_HANDLER, ODX_AUTH_USER_PROFILE_HOSTS, SignInDirective, SignOutDirective, authGuard, authInterceptor, coreDebugPlugin, coreIdentityPlugin, createAuthHostUrl, createInitials, handleAuthError, handleOAuthEvent, initalizeAuthConfig, initializeAuthErrorHandlers, injectAuthConfig, offlineAuthErrorHandler, provideAuth, provideAuthConfig, provideAuthLogger, requireAuthentication, resolveEmail, resolveUsername, setHttpAuthHeader, unauthGuard, userLanguageLoader, userProfileUrlPlugin };
744
+ export type { AuthErrorHandlerFn, AuthPlugin, AuthPluginError, AuthPluginErrorHandler, AuthPluginFactory, AuthorizedHandler, CreateInitialsFn, ResolveEmailFn, ResolveUsernameFn };