@odx/auth 5.1.0 → 6.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.
- package/CHANGELOG.md +28 -0
- package/README.md +4 -4
- package/{esm2020 → esm2022}/lib/auth.component.mjs +4 -4
- package/{esm2020 → esm2022}/lib/auth.directive.mjs +4 -4
- package/{esm2020 → esm2022}/lib/auth.module.mjs +5 -5
- package/{esm2020 → esm2022}/lib/auth.service.mjs +4 -4
- package/esm2022/lib/components/auth-actions/auth-actions.component.mjs +29 -0
- package/esm2022/lib/components/auth-loading-screen/auth-loading-screen.component.mjs +41 -0
- package/{esm2020 → esm2022}/lib/directives/auth-action.directive.mjs +4 -4
- package/{esm2020 → esm2022}/lib/directives/sign-in.directive.mjs +4 -4
- package/{esm2020 → esm2022}/lib/directives/sign-out.directive.mjs +4 -4
- package/esm2022/lib/models/auth-http-cache.mjs +50 -0
- package/{esm2020 → esm2022}/lib/models/auth-plugin-manager.mjs +4 -4
- package/{esm2020 → esm2022}/plugins/service-connect/lib/service-connect-rights.directive.mjs +4 -4
- package/{fesm2020 → fesm2022}/odx-auth-plugins-service-connect.mjs +3 -3
- package/{fesm2020 → fesm2022}/odx-auth-plugins-service-connect.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/odx-auth.mjs +37 -37
- package/{fesm2020 → fesm2022}/odx-auth.mjs.map +1 -1
- package/lib/auth.directive.d.ts +1 -1
- package/lib/components/auth-actions/auth-actions.component.d.ts +1 -1
- package/package.json +13 -21
- package/plugins/service-connect/lib/service-connect-rights.directive.d.ts +1 -1
- package/esm2020/lib/components/auth-actions/auth-actions.component.mjs +0 -30
- package/esm2020/lib/components/auth-loading-screen/auth-loading-screen.component.mjs +0 -41
- package/esm2020/lib/models/auth-http-cache.mjs +0 -50
- package/fesm2015/odx-auth-plugins-service-connect.mjs +0 -93
- package/fesm2015/odx-auth-plugins-service-connect.mjs.map +0 -1
- package/fesm2015/odx-auth.mjs +0 -749
- package/fesm2015/odx-auth.mjs.map +0 -1
- /package/{esm2020 → esm2022}/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/auth.config.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/auth.guard.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/auth.i18n.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/auth.providers.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/auth.typings.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/components/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/directives/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/helpers/create-inititals.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/helpers/handle-auth-error.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/helpers/handle-oauth-event.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/helpers/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/helpers/resolve-email.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/helpers/resolve-username.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/models/auth-environment.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/models/authorized-handler.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/models/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/models/offline-auth-error-handler.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/plugins/core-identity.plugin.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/plugins/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/plugins/user-profile-link.plugin.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/unauth.guard.mjs +0 -0
- /package/{esm2020 → esm2022}/odx-auth.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/index.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/dtos/get-service-connect-rights-response.dto.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/dtos/index.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/helpers/build-service-connect-url.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/helpers/has-roles-or-rights-handler.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/helpers/has-roles-or-rights.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/helpers/index.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/helpers/service-connect-plugin-factory.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/service-connect-rights.guard.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/service-connect-rights.plugin.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/service-connect.config.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/lib/service-connect.typings.mjs +0 -0
- /package/{esm2020 → esm2022}/plugins/service-connect/odx-auth-plugins-service-connect.mjs +0 -0
package/fesm2015/odx-auth.mjs
DELETED
|
@@ -1,749 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, EnvironmentInjector, InjectionToken, Injectable, ErrorHandler, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Directive, EventEmitter, Output, HostListener, NgModule, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, APP_INITIALIZER } from '@angular/core';
|
|
3
|
-
import { WindowRef, CoreModule } from '@odx/angular';
|
|
4
|
-
import * as i3$1 from '@odx/angular/components/area-header';
|
|
5
|
-
import { AreaHeaderModule } from '@odx/angular/components/area-header';
|
|
6
|
-
import * as i8 from '@odx/angular/components/dropdown';
|
|
7
|
-
import { DropdownModule } from '@odx/angular/components/dropdown';
|
|
8
|
-
import { HeaderModule } from '@odx/angular/components/header';
|
|
9
|
-
import * as i1$1 from '@odx/angular/components/loading-spinner';
|
|
10
|
-
import { LoadingSpinnerDirective, LoadingSpinnerModule } from '@odx/angular/components/loading-spinner';
|
|
11
|
-
import { LogoDirective } from '@odx/angular/components/logo';
|
|
12
|
-
import { TranslatePipe, provideTranslations } from '@odx/angular/internal/translate';
|
|
13
|
-
import { isString, createConfigTokens, injectElement, untilDestroyed, Position, buildUrl } from '@odx/angular/utils';
|
|
14
|
-
import { OAuthErrorEvent, OAuthService, provideOAuthClient, OAuthModuleConfig, OAuthStorage } from 'angular-oauth2-oidc';
|
|
15
|
-
import { filter, switchMap, BehaviorSubject, map, distinctUntilChanged, share, of, combineLatest, catchError, tap, take, fromEvent, startWith, shareReplay, merge, EMPTY } from 'rxjs';
|
|
16
|
-
import { __awaiter, __decorate } from 'tslib';
|
|
17
|
-
import { HttpErrorResponse } from '@angular/common/http';
|
|
18
|
-
import { Router } from '@angular/router';
|
|
19
|
-
import { deepmerge } from 'deepmerge-ts';
|
|
20
|
-
import * as i2 from '@odx/angular/components/list';
|
|
21
|
-
import { ListModule } from '@odx/angular/components/list';
|
|
22
|
-
import { CSSComponent } from '@odx/angular/internal';
|
|
23
|
-
import * as i1 from '@angular/common';
|
|
24
|
-
import { CommonModule, NgIf } from '@angular/common';
|
|
25
|
-
import * as i3 from '@odx/angular/components/icon';
|
|
26
|
-
import { IconComponent } from '@odx/angular/components/icon';
|
|
27
|
-
import { trigger, transition, useAnimation } from '@angular/animations';
|
|
28
|
-
import { fadeOut } from '@odx/angular/animations';
|
|
29
|
-
import { DynamicViewDirective, DynamicViewService } from '@odx/angular/cdk/dynamic-view';
|
|
30
|
-
import * as i6 from '@odx/angular/components/button';
|
|
31
|
-
import { ButtonComponent } from '@odx/angular/components/button';
|
|
32
|
-
import { CircularProgressComponent } from '@odx/angular/components/circular-progress';
|
|
33
|
-
import * as i2$1 from '@ngrx/component';
|
|
34
|
-
import * as i4 from '@odx/angular/components/avatar';
|
|
35
|
-
import * as i5 from '@odx/angular/components/action-group';
|
|
36
|
-
|
|
37
|
-
function createInitials(value) {
|
|
38
|
-
if (!value)
|
|
39
|
-
return '';
|
|
40
|
-
const parts = value
|
|
41
|
-
.replace(/\([^()]*\)/, '')
|
|
42
|
-
.trim()
|
|
43
|
-
.split(' ');
|
|
44
|
-
return parts.reduce((initials, curr, index) => {
|
|
45
|
-
if (index === 0 || index === parts.length - 1) {
|
|
46
|
-
initials += curr[0].toUpperCase();
|
|
47
|
-
}
|
|
48
|
-
return initials;
|
|
49
|
-
}, '');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function handleAuthError(handlers) {
|
|
53
|
-
const injector = inject(EnvironmentInjector);
|
|
54
|
-
return (error) => {
|
|
55
|
-
injector.runInContext(() => {
|
|
56
|
-
for (const handler of handlers) {
|
|
57
|
-
try {
|
|
58
|
-
handler(error);
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
catch (unhandledError) {
|
|
62
|
-
if (!(unhandledError instanceof OAuthErrorEvent))
|
|
63
|
-
throw error;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function handleOAuthEvent(type, handler) {
|
|
72
|
-
return (source$) => source$.pipe(filter((event) => event.type === type), switchMap((event) => handler(event)));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function resolveEmail(claims) {
|
|
76
|
-
if (isString(claims['email'])) {
|
|
77
|
-
return claims['email'];
|
|
78
|
-
}
|
|
79
|
-
if (isString(claims['email_address'])) {
|
|
80
|
-
return claims['email_address'];
|
|
81
|
-
}
|
|
82
|
-
if (Array.isArray(claims['emails']) && isString(claims['emails'][0])) {
|
|
83
|
-
return claims['emails'][0];
|
|
84
|
-
}
|
|
85
|
-
return '';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function resolveUsername(claims) {
|
|
89
|
-
if (isString(claims['firstname']) && isString(claims['lastname'])) {
|
|
90
|
-
return `${claims['firstname']} ${claims['lastname']}`;
|
|
91
|
-
}
|
|
92
|
-
if (isString(claims['given_name']) && isString(claims['family_name'])) {
|
|
93
|
-
return `${claims['given_name']} ${claims['family_name']}`;
|
|
94
|
-
}
|
|
95
|
-
if (isString(claims['name'])) {
|
|
96
|
-
return claims['name'];
|
|
97
|
-
}
|
|
98
|
-
if (isString(claims['displayname'])) {
|
|
99
|
-
return claims['displayname'];
|
|
100
|
-
}
|
|
101
|
-
return '';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const DEFAULT_AUTH_SCOPES = ['openid', 'profile', 'email', 'offline_access'];
|
|
105
|
-
const DEFAULT_ISSUERS = {
|
|
106
|
-
dev: 'https://dev.login.draeger.com/oauth2/default',
|
|
107
|
-
stage: 'https://test.login.draeger.com/oauth2/default',
|
|
108
|
-
prod: 'https://login.draeger.com/oauth2/default',
|
|
109
|
-
};
|
|
110
|
-
const DEFAULT_USER_PROFILE_URLS = {
|
|
111
|
-
dev: 'https://lemon-ocean-04a922703.3.azurestaticapps.net',
|
|
112
|
-
stage: 'https://purple-cliff-0e61c5703.3.azurestaticapps.net',
|
|
113
|
-
prod: 'https://id.draeger.com',
|
|
114
|
-
};
|
|
115
|
-
const ODX_AUTH_CORE_PLUGINS = new InjectionToken('@odx/auth::CorePlugins', {
|
|
116
|
-
providedIn: 'root',
|
|
117
|
-
factory: () => [],
|
|
118
|
-
});
|
|
119
|
-
const ODX_AUTH_ERROR_HANDLERS = new InjectionToken('@odx/auth::ErrorHandlers', {
|
|
120
|
-
providedIn: 'root',
|
|
121
|
-
factory: () => [],
|
|
122
|
-
});
|
|
123
|
-
const ODX_AUTH_PLUGINS = new InjectionToken('@odx/auth::Plugins', {
|
|
124
|
-
providedIn: 'root',
|
|
125
|
-
factory: () => {
|
|
126
|
-
const { plugins } = injectAuthConfig();
|
|
127
|
-
const corePlugins = inject(ODX_AUTH_CORE_PLUGINS);
|
|
128
|
-
return [...corePlugins, ...plugins].map((pluginFactory) => pluginFactory());
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
const { AuthDefaultConfig, AuthConfig, injectAuthConfig, provideAuthConfig } = createConfigTokens('Auth', '@odx/auth', {
|
|
132
|
-
environment: 'prod',
|
|
133
|
-
redirectPath: 'login/callback',
|
|
134
|
-
allowedUrls: [],
|
|
135
|
-
timeoutFactor: 0.75,
|
|
136
|
-
maxOfflineTime: 24 * 60 * 60,
|
|
137
|
-
loadUserProfile: false,
|
|
138
|
-
errorHandler: (error) => {
|
|
139
|
-
throw error;
|
|
140
|
-
},
|
|
141
|
-
createInitials,
|
|
142
|
-
resolveEmail,
|
|
143
|
-
resolveUsername,
|
|
144
|
-
plugins: [],
|
|
145
|
-
defaultAuthorizedHandler: null,
|
|
146
|
-
enableLoadingScreen: true,
|
|
147
|
-
loadingScreenMessage: null,
|
|
148
|
-
refreshTokenOnInit: true,
|
|
149
|
-
requireSignIn: false,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
var translations = {
|
|
153
|
-
en: {
|
|
154
|
-
userProfileLink: 'My profile',
|
|
155
|
-
signInButtonText: 'Sign in',
|
|
156
|
-
signOutButtonText: 'Sign out',
|
|
157
|
-
},
|
|
158
|
-
de: {
|
|
159
|
-
userProfileLink: 'Mein Profil',
|
|
160
|
-
signInButtonText: 'Einloggen',
|
|
161
|
-
signOutButtonText: 'Ausloggen',
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const ODX_AUTH_HTTP_CACHE_STORAGE = new InjectionToken('@odx/auth::AuthHttpCacheStorage', {
|
|
166
|
-
providedIn: 'root',
|
|
167
|
-
factory: () => inject(WindowRef).nativeWindow.caches,
|
|
168
|
-
});
|
|
169
|
-
class AuthHttpCache {
|
|
170
|
-
constructor() {
|
|
171
|
-
this.cacheStorage = inject(ODX_AUTH_HTTP_CACHE_STORAGE);
|
|
172
|
-
this.oauthService = inject(OAuthService);
|
|
173
|
-
this.oauthService.events.pipe(handleOAuthEvent('logout', () => this.deleteAll())).subscribe();
|
|
174
|
-
}
|
|
175
|
-
deleteAll() {
|
|
176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
const cache = yield this.cacheStorage.open(AuthHttpCache.CACHE_KEY);
|
|
178
|
-
for (const key of yield cache.keys()) {
|
|
179
|
-
yield cache.delete(key);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
delete(request) {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
const cache = yield this.cacheStorage.open(AuthHttpCache.CACHE_KEY);
|
|
186
|
-
return cache.delete(request);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
request(requestInfo, authentication = false) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
const request = new Request(requestInfo);
|
|
192
|
-
const authorizationHeader = authentication ? this.oauthService.authorizationHeader() : null;
|
|
193
|
-
if (authorizationHeader) {
|
|
194
|
-
request.headers.set('Authorization', authorizationHeader);
|
|
195
|
-
}
|
|
196
|
-
const cache = yield this.cacheStorage.open(AuthHttpCache.CACHE_KEY);
|
|
197
|
-
const response = yield fetch(request).catch(() => null);
|
|
198
|
-
if (response === null || response === void 0 ? void 0 : response.ok) {
|
|
199
|
-
yield cache.put(request, response).catch(() => null);
|
|
200
|
-
}
|
|
201
|
-
if (authorizationHeader && (response === null || response === void 0 ? void 0 : response.status) === 401) {
|
|
202
|
-
yield cache.delete(request);
|
|
203
|
-
}
|
|
204
|
-
return cache.match(request).then((res) => { var _a; return (_a = res === null || res === void 0 ? void 0 : res.json()) !== null && _a !== void 0 ? _a : null; });
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
AuthHttpCache.CACHE_KEY = '@odx/auth/http-cache';
|
|
209
|
-
AuthHttpCache.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthHttpCache, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
210
|
-
AuthHttpCache.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthHttpCache, providedIn: 'root' });
|
|
211
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthHttpCache, decorators: [{
|
|
212
|
-
type: Injectable,
|
|
213
|
-
args: [{ providedIn: 'root' }]
|
|
214
|
-
}], ctorParameters: function () { return []; } });
|
|
215
|
-
|
|
216
|
-
class AuthPluginManager {
|
|
217
|
-
constructor() {
|
|
218
|
-
this.errorHandler = inject(ErrorHandler, { optional: true });
|
|
219
|
-
this.plugins = inject(ODX_AUTH_PLUGINS);
|
|
220
|
-
this.result$$ = new BehaviorSubject(null);
|
|
221
|
-
this.pluginsReady$ = this.result$$.pipe(filter(Boolean), map(Boolean), distinctUntilChanged(), share());
|
|
222
|
-
this.pluginsLoading$ = this.result$$.pipe(map((result) => !result), distinctUntilChanged(), share());
|
|
223
|
-
}
|
|
224
|
-
runPlugins(authService) {
|
|
225
|
-
if (this.plugins.length < 1) {
|
|
226
|
-
return of({});
|
|
227
|
-
}
|
|
228
|
-
return authService.isInitialized$.pipe(switchMap(() => {
|
|
229
|
-
if (!authService.getAccessToken()) {
|
|
230
|
-
return of({});
|
|
231
|
-
}
|
|
232
|
-
return combineLatest(this.plugins.map((plugin) => plugin(authService).pipe(catchError(this.handlePluginError.bind(this))))).pipe(map((results) => deepmerge(...results)));
|
|
233
|
-
}), tap((result) => this.result$$.next(result)), take(1));
|
|
234
|
-
}
|
|
235
|
-
getResult() {
|
|
236
|
-
var _a;
|
|
237
|
-
return (_a = this.result$$.getValue()) !== null && _a !== void 0 ? _a : {};
|
|
238
|
-
}
|
|
239
|
-
handlePluginError(error) {
|
|
240
|
-
var _a;
|
|
241
|
-
(_a = this.errorHandler) === null || _a === void 0 ? void 0 : _a.handleError(error);
|
|
242
|
-
return of({});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
AuthPluginManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthPluginManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
246
|
-
AuthPluginManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthPluginManager, providedIn: 'root' });
|
|
247
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthPluginManager, decorators: [{
|
|
248
|
-
type: Injectable,
|
|
249
|
-
args: [{ providedIn: 'root' }]
|
|
250
|
-
}] });
|
|
251
|
-
|
|
252
|
-
const offlineAuthErrorHandler = (error) => {
|
|
253
|
-
var _a;
|
|
254
|
-
if (error.type === 'discovery_document_load_error' && ((_a = error.reason) === null || _a === void 0 ? void 0 : _a.status) === 504) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
throw error;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
class AuthService {
|
|
261
|
-
constructor() {
|
|
262
|
-
this.authConfig = injectAuthConfig();
|
|
263
|
-
this.authPluginManager = inject(AuthPluginManager);
|
|
264
|
-
this.oauthService = inject(OAuthService);
|
|
265
|
-
this.router = inject(Router);
|
|
266
|
-
this.windowRef = inject(WindowRef);
|
|
267
|
-
this.isInitialized$$ = new BehaviorSubject(false);
|
|
268
|
-
this.isRedirecting$$ = new BehaviorSubject(false);
|
|
269
|
-
this.onAccessTokenUpdate$ = fromEvent(this.windowRef.nativeWindow, 'storage').pipe(filter(({ key }) => key === 'access_token' || key === null), startWith(null), share());
|
|
270
|
-
this.silentRefreshHandler$ = this.isInitialized$$.pipe(filter(Boolean), switchMap(() => this.windowRef.isOnline$), tap((isOnline) => this.updateSilentRefresh(isOnline)));
|
|
271
|
-
this.onAuthStateChange$ = combineLatest([this.oauthService.events.pipe(startWith(null)), this.windowRef.isOnline$, this.onAccessTokenUpdate$]);
|
|
272
|
-
this.isInitialized$ = this.isInitialized$$.pipe(filter(Boolean), distinctUntilChanged());
|
|
273
|
-
this.isRedirecting$ = this.isRedirecting$$.pipe(distinctUntilChanged(), shareReplay({ refCount: true }));
|
|
274
|
-
this.isLoading$ = merge(this.isRedirecting$, this.authPluginManager.pluginsLoading$).pipe(distinctUntilChanged());
|
|
275
|
-
this.isAuthenticated$ = this.isInitialized$.pipe(switchMap(() => this.authPluginManager.pluginsReady$), switchMap(() => this.onAuthStateChange$), map(() => this.isAuthenticated()), shareReplay({ refCount: true }));
|
|
276
|
-
this.identityClaims$ = this.isAuthenticated$.pipe(map(() => this.getIdentityClaims()), shareReplay({ refCount: true }));
|
|
277
|
-
this.errors$ = this.oauthService.events.pipe(filter((event) => event instanceof OAuthErrorEvent), share());
|
|
278
|
-
this.authPluginManager.runPlugins(this).subscribe();
|
|
279
|
-
this.silentRefreshHandler$.subscribe();
|
|
280
|
-
}
|
|
281
|
-
initialize(config) {
|
|
282
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
-
this.assertAudience(config.clientId);
|
|
284
|
-
this.oauthService.configure(Object.assign(Object.assign({}, config), { openUri: this.redirectToLogin.bind(this) }));
|
|
285
|
-
try {
|
|
286
|
-
yield this.oauthService.loadDiscoveryDocument(this.authConfig.discoveryUrl);
|
|
287
|
-
yield this.oauthService.tryLogin();
|
|
288
|
-
yield this.tryRefreshToken();
|
|
289
|
-
}
|
|
290
|
-
catch (error) {
|
|
291
|
-
if (!(error instanceof HttpErrorResponse || error instanceof OAuthErrorEvent)) {
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
if (error.type === 'token_refresh_error' || (error instanceof HttpErrorResponse && error.status === 401)) {
|
|
295
|
-
this.signOut(true);
|
|
296
|
-
this.signIn(this.windowRef.location.pathname);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
this.isInitialized$$.next(true);
|
|
300
|
-
if (this.authConfig.requireSignIn && !this.isAuthenticated()) {
|
|
301
|
-
this.signIn(this.windowRef.location.pathname);
|
|
302
|
-
}
|
|
303
|
-
yield this.tryLoadUserProfile();
|
|
304
|
-
yield this.routeToRequestedUrl();
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
getIssuer() {
|
|
308
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
309
|
-
return new URL(this.oauthService.issuer);
|
|
310
|
-
}
|
|
311
|
-
signIn(url) {
|
|
312
|
-
this.oauthService.initLoginFlow(url);
|
|
313
|
-
}
|
|
314
|
-
signOut(noRedirect) {
|
|
315
|
-
this.oauthService.logOut(noRedirect || !this.getAccessToken());
|
|
316
|
-
}
|
|
317
|
-
loadUserProfile() {
|
|
318
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
319
|
-
yield this.oauthService.loadUserProfile();
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
refreshTokens() {
|
|
323
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
324
|
-
return this.oauthService.refreshToken();
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
getAccessToken() {
|
|
328
|
-
var _a;
|
|
329
|
-
return (_a = this.oauthService.getAccessToken()) !== null && _a !== void 0 ? _a : null;
|
|
330
|
-
}
|
|
331
|
-
getRefreshToken() {
|
|
332
|
-
var _a;
|
|
333
|
-
return (_a = this.oauthService.getRefreshToken()) !== null && _a !== void 0 ? _a : null;
|
|
334
|
-
}
|
|
335
|
-
getIdToken() {
|
|
336
|
-
var _a;
|
|
337
|
-
return (_a = this.oauthService.getIdToken()) !== null && _a !== void 0 ? _a : null;
|
|
338
|
-
}
|
|
339
|
-
getIdentityClaims() {
|
|
340
|
-
if (!this.getIdToken())
|
|
341
|
-
return null;
|
|
342
|
-
return deepmerge(this.oauthService.getIdentityClaims(), this.authPluginManager.getResult());
|
|
343
|
-
}
|
|
344
|
-
getRawIdentityClaims() {
|
|
345
|
-
if (!this.getIdToken())
|
|
346
|
-
return null;
|
|
347
|
-
return this.oauthService.getIdentityClaims();
|
|
348
|
-
}
|
|
349
|
-
isAuthenticated() {
|
|
350
|
-
if (this.windowRef.isOnline()) {
|
|
351
|
-
return this.oauthService.hasValidAccessToken() && this.oauthService.hasValidIdToken();
|
|
352
|
-
}
|
|
353
|
-
return this.hasValidOfflineToken();
|
|
354
|
-
}
|
|
355
|
-
isAuthorized(authorizedHandler) {
|
|
356
|
-
var _a;
|
|
357
|
-
const handler = authorizedHandler !== null && authorizedHandler !== void 0 ? authorizedHandler : this.authConfig.defaultAuthorizedHandler;
|
|
358
|
-
return this.isAuthenticated() && ((_a = handler === null || handler === void 0 ? void 0 : handler(this.getIdentityClaims(), this, this.router)) !== null && _a !== void 0 ? _a : true);
|
|
359
|
-
}
|
|
360
|
-
isAuthorized$(authorizedHandler) {
|
|
361
|
-
return this.isAuthenticated$.pipe(map(() => this.isAuthorized(authorizedHandler)));
|
|
362
|
-
}
|
|
363
|
-
routeToRequestedUrl() {
|
|
364
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
-
if (!this.oauthService.state || !this.oauthService.hasValidAccessToken())
|
|
366
|
-
return;
|
|
367
|
-
yield this.router.navigateByUrl(decodeURIComponent(this.oauthService.state));
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
hasValidOfflineToken() {
|
|
371
|
-
var _a, _b;
|
|
372
|
-
const issuedAt = (_b = (_a = this.getIdentityClaims()) === null || _a === void 0 ? void 0 : _a.iat) !== null && _b !== void 0 ? _b : 0;
|
|
373
|
-
return Date.now() - issuedAt * 1000 <= this.authConfig.maxOfflineTime * 1000;
|
|
374
|
-
}
|
|
375
|
-
redirectToLogin(uri) {
|
|
376
|
-
this.windowRef.location.assign(uri);
|
|
377
|
-
this.isRedirecting$$.next(true);
|
|
378
|
-
}
|
|
379
|
-
tryRefreshToken() {
|
|
380
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
381
|
-
if (!this.authConfig.refreshTokenOnInit || !this.getRefreshToken())
|
|
382
|
-
return;
|
|
383
|
-
yield this.oauthService.refreshToken();
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
tryLoadUserProfile() {
|
|
387
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
388
|
-
if (!this.authConfig.loadUserProfile || !this.oauthService.hasValidAccessToken())
|
|
389
|
-
return;
|
|
390
|
-
yield this.loadUserProfile().catch(() => null);
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
assertAudience(clientId) {
|
|
394
|
-
var _a;
|
|
395
|
-
const tokenClientId = (_a = this.getIdentityClaims()) === null || _a === void 0 ? void 0 : _a.aud;
|
|
396
|
-
if (!clientId || !tokenClientId || clientId === tokenClientId)
|
|
397
|
-
return;
|
|
398
|
-
this.signOut(true);
|
|
399
|
-
}
|
|
400
|
-
updateSilentRefresh(enabled) {
|
|
401
|
-
if (enabled) {
|
|
402
|
-
this.oauthService.setupAutomaticSilentRefresh();
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
this.oauthService.stopAutomaticRefresh();
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
410
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
411
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthService, decorators: [{
|
|
412
|
-
type: Injectable,
|
|
413
|
-
args: [{ providedIn: 'root' }]
|
|
414
|
-
}], ctorParameters: function () { return []; } });
|
|
415
|
-
|
|
416
|
-
let AuthActionsComponent = class AuthActionsComponent {
|
|
417
|
-
constructor() {
|
|
418
|
-
this.element = injectElement();
|
|
419
|
-
this.claims = null;
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
AuthActionsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthActionsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
423
|
-
AuthActionsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: AuthActionsComponent, isStandalone: true, selector: "odx-auth-actions", inputs: { claims: "claims" }, ngImport: i0, template: "<odx-list>\n <a data-testid=\"odx-auth-user-profile-link\" odxListItem [href]=\"url\" rel=\"noopener\" target=\"_blank\" *ngIf=\"claims?.userProfileUrl as url\">\n <odx-icon name=\"user-administration\" iconSet=\"core\" odxListPrefix></odx-icon>\n {{ 'userProfileLink' | odxTranslate | async }}\n </a>\n</odx-list>\n", dependencies: [{ kind: "ngmodule", type: CoreModule }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "ngmodule", type: ListModule }, { kind: "component", type: i2.ListComponent, selector: "odx-list", inputs: ["multiple"] }, { kind: "component", type: i2.ListItemComponent, selector: "[odxListItem]", inputs: ["danger", "selected"] }, { kind: "component", type: i3.IconComponent, selector: "odx-icon", inputs: ["inline", "size", "name", "iconSet"] }, { kind: "pipe", type: TranslatePipe, name: "odxTranslate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
424
|
-
AuthActionsComponent = __decorate([
|
|
425
|
-
CSSComponent('auth-actions')
|
|
426
|
-
], AuthActionsComponent);
|
|
427
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthActionsComponent, decorators: [{
|
|
428
|
-
type: Component,
|
|
429
|
-
args: [{ standalone: true, selector: 'odx-auth-actions', imports: [CoreModule, ListModule, TranslatePipe], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: "<odx-list>\n <a data-testid=\"odx-auth-user-profile-link\" odxListItem [href]=\"url\" rel=\"noopener\" target=\"_blank\" *ngIf=\"claims?.userProfileUrl as url\">\n <odx-icon name=\"user-administration\" iconSet=\"core\" odxListPrefix></odx-icon>\n {{ 'userProfileLink' | odxTranslate | async }}\n </a>\n</odx-list>\n" }]
|
|
430
|
-
}], propDecorators: { claims: [{
|
|
431
|
-
type: Input
|
|
432
|
-
}] } });
|
|
433
|
-
|
|
434
|
-
class AuthLoadingScreenComponent {
|
|
435
|
-
constructor() {
|
|
436
|
-
this.authConfig = injectAuthConfig();
|
|
437
|
-
this.icon$ = inject(AuthService).isRedirecting$.pipe(distinctUntilChanged(), map((isRedirecting) => (isRedirecting ? 'link-external' : 'user')));
|
|
438
|
-
}
|
|
439
|
-
static initialize(authService, dynamicViewService) {
|
|
440
|
-
authService.isLoading$.subscribe((isLoading) => {
|
|
441
|
-
var _a, _b;
|
|
442
|
-
if (isLoading) {
|
|
443
|
-
(_a = AuthLoadingScreenComponent.instance) !== null && _a !== void 0 ? _a : (AuthLoadingScreenComponent.instance = dynamicViewService.createView(AuthLoadingScreenComponent));
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
(_b = AuthLoadingScreenComponent.instance) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
447
|
-
AuthLoadingScreenComponent.instance = null;
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
AuthLoadingScreenComponent.instance = null;
|
|
453
|
-
AuthLoadingScreenComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthLoadingScreenComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
454
|
-
AuthLoadingScreenComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: AuthLoadingScreenComponent, isStandalone: true, selector: "div.odx-auth-loading-screen", host: { properties: { "@hostAnimation": "true" } }, ngImport: i0, template: "<div class=\"odx-auth-loading-screen__content\" odxLayout=\"grid 12 horizontal-center vertical-center gap-small\">\n <odx-logo size=\"large\"></odx-logo>\n <odx-circular-progress class=\"odx-auth-loading-screen__spinner\" value=\"-1\" size=\"medium\" stroke=\"3\">\n <odx-icon [name]=\"icon$ | async\" iconSet=\"core\"></odx-icon>\n </odx-circular-progress>\n <p class=\"odx-auth-loading-screen__message\" *ngIf=\"authConfig.loadingScreenMessage as content\">\n <ng-template [odxDynamicView]=\"content\"></ng-template>\n </p>\n</div>\n", styles: ["@keyframes odx-auth-loading-screen-animation{0%{opacity:0;transform:translate(-50%,-50%) scale(.9)}to{opacity:1;transform:translate(-50%,-50%)}}.odx-auth-loading-screen{--odx-c-highlight: var(--odx-c-primary);background-color:var(--odx-c-background-content);position:fixed;z-index:var(--odx-v-layer-5);inset:0}.odx-auth-loading-screen__content{top:50%;left:50%;transform:translate(-50%,-50%);position:absolute;animation:odx-auth-loading-screen-animation .75s ease}.odx-auth-loading-screen__message{text-align:center}.odx-auth-loading-screen__spinner{position:relative}.odx-auth-loading-screen__spinner .odx-icon{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "component", type: IconComponent, selector: "odx-icon", inputs: ["inline", "size", "name", "iconSet"] }, { kind: "directive", type: LogoDirective, selector: "odx-logo", inputs: ["size", "variant"] }, { kind: "component", type: CircularProgressComponent, selector: "odx-circular-progress", inputs: ["stroke", "size", "value"] }, { kind: "directive", type: DynamicViewDirective, selector: "ng-template[odxDynamicView]", inputs: ["odxDynamicView", "odxDynamicViewInjector", "odxDynamicViewContext"] }], animations: [trigger('hostAnimation', [transition(':leave', useAnimation(fadeOut()))])], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
455
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthLoadingScreenComponent, decorators: [{
|
|
456
|
-
type: Component,
|
|
457
|
-
args: [{ standalone: true, selector: 'div.odx-auth-loading-screen', imports: [CommonModule, ButtonComponent, IconComponent, LogoDirective, CircularProgressComponent, DynamicViewDirective], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
458
|
-
'[@hostAnimation]': 'true',
|
|
459
|
-
}, animations: [trigger('hostAnimation', [transition(':leave', useAnimation(fadeOut()))])], template: "<div class=\"odx-auth-loading-screen__content\" odxLayout=\"grid 12 horizontal-center vertical-center gap-small\">\n <odx-logo size=\"large\"></odx-logo>\n <odx-circular-progress class=\"odx-auth-loading-screen__spinner\" value=\"-1\" size=\"medium\" stroke=\"3\">\n <odx-icon [name]=\"icon$ | async\" iconSet=\"core\"></odx-icon>\n </odx-circular-progress>\n <p class=\"odx-auth-loading-screen__message\" *ngIf=\"authConfig.loadingScreenMessage as content\">\n <ng-template [odxDynamicView]=\"content\"></ng-template>\n </p>\n</div>\n", styles: ["@keyframes odx-auth-loading-screen-animation{0%{opacity:0;transform:translate(-50%,-50%) scale(.9)}to{opacity:1;transform:translate(-50%,-50%)}}.odx-auth-loading-screen{--odx-c-highlight: var(--odx-c-primary);background-color:var(--odx-c-background-content);position:fixed;z-index:var(--odx-v-layer-5);inset:0}.odx-auth-loading-screen__content{top:50%;left:50%;transform:translate(-50%,-50%);position:absolute;animation:odx-auth-loading-screen-animation .75s ease}.odx-auth-loading-screen__message{text-align:center}.odx-auth-loading-screen__spinner{position:relative}.odx-auth-loading-screen__spinner .odx-icon{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}\n"] }]
|
|
460
|
-
}] });
|
|
461
|
-
|
|
462
|
-
class AuthActionDirective {
|
|
463
|
-
constructor() {
|
|
464
|
-
this.takeUntilDestroyed = untilDestroyed();
|
|
465
|
-
this.loadingSpinnerDirective = inject(LoadingSpinnerDirective, { self: true });
|
|
466
|
-
this.authService = inject(AuthService);
|
|
467
|
-
}
|
|
468
|
-
ngAfterViewInit() {
|
|
469
|
-
this.loadingSpinnerDirective.autoColor = true;
|
|
470
|
-
this.authService.isRedirecting$.pipe(this.takeUntilDestroyed()).subscribe((isRedirecting) => {
|
|
471
|
-
this.loadingSpinnerDirective.isLoading = isRedirecting;
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
AuthActionDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthActionDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
476
|
-
AuthActionDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.10", type: AuthActionDirective, ngImport: i0 });
|
|
477
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthActionDirective, decorators: [{
|
|
478
|
-
type: Directive
|
|
479
|
-
}] });
|
|
480
|
-
|
|
481
|
-
class SignInDirective extends AuthActionDirective {
|
|
482
|
-
constructor() {
|
|
483
|
-
super(...arguments);
|
|
484
|
-
// eslint-disable-next-line @angular-eslint/no-output-rename
|
|
485
|
-
this.afterSignIn = new EventEmitter();
|
|
486
|
-
}
|
|
487
|
-
handleClick() {
|
|
488
|
-
this.authService.signIn();
|
|
489
|
-
this.afterSignIn.next();
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
SignInDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SignInDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
493
|
-
SignInDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.10", type: SignInDirective, isStandalone: true, selector: "[odxButton][odxAuthSignIn]", outputs: { afterSignIn: "odxAuthSignIn" }, host: { listeners: { "click": "handleClick()" } }, usesInheritance: true, hostDirectives: [{ directive: i1$1.LoadingSpinnerDirective }], ngImport: i0 });
|
|
494
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SignInDirective, decorators: [{
|
|
495
|
-
type: Directive,
|
|
496
|
-
args: [{
|
|
497
|
-
standalone: true,
|
|
498
|
-
selector: '[odxButton][odxAuthSignIn]',
|
|
499
|
-
hostDirectives: [LoadingSpinnerDirective],
|
|
500
|
-
}]
|
|
501
|
-
}], propDecorators: { afterSignIn: [{
|
|
502
|
-
type: Output,
|
|
503
|
-
args: ['odxAuthSignIn']
|
|
504
|
-
}], handleClick: [{
|
|
505
|
-
type: HostListener,
|
|
506
|
-
args: ['click']
|
|
507
|
-
}] } });
|
|
508
|
-
|
|
509
|
-
class SignOutDirective extends AuthActionDirective {
|
|
510
|
-
constructor() {
|
|
511
|
-
super(...arguments);
|
|
512
|
-
// eslint-disable-next-line @angular-eslint/no-output-rename
|
|
513
|
-
this.afterSignOut = new EventEmitter();
|
|
514
|
-
}
|
|
515
|
-
handleClick() {
|
|
516
|
-
this.authService.signOut();
|
|
517
|
-
this.afterSignOut.next();
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
SignOutDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SignOutDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
521
|
-
SignOutDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.10", type: SignOutDirective, isStandalone: true, selector: "[odxButton][odxAuthSignOut]", outputs: { afterSignOut: "odxAuthSignOut" }, host: { listeners: { "click": "handleClick()" } }, usesInheritance: true, hostDirectives: [{ directive: i1$1.LoadingSpinnerDirective }], ngImport: i0 });
|
|
522
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SignOutDirective, decorators: [{
|
|
523
|
-
type: Directive,
|
|
524
|
-
args: [{
|
|
525
|
-
standalone: true,
|
|
526
|
-
selector: '[odxButton][odxAuthSignOut]',
|
|
527
|
-
hostDirectives: [LoadingSpinnerDirective],
|
|
528
|
-
}]
|
|
529
|
-
}], propDecorators: { afterSignOut: [{
|
|
530
|
-
type: Output,
|
|
531
|
-
args: ['odxAuthSignOut']
|
|
532
|
-
}], handleClick: [{
|
|
533
|
-
type: HostListener,
|
|
534
|
-
args: ['click']
|
|
535
|
-
}] } });
|
|
536
|
-
|
|
537
|
-
class AuthComponent {
|
|
538
|
-
constructor() {
|
|
539
|
-
this.authConfig = injectAuthConfig();
|
|
540
|
-
this.authService = inject(AuthService);
|
|
541
|
-
this.dropdownOptions = {
|
|
542
|
-
position: Position.BOTTOM_END,
|
|
543
|
-
enableFallback: false,
|
|
544
|
-
containerClass: 'odx-auth-user-profile',
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
AuthComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
549
|
-
AuthComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: AuthComponent, isStandalone: true, selector: "odx-auth", providers: [provideTranslations(translations)], ngImport: i0, template: "<odx-action-group>\n <ng-template [ngrxLet]=\"{ idClaims: authService.identityClaims$, isAuthenticated: authService.isAuthenticated$ }\" let-vm>\n <ng-template [ngIf]=\"vm.isAuthenticated\" [ngIfElse]=\"notAuthenticated\">\n <button odxButton [odxDropdown]=\"userProfileMenu\" [odxDropdownOptions]=\"dropdownOptions\" data-testid=\"odx-auth-user-profile-button\">\n <ng-template [ngTemplateOutlet]=\"userAvatar\"></ng-template>\n </button>\n <ng-template #userProfileMenu>\n <odx-area-header class=\"odx-padding-x-12\" size=\"small\">\n <ng-template [ngTemplateOutlet]=\"userAvatar\" ngProjectAs=\"odx-avatar\"></ng-template>\n {{ vm.idClaims?.username }}\n <odx-area-header-subtitle>\n {{ vm.idClaims?.email }}\n </odx-area-header-subtitle>\n </odx-area-header>\n <ng-content></ng-content>\n <odx-auth-actions [claims]=\"vm.idClaims\"></odx-auth-actions>\n <div class=\"odx-margin-top-12\" odxLayout=\"flex vertical-center\">\n <odx-logo odxLayout=\"auto\" class=\"odx-margin-left-12 odx-margin-right-auto\"></odx-logo>\n <button odxButton odxAuthSignOut variant=\"ghost\" data-testid=\"odx-auth-sign-out-button\">\n {{ 'signOutButtonText' | odxTranslate | async }}\n <odx-icon name=\"logout\" alignRight></odx-icon>\n </button>\n </div>\n </ng-template>\n </ng-template>\n <ng-template #notAuthenticated>\n <button class=\"odx-auth-sign-in\" odxButton odxAuthSignIn variant=\"secondary\" data-testid=\"odx-auth-sign-in-button\">\n <odx-icon name=\"user\" alignLeft></odx-icon>\n {{ 'signInButtonText' | odxTranslate | async }}\n </button>\n </ng-template>\n <ng-template #userAvatar>\n <odx-avatar class=\"odx-auth-user-avatar\">\n {{ vm.idClaims?.initials ?? '' }}\n </odx-avatar>\n </ng-template>\n </ng-template>\n</odx-action-group>\n", styles: [".odx-auth-user-profile .odx-dropdown__inner>.odx-area-header{max-width:max(360px,25vw);min-width:296px}.odx-auth-actions{display:block;margin-top:calc(var(--odx-vertical-rythm-base-size) * .5);margin-bottom:calc(var(--odx-vertical-rythm-base-size) * .5);margin-right:calc(var(--odx-vertical-rythm-base-size) * .25);margin-left:calc(var(--odx-vertical-rythm-base-size) * .25)}\n"], dependencies: [{ kind: "ngmodule", type: CoreModule }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "directive", type: i2$1.LetDirective, selector: "[ngrxLet]", inputs: ["ngrxLet", "ngrxLetSuspenseTpl"] }, { kind: "ngmodule", type: AreaHeaderModule }, { kind: "component", type: i3$1.AreaHeaderComponent, selector: "odx-area-header", inputs: ["size"] }, { kind: "directive", type: i3$1.AreaHeaderSubtitleDirective, selector: "odx-area-header-subtitle" }, { kind: "component", type: i4.AvatarComponent, selector: "odx-avatar", inputs: ["size", "variant"] }, { kind: "component", type: i5.ActionGroupComponent, selector: "odx-action-group", inputs: ["reverse"] }, { kind: "component", type: i6.ButtonComponent, selector: "button[odxButton], a[odxButton]", inputs: ["variant", "size"] }, { kind: "component", type: i3.IconComponent, selector: "odx-icon", inputs: ["inline", "size", "name", "iconSet"] }, { kind: "ngmodule", type: DropdownModule }, { kind: "directive", type: i8.DropdownDirective, selector: "[odxDropdown]", inputs: ["odxDropdown", "odxDropdownDisabled", "odxDropdownShowLoader", "odxDropdownClickOutsideActive", "odxDropdownOptions", "odxDropdownReferenceElement", "odxDropdownTriggerElement", "odxDropdownHost", "odxDropdownOpenTrigger", "odxDropdownCloseTrigger"], outputs: ["odxDropdownBeforeOpen", "odxDropdownAfterOpen", "odxDropdownBeforeClose", "odxDropdownAfterClose"], exportAs: ["odxDropdown"] }, { kind: "ngmodule", type: HeaderModule }, { kind: "directive", type: LogoDirective, selector: "odx-logo", inputs: ["size", "variant"] }, { kind: "directive", type: SignInDirective, selector: "[odxButton][odxAuthSignIn]", outputs: ["odxAuthSignIn"] }, { kind: "directive", type: SignOutDirective, selector: "[odxButton][odxAuthSignOut]", outputs: ["odxAuthSignOut"] }, { kind: "ngmodule", type: LoadingSpinnerModule }, { kind: "component", type: AuthActionsComponent, selector: "odx-auth-actions", inputs: ["claims"] }, { kind: "pipe", type: TranslatePipe, name: "odxTranslate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
550
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthComponent, decorators: [{
|
|
551
|
-
type: Component,
|
|
552
|
-
args: [{ standalone: true, selector: 'odx-auth', imports: [
|
|
553
|
-
CoreModule,
|
|
554
|
-
AreaHeaderModule,
|
|
555
|
-
DropdownModule,
|
|
556
|
-
HeaderModule,
|
|
557
|
-
LogoDirective,
|
|
558
|
-
SignInDirective,
|
|
559
|
-
SignOutDirective,
|
|
560
|
-
LoadingSpinnerModule,
|
|
561
|
-
AuthActionsComponent,
|
|
562
|
-
TranslatePipe,
|
|
563
|
-
], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [provideTranslations(translations)], template: "<odx-action-group>\n <ng-template [ngrxLet]=\"{ idClaims: authService.identityClaims$, isAuthenticated: authService.isAuthenticated$ }\" let-vm>\n <ng-template [ngIf]=\"vm.isAuthenticated\" [ngIfElse]=\"notAuthenticated\">\n <button odxButton [odxDropdown]=\"userProfileMenu\" [odxDropdownOptions]=\"dropdownOptions\" data-testid=\"odx-auth-user-profile-button\">\n <ng-template [ngTemplateOutlet]=\"userAvatar\"></ng-template>\n </button>\n <ng-template #userProfileMenu>\n <odx-area-header class=\"odx-padding-x-12\" size=\"small\">\n <ng-template [ngTemplateOutlet]=\"userAvatar\" ngProjectAs=\"odx-avatar\"></ng-template>\n {{ vm.idClaims?.username }}\n <odx-area-header-subtitle>\n {{ vm.idClaims?.email }}\n </odx-area-header-subtitle>\n </odx-area-header>\n <ng-content></ng-content>\n <odx-auth-actions [claims]=\"vm.idClaims\"></odx-auth-actions>\n <div class=\"odx-margin-top-12\" odxLayout=\"flex vertical-center\">\n <odx-logo odxLayout=\"auto\" class=\"odx-margin-left-12 odx-margin-right-auto\"></odx-logo>\n <button odxButton odxAuthSignOut variant=\"ghost\" data-testid=\"odx-auth-sign-out-button\">\n {{ 'signOutButtonText' | odxTranslate | async }}\n <odx-icon name=\"logout\" alignRight></odx-icon>\n </button>\n </div>\n </ng-template>\n </ng-template>\n <ng-template #notAuthenticated>\n <button class=\"odx-auth-sign-in\" odxButton odxAuthSignIn variant=\"secondary\" data-testid=\"odx-auth-sign-in-button\">\n <odx-icon name=\"user\" alignLeft></odx-icon>\n {{ 'signInButtonText' | odxTranslate | async }}\n </button>\n </ng-template>\n <ng-template #userAvatar>\n <odx-avatar class=\"odx-auth-user-avatar\">\n {{ vm.idClaims?.initials ?? '' }}\n </odx-avatar>\n </ng-template>\n </ng-template>\n</odx-action-group>\n", styles: [".odx-auth-user-profile .odx-dropdown__inner>.odx-area-header{max-width:max(360px,25vw);min-width:296px}.odx-auth-actions{display:block;margin-top:calc(var(--odx-vertical-rythm-base-size) * .5);margin-bottom:calc(var(--odx-vertical-rythm-base-size) * .5);margin-right:calc(var(--odx-vertical-rythm-base-size) * .25);margin-left:calc(var(--odx-vertical-rythm-base-size) * .25)}\n"] }]
|
|
564
|
-
}] });
|
|
565
|
-
|
|
566
|
-
class AuthDirective {
|
|
567
|
-
constructor() {
|
|
568
|
-
this.authService = inject(AuthService);
|
|
569
|
-
this.ngIfDirective = inject(NgIf, { host: true });
|
|
570
|
-
this.takeUntilDestroyed = untilDestroyed();
|
|
571
|
-
this.authorizationHandler = null;
|
|
572
|
-
}
|
|
573
|
-
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
574
|
-
set elseTemplate(value) {
|
|
575
|
-
this.ngIfDirective.ngIfElse = value;
|
|
576
|
-
}
|
|
577
|
-
ngAfterViewInit() {
|
|
578
|
-
this.authService.identityClaims$.pipe(this.takeUntilDestroyed()).subscribe(() => {
|
|
579
|
-
const handler = isString(this.authorizationHandler) ? null : this.authorizationHandler;
|
|
580
|
-
this.ngIfDirective.ngIf = this.authService.isAuthorized(handler);
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
AuthDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
585
|
-
AuthDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.10", type: AuthDirective, isStandalone: true, selector: "ng-template[odxAuth]", inputs: { authorizationHandler: ["odxAuth", "authorizationHandler"], elseTemplate: ["odxAuthElse", "elseTemplate"] }, hostDirectives: [{ directive: i1.NgIf }], ngImport: i0 });
|
|
586
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthDirective, decorators: [{
|
|
587
|
-
type: Directive,
|
|
588
|
-
args: [{
|
|
589
|
-
standalone: true,
|
|
590
|
-
selector: 'ng-template[odxAuth]',
|
|
591
|
-
hostDirectives: [NgIf],
|
|
592
|
-
}]
|
|
593
|
-
}], propDecorators: { authorizationHandler: [{
|
|
594
|
-
type: Input,
|
|
595
|
-
args: ['odxAuth']
|
|
596
|
-
}], elseTemplate: [{
|
|
597
|
-
type: Input,
|
|
598
|
-
args: ['odxAuthElse']
|
|
599
|
-
}] } });
|
|
600
|
-
|
|
601
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
602
|
-
function authGuard(authorizedHandler, redirectTo) {
|
|
603
|
-
return (_, state) => {
|
|
604
|
-
const authService = inject(AuthService);
|
|
605
|
-
const router = inject(Router, { optional: true });
|
|
606
|
-
return authService.isAuthenticated$.pipe(switchMap((isAuthenticated) => {
|
|
607
|
-
if (!isAuthenticated) {
|
|
608
|
-
authService.signIn(state.url);
|
|
609
|
-
return EMPTY;
|
|
610
|
-
}
|
|
611
|
-
return of(authService.isAuthorized(authorizedHandler));
|
|
612
|
-
}), tap((isAuthorized) => {
|
|
613
|
-
if (isAuthorized || !router)
|
|
614
|
-
return;
|
|
615
|
-
if (isString(redirectTo)) {
|
|
616
|
-
router.navigateByUrl(redirectTo);
|
|
617
|
-
}
|
|
618
|
-
else if (Array.isArray(redirectTo)) {
|
|
619
|
-
router.navigate(redirectTo);
|
|
620
|
-
}
|
|
621
|
-
}), take(1));
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
const modules = [AuthComponent, AuthDirective, SignInDirective, SignOutDirective];
|
|
626
|
-
class AuthModule {
|
|
627
|
-
}
|
|
628
|
-
AuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
629
|
-
AuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: AuthModule, imports: [AuthComponent, AuthDirective, SignInDirective, SignOutDirective], exports: [AuthComponent, AuthDirective, SignInDirective, SignOutDirective] });
|
|
630
|
-
AuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthModule, imports: [AuthComponent] });
|
|
631
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AuthModule, decorators: [{
|
|
632
|
-
type: NgModule,
|
|
633
|
-
args: [{
|
|
634
|
-
imports: [...modules],
|
|
635
|
-
exports: [...modules],
|
|
636
|
-
}]
|
|
637
|
-
}] });
|
|
638
|
-
|
|
639
|
-
const coreIdentityPlugin = () => {
|
|
640
|
-
const { resolveEmail, resolveUsername, createInitials } = injectAuthConfig();
|
|
641
|
-
return (authService) => {
|
|
642
|
-
const claims = authService.getRawIdentityClaims();
|
|
643
|
-
if (!claims)
|
|
644
|
-
return of({});
|
|
645
|
-
const username = resolveUsername(claims);
|
|
646
|
-
return of({ email: resolveEmail(claims), username, initials: createInitials(username) });
|
|
647
|
-
};
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
const userProfileUrlPlugin = () => {
|
|
651
|
-
const { environment, userProfileUrl } = injectAuthConfig();
|
|
652
|
-
return () => {
|
|
653
|
-
return of({ userProfileUrl: userProfileUrl !== null && userProfileUrl !== void 0 ? userProfileUrl : DEFAULT_USER_PROFILE_URLS[environment] });
|
|
654
|
-
};
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
function configureInterceptor() {
|
|
658
|
-
const { allowedUrls } = injectAuthConfig();
|
|
659
|
-
const urls = allowedUrls.filter(Boolean);
|
|
660
|
-
return {
|
|
661
|
-
resourceServer: {
|
|
662
|
-
customUrlValidation: (url) => urls.some((allowedUrl) => (isString(allowedUrl) ? url.startsWith(allowedUrl) : !!url.match(allowedUrl))),
|
|
663
|
-
sendAccessToken: true,
|
|
664
|
-
},
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
function initializeAuthErrorHandlers() {
|
|
668
|
-
const authService = inject(AuthService);
|
|
669
|
-
const handler = handleAuthError(inject(ODX_AUTH_ERROR_HANDLERS));
|
|
670
|
-
authService.errors$.pipe(tap((error) => handler(error))).subscribe();
|
|
671
|
-
}
|
|
672
|
-
function initalizeAuthConfig() {
|
|
673
|
-
const { clientId, scopes, redirectPath, environment, postLogoutRedirectUrl, issuer, timeoutFactor, discoveryUrl, enableLoadingScreen } = injectAuthConfig();
|
|
674
|
-
const authService = inject(AuthService);
|
|
675
|
-
const origin = inject(WindowRef).getOrigin();
|
|
676
|
-
const scope = Array.from(new Set(DEFAULT_AUTH_SCOPES.concat(scopes !== null && scopes !== void 0 ? scopes : []))).join(' ');
|
|
677
|
-
if (enableLoadingScreen) {
|
|
678
|
-
AuthLoadingScreenComponent.initialize(authService, inject(DynamicViewService));
|
|
679
|
-
}
|
|
680
|
-
return () => authService.initialize({
|
|
681
|
-
clientId,
|
|
682
|
-
issuer: issuer !== null && issuer !== void 0 ? issuer : DEFAULT_ISSUERS[environment],
|
|
683
|
-
scope,
|
|
684
|
-
redirectUri: buildUrl(origin, redirectPath),
|
|
685
|
-
postLogoutRedirectUri: postLogoutRedirectUrl,
|
|
686
|
-
preserveRequestedRoute: true,
|
|
687
|
-
strictDiscoveryDocumentValidation: !discoveryUrl,
|
|
688
|
-
responseType: 'code',
|
|
689
|
-
showDebugInformation: environment === 'dev',
|
|
690
|
-
timeoutFactor,
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
function provideAuth(config) {
|
|
694
|
-
return makeEnvironmentProviders([
|
|
695
|
-
provideAuthConfig(config),
|
|
696
|
-
provideOAuthClient(),
|
|
697
|
-
{
|
|
698
|
-
provide: OAuthModuleConfig,
|
|
699
|
-
useFactory: configureInterceptor,
|
|
700
|
-
},
|
|
701
|
-
{
|
|
702
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
703
|
-
useValue: initializeAuthErrorHandlers,
|
|
704
|
-
multi: true,
|
|
705
|
-
},
|
|
706
|
-
{
|
|
707
|
-
provide: ODX_AUTH_ERROR_HANDLERS,
|
|
708
|
-
useFactory: () => [offlineAuthErrorHandler, injectAuthConfig().errorHandler],
|
|
709
|
-
},
|
|
710
|
-
{
|
|
711
|
-
provide: APP_INITIALIZER,
|
|
712
|
-
useFactory: initalizeAuthConfig,
|
|
713
|
-
multi: true,
|
|
714
|
-
},
|
|
715
|
-
{
|
|
716
|
-
provide: OAuthStorage,
|
|
717
|
-
useFactory: () => { var _a; return (_a = injectAuthConfig().storage) !== null && _a !== void 0 ? _a : inject(WindowRef).nativeWindow.localStorage; },
|
|
718
|
-
},
|
|
719
|
-
{
|
|
720
|
-
provide: ODX_AUTH_CORE_PLUGINS,
|
|
721
|
-
useValue: [coreIdentityPlugin, userProfileUrlPlugin],
|
|
722
|
-
},
|
|
723
|
-
]);
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
727
|
-
function unauthGuard(authorizedHandler, redirectTo) {
|
|
728
|
-
return (_) => {
|
|
729
|
-
const authService = inject(AuthService);
|
|
730
|
-
const router = inject(Router, { optional: true });
|
|
731
|
-
return authService.isAuthenticated$.pipe(map(() => !authService.isAuthorized(authorizedHandler)), tap((isUnauthorized) => {
|
|
732
|
-
if (isUnauthorized || !router)
|
|
733
|
-
return;
|
|
734
|
-
if (isString(redirectTo)) {
|
|
735
|
-
router.navigateByUrl(redirectTo);
|
|
736
|
-
}
|
|
737
|
-
else if (Array.isArray(redirectTo)) {
|
|
738
|
-
router.navigate(redirectTo);
|
|
739
|
-
}
|
|
740
|
-
}), take(1));
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Generated bundle index. Do not edit.
|
|
746
|
-
*/
|
|
747
|
-
|
|
748
|
-
export { AuthActionDirective, AuthActionsComponent, AuthComponent, AuthConfig, AuthDefaultConfig, AuthDirective, AuthHttpCache, AuthLoadingScreenComponent, AuthModule, AuthPluginManager, AuthService, DEFAULT_AUTH_SCOPES, DEFAULT_ISSUERS, DEFAULT_USER_PROFILE_URLS, ODX_AUTH_CORE_PLUGINS, ODX_AUTH_ERROR_HANDLERS, ODX_AUTH_HTTP_CACHE_STORAGE, ODX_AUTH_PLUGINS, SignInDirective, SignOutDirective, authGuard, configureInterceptor, coreIdentityPlugin, createInitials, handleAuthError, handleOAuthEvent, initalizeAuthConfig, initializeAuthErrorHandlers, injectAuthConfig, offlineAuthErrorHandler, provideAuth, provideAuthConfig, resolveEmail, resolveUsername, unauthGuard, userProfileUrlPlugin };
|
|
749
|
-
//# sourceMappingURL=odx-auth.mjs.map
|