@odx/auth 1.0.3 → 3.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/README.md +27 -1
- package/esm2020/index.mjs +2 -1
- package/esm2020/lib/auth.component.mjs +6 -5
- package/esm2020/lib/auth.config.mjs +20 -4
- package/esm2020/lib/auth.directive.mjs +2 -2
- package/esm2020/lib/auth.guard.mjs +17 -6
- package/esm2020/lib/auth.providers.mjs +7 -2
- package/esm2020/lib/auth.service.mjs +29 -15
- package/esm2020/lib/auth.typings.mjs +1 -1
- package/esm2020/lib/directives/auth-action.directive.mjs +24 -0
- package/esm2020/lib/directives/index.mjs +2 -1
- package/esm2020/lib/directives/sign-in.directive.mjs +10 -15
- package/esm2020/lib/directives/sign-out.directive.mjs +10 -15
- package/esm2020/lib/helpers/create-inititals.mjs +3 -3
- package/esm2020/lib/helpers/index.mjs +3 -2
- package/esm2020/lib/helpers/resolve-email.mjs +14 -0
- package/esm2020/lib/helpers/resolve-username.mjs +14 -0
- package/esm2020/lib/models/auth-http-cache.mjs +34 -0
- package/esm2020/lib/models/auth-plugin-manager.mjs +29 -0
- package/esm2020/lib/models/authorized-handler.mjs +1 -1
- package/esm2020/lib/models/index.mjs +3 -1
- package/esm2020/lib/plugins/core-identity.plugin.mjs +13 -0
- package/esm2020/lib/plugins/index.mjs +2 -0
- package/esm2020/plugins/service-connect/index.mjs +8 -0
- package/esm2020/plugins/service-connect/lib/dtos/get-service-connect-rights-response.dto.mjs +2 -0
- package/esm2020/plugins/service-connect/lib/dtos/index.mjs +2 -0
- package/esm2020/plugins/service-connect/lib/helpers/build-service-connect-url.mjs +9 -0
- package/esm2020/plugins/service-connect/lib/helpers/has-roles-or-rights-handler.mjs +5 -0
- package/esm2020/plugins/service-connect/lib/helpers/has-roles-or-rights.mjs +5 -0
- package/esm2020/plugins/service-connect/lib/helpers/index.mjs +4 -0
- package/esm2020/plugins/service-connect/lib/service-connect-rights.directive.mjs +32 -0
- package/esm2020/plugins/service-connect/lib/service-connect-rights.guard.mjs +7 -0
- package/esm2020/plugins/service-connect/lib/service-connect-rights.plugin.mjs +29 -0
- package/esm2020/plugins/service-connect/lib/service-connect.config.mjs +14 -0
- package/esm2020/plugins/service-connect/lib/service-connect.typings.mjs +2 -0
- package/esm2020/plugins/service-connect/odx-auth-plugins-service-connect.mjs +5 -0
- package/fesm2015/odx-auth-plugins-service-connect.mjs +99 -0
- package/fesm2015/odx-auth-plugins-service-connect.mjs.map +1 -0
- package/fesm2015/odx-auth.mjs +208 -72
- package/fesm2015/odx-auth.mjs.map +1 -1
- package/fesm2020/odx-auth-plugins-service-connect.mjs +97 -0
- package/fesm2020/odx-auth-plugins-service-connect.mjs.map +1 -0
- package/fesm2020/odx-auth.mjs +201 -71
- package/fesm2020/odx-auth.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/auth.component.d.ts +1 -1
- package/lib/auth.config.d.ts +12 -3
- package/lib/auth.guard.d.ts +2 -2
- package/lib/auth.service.d.ts +11 -8
- package/lib/auth.typings.d.ts +9 -1
- package/lib/directives/auth-action.directive.d.ts +12 -0
- package/lib/directives/index.d.ts +1 -0
- package/lib/directives/sign-in.directive.d.ts +4 -6
- package/lib/directives/sign-out.directive.d.ts +4 -6
- package/lib/helpers/create-inititals.d.ts +1 -1
- package/lib/helpers/index.d.ts +2 -1
- package/lib/helpers/resolve-email.d.ts +1 -0
- package/lib/helpers/resolve-username.d.ts +1 -0
- package/lib/models/auth-http-cache.d.ts +11 -0
- package/lib/models/auth-plugin-manager.d.ts +15 -0
- package/lib/models/authorized-handler.d.ts +1 -2
- package/lib/models/index.d.ts +2 -0
- package/lib/plugins/core-identity.plugin.d.ts +11 -0
- package/lib/plugins/index.d.ts +1 -0
- package/package.json +11 -2
- package/plugins/service-connect/README.md +3 -0
- package/plugins/service-connect/index.d.ts +7 -0
- package/plugins/service-connect/lib/dtos/get-service-connect-rights-response.dto.d.ts +3 -0
- package/plugins/service-connect/lib/dtos/index.d.ts +1 -0
- package/plugins/service-connect/lib/helpers/build-service-connect-url.d.ts +3 -0
- package/plugins/service-connect/lib/helpers/has-roles-or-rights-handler.d.ts +3 -0
- package/plugins/service-connect/lib/helpers/has-roles-or-rights.d.ts +5 -0
- package/plugins/service-connect/lib/helpers/index.d.ts +3 -0
- package/plugins/service-connect/lib/service-connect-rights.directive.d.ts +9 -0
- package/plugins/service-connect/lib/service-connect-rights.guard.d.ts +3 -0
- package/plugins/service-connect/lib/service-connect-rights.plugin.d.ts +7 -0
- package/plugins/service-connect/lib/service-connect.config.d.ts +11 -0
- package/plugins/service-connect/lib/service-connect.typings.d.ts +9 -0
- package/esm2020/lib/helpers/parse-identity-claims.mjs +0 -13
- package/lib/helpers/parse-identity-claims.d.ts +0 -2
package/fesm2015/odx-auth.mjs
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, Injectable,
|
|
2
|
+
import { InjectionToken, inject, Injectable, Directive, EventEmitter, Output, HostListener, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, NgModule, EnvironmentInjector, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, APP_INITIALIZER } from '@angular/core';
|
|
3
3
|
import { WindowRef, CoreModule } from '@odx/angular';
|
|
4
4
|
import * as i3 from '@odx/angular/components/area-header';
|
|
5
5
|
import { AreaHeaderModule } from '@odx/angular/components/area-header';
|
|
6
6
|
import * as i8 from '@odx/angular/components/dropdown';
|
|
7
7
|
import { DropdownModule } from '@odx/angular/components/dropdown';
|
|
8
|
-
import * as i9 from '@odx/angular/components/header';
|
|
9
8
|
import { HeaderModule } from '@odx/angular/components/header';
|
|
9
|
+
import * as i1 from '@odx/angular/components/loading-spinner';
|
|
10
|
+
import { LoadingSpinnerDirective, LoadingSpinnerModule } from '@odx/angular/components/loading-spinner';
|
|
10
11
|
import { LogoDirective } from '@odx/angular/components/logo';
|
|
11
|
-
import {
|
|
12
|
+
import { isString, createConfigTokens, untilDestroyed, Position, buildUrl } from '@odx/angular/utils';
|
|
12
13
|
import { __awaiter } from 'tslib';
|
|
13
14
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
14
15
|
import { Router } from '@angular/router';
|
|
16
|
+
import { fromEvents } from '@odx/angular/rxjs';
|
|
15
17
|
import { OAuthService, OAuthErrorEvent, provideOAuthClient, OAuthModuleConfig, OAuthStorage } from 'angular-oauth2-oidc';
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
18
|
+
import { deepmerge } from 'deepmerge-ts';
|
|
19
|
+
import jwtDecode from 'jwt-decode';
|
|
20
|
+
import { BehaviorSubject, filter, map, distinctUntilChanged, share, of, switchMap, combineLatest, tap, take, fromEvent, startWith, shareReplay, merge } from 'rxjs';
|
|
19
21
|
import * as i1$1 from '@angular/common';
|
|
20
22
|
import { NgIf } from '@angular/common';
|
|
21
23
|
import * as i2 from '@ngrx/component';
|
|
@@ -24,12 +26,62 @@ import * as i5 from '@odx/angular/components/action-group';
|
|
|
24
26
|
import * as i6 from '@odx/angular/components/button';
|
|
25
27
|
import * as i7 from '@odx/angular/components/icon';
|
|
26
28
|
|
|
29
|
+
function createInitials(value) {
|
|
30
|
+
if (!value)
|
|
31
|
+
return '';
|
|
32
|
+
const parts = value.trim().split(' ');
|
|
33
|
+
return parts.reduce((initials, curr, index) => {
|
|
34
|
+
if (index === 0 || index === parts.length - 1) {
|
|
35
|
+
initials += curr[0].toUpperCase();
|
|
36
|
+
}
|
|
37
|
+
return initials;
|
|
38
|
+
}, '');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function resolveEmail(claims) {
|
|
42
|
+
if (isString(claims['email'])) {
|
|
43
|
+
return claims['email'];
|
|
44
|
+
}
|
|
45
|
+
if (isString(claims['email_address'])) {
|
|
46
|
+
return claims['email_address'];
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(claims['emails']) && isString(claims['emails'][0])) {
|
|
49
|
+
return claims['emails'][0];
|
|
50
|
+
}
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveUsername(claims) {
|
|
55
|
+
if (isString(claims['firstname']) && isString(claims['lastname'])) {
|
|
56
|
+
return `${claims['firstname']} ${claims['lastname']}`;
|
|
57
|
+
}
|
|
58
|
+
if (isString(claims['displayname'])) {
|
|
59
|
+
return claims['displayname'];
|
|
60
|
+
}
|
|
61
|
+
if (isString(claims['name'])) {
|
|
62
|
+
return claims['name'];
|
|
63
|
+
}
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
|
|
27
67
|
const DEFAULT_AUTH_SCOPES = ['openid', 'profile', 'email', 'offline_access'];
|
|
28
68
|
const DEFAULT_ISSUERS = {
|
|
29
69
|
dev: 'https://dev.login.draeger.com/oauth2/default',
|
|
30
70
|
stage: 'https://test.login.draeger.com/oauth2/default',
|
|
31
71
|
prod: 'https://login.draeger.com/oauth2/default',
|
|
32
72
|
};
|
|
73
|
+
const ODX_AUTH_CORE_PLUGINS = new InjectionToken('@odx/auth::CorePlugins', {
|
|
74
|
+
providedIn: 'root',
|
|
75
|
+
factory: () => [],
|
|
76
|
+
});
|
|
77
|
+
const ODX_AUTH_PLUGINS = new InjectionToken('@odx/auth::Plugins', {
|
|
78
|
+
providedIn: 'root',
|
|
79
|
+
factory: () => {
|
|
80
|
+
const { plugins } = injectAuthConfig();
|
|
81
|
+
const corePlugins = inject(ODX_AUTH_CORE_PLUGINS);
|
|
82
|
+
return [...corePlugins, ...plugins].map((pluginFactory) => pluginFactory());
|
|
83
|
+
},
|
|
84
|
+
});
|
|
33
85
|
const { AuthDefaultConfig, AuthConfig, injectAuthConfig, provideAuthConfig } = createConfigTokens('Auth', '@odx/auth', {
|
|
34
86
|
environment: 'prod',
|
|
35
87
|
redirectPath: 'login/callback',
|
|
@@ -40,55 +92,98 @@ const { AuthDefaultConfig, AuthConfig, injectAuthConfig, provideAuthConfig } = c
|
|
|
40
92
|
errorHandler: (error) => {
|
|
41
93
|
throw error;
|
|
42
94
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
95
|
+
createInitials,
|
|
96
|
+
resolveEmail,
|
|
97
|
+
resolveUsername,
|
|
98
|
+
showRedirectOverlay: false,
|
|
99
|
+
plugins: [],
|
|
46
100
|
});
|
|
47
101
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
102
|
+
const ODX_AUTH_HTTP_CACHE_STORAGE = new InjectionToken('@odx/auth::AuthHttpCacheStorage', {
|
|
103
|
+
providedIn: 'root',
|
|
104
|
+
factory: () => inject(WindowRef).nativeWindow.caches,
|
|
105
|
+
});
|
|
106
|
+
class AuthHttpCache {
|
|
107
|
+
constructor() {
|
|
108
|
+
this.cacheStorage = inject(ODX_AUTH_HTTP_CACHE_STORAGE);
|
|
109
|
+
}
|
|
110
|
+
delete(request) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const cache = yield this.cacheStorage.open(AuthHttpCache.CACHE_KEY);
|
|
113
|
+
return cache.delete(request);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
request(request) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const cache = yield this.cacheStorage.open(AuthHttpCache.CACHE_KEY);
|
|
119
|
+
try {
|
|
120
|
+
yield cache.add(request);
|
|
121
|
+
}
|
|
122
|
+
catch (_a) {
|
|
123
|
+
// ignore request errors
|
|
124
|
+
}
|
|
125
|
+
return cache.match(request, { ignoreVary: true, ignoreSearch: true }).then((res) => { var _a; return (_a = res === null || res === void 0 ? void 0 : res.json()) !== null && _a !== void 0 ? _a : null; });
|
|
126
|
+
});
|
|
127
|
+
}
|
|
58
128
|
}
|
|
129
|
+
AuthHttpCache.CACHE_KEY = '@odx/auth/http-cache';
|
|
130
|
+
AuthHttpCache.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthHttpCache, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
131
|
+
AuthHttpCache.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthHttpCache, providedIn: 'root' });
|
|
132
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthHttpCache, decorators: [{
|
|
133
|
+
type: Injectable,
|
|
134
|
+
args: [{ providedIn: 'root' }]
|
|
135
|
+
}] });
|
|
59
136
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
137
|
+
class AuthPluginManager {
|
|
138
|
+
constructor() {
|
|
139
|
+
this.plugins = inject(ODX_AUTH_PLUGINS);
|
|
140
|
+
this.result$$ = new BehaviorSubject(null);
|
|
141
|
+
this.pluginsReady$ = this.result$$.pipe(filter(Boolean), map(Boolean), distinctUntilChanged(), share());
|
|
142
|
+
this.pluginsLoading$ = this.result$$.pipe(map((result) => !result), distinctUntilChanged(), share());
|
|
143
|
+
}
|
|
144
|
+
runPlugins(authService) {
|
|
145
|
+
if (this.plugins.length < 1) {
|
|
146
|
+
return of({});
|
|
147
|
+
}
|
|
148
|
+
return authService.isInitialized$.pipe(switchMap(() => combineLatest(this.plugins.map((plugin) => plugin(authService)))), map((results) => deepmerge(...results)), tap((result) => this.result$$.next(result)), take(1));
|
|
149
|
+
}
|
|
150
|
+
getResult() {
|
|
151
|
+
var _a;
|
|
152
|
+
return (_a = this.result$$.getValue()) !== null && _a !== void 0 ? _a : {};
|
|
153
|
+
}
|
|
65
154
|
}
|
|
155
|
+
AuthPluginManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthPluginManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
156
|
+
AuthPluginManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthPluginManager, providedIn: 'root' });
|
|
157
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthPluginManager, decorators: [{
|
|
158
|
+
type: Injectable,
|
|
159
|
+
args: [{ providedIn: 'root' }]
|
|
160
|
+
}] });
|
|
66
161
|
|
|
67
162
|
class AuthService {
|
|
68
163
|
constructor() {
|
|
69
164
|
this.authConfig = injectAuthConfig();
|
|
165
|
+
this.authPluginManager = inject(AuthPluginManager);
|
|
70
166
|
this.oauthService = inject(OAuthService);
|
|
71
167
|
this.router = inject(Router);
|
|
72
168
|
this.windowRef = inject(WindowRef);
|
|
73
169
|
this.isInitialized$$ = new BehaviorSubject(false);
|
|
74
170
|
this.onAccessTokenUpdate$ = fromEvent(this.windowRef.nativeWindow, 'storage').pipe(filter(({ key }) => key === 'access_token' || key === null), startWith(null), share());
|
|
75
171
|
this.onAuthStateChange$ = combineLatest([this.oauthService.events.pipe(startWith(null)), this.windowRef.isOnline$, this.onAccessTokenUpdate$]);
|
|
76
|
-
this.
|
|
172
|
+
this.isInitialized$ = this.isInitialized$$.pipe(filter(Boolean), distinctUntilChanged());
|
|
173
|
+
this.isAuthenticated$ = this.isInitialized$.pipe(switchMap(() => this.authPluginManager.pluginsReady$), switchMap(() => this.onAuthStateChange$), map(() => this.isAuthenticated()), shareReplay({ refCount: true }));
|
|
77
174
|
this.identityClaims$ = this.isAuthenticated$.pipe(map(() => this.getIdentityClaims()), shareReplay({ refCount: true }));
|
|
78
175
|
this.errors$ = this.oauthService.events.pipe(filter((event) => event instanceof OAuthErrorEvent), share());
|
|
79
|
-
this.
|
|
80
|
-
|
|
176
|
+
this.isRedirecting$ = fromEvents(this.windowRef.nativeWindow, 'beforeunload').pipe(map(Boolean), distinctUntilChanged(), share());
|
|
177
|
+
this.isLoading$ = merge(this.isRedirecting$, this.authPluginManager.pluginsLoading$).pipe(distinctUntilChanged());
|
|
178
|
+
this.windowRef.isOnline$.subscribe((isOnline) => {
|
|
81
179
|
if (isOnline) {
|
|
82
180
|
this.oauthService.setupAutomaticSilentRefresh();
|
|
83
181
|
}
|
|
84
182
|
else {
|
|
85
183
|
this.oauthService.stopAutomaticRefresh();
|
|
86
184
|
}
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
ngOnDestroy() {
|
|
91
|
-
this.subscription.unsubscribe();
|
|
185
|
+
});
|
|
186
|
+
this.authPluginManager.runPlugins(this).subscribe();
|
|
92
187
|
}
|
|
93
188
|
initialize(config) {
|
|
94
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -147,6 +242,10 @@ class AuthService {
|
|
|
147
242
|
var _a;
|
|
148
243
|
return (_a = this.oauthService.getAccessToken()) !== null && _a !== void 0 ? _a : null;
|
|
149
244
|
}
|
|
245
|
+
getAccessTokenPayload() {
|
|
246
|
+
const token = this.getAccessToken();
|
|
247
|
+
return token ? jwtDecode(token) : null;
|
|
248
|
+
}
|
|
150
249
|
getRefreshToken() {
|
|
151
250
|
var _a;
|
|
152
251
|
return (_a = this.oauthService.getRefreshToken()) !== null && _a !== void 0 ? _a : null;
|
|
@@ -156,7 +255,14 @@ class AuthService {
|
|
|
156
255
|
return (_a = this.oauthService.getIdToken()) !== null && _a !== void 0 ? _a : null;
|
|
157
256
|
}
|
|
158
257
|
getIdentityClaims() {
|
|
159
|
-
|
|
258
|
+
if (!this.getIdToken())
|
|
259
|
+
return null;
|
|
260
|
+
return deepmerge(this.oauthService.getIdentityClaims(), this.authPluginManager.getResult());
|
|
261
|
+
}
|
|
262
|
+
getRawIdentityClaims() {
|
|
263
|
+
if (!this.getIdToken())
|
|
264
|
+
return null;
|
|
265
|
+
return this.oauthService.getIdentityClaims();
|
|
160
266
|
}
|
|
161
267
|
isAuthenticated() {
|
|
162
268
|
if (this.windowRef.isOnline()) {
|
|
@@ -170,9 +276,9 @@ class AuthService {
|
|
|
170
276
|
}
|
|
171
277
|
routeToRequestedUrl() {
|
|
172
278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
if (this.oauthService.state)
|
|
174
|
-
|
|
175
|
-
|
|
279
|
+
if (!this.oauthService.state)
|
|
280
|
+
return;
|
|
281
|
+
yield this.router.navigateByUrl(decodeURIComponent(this.oauthService.state));
|
|
176
282
|
});
|
|
177
283
|
}
|
|
178
284
|
hasValidOfflineToken() {
|
|
@@ -188,26 +294,38 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
188
294
|
args: [{ providedIn: 'root' }]
|
|
189
295
|
}], ctorParameters: function () { return []; } });
|
|
190
296
|
|
|
191
|
-
class
|
|
297
|
+
class AuthActionDirective {
|
|
192
298
|
constructor() {
|
|
193
|
-
this.
|
|
299
|
+
this.takeUntilDestroyed = untilDestroyed();
|
|
194
300
|
this.loadingSpinnerDirective = inject(LoadingSpinnerDirective, { self: true });
|
|
195
|
-
|
|
196
|
-
this.afterSignIn = new EventEmitter();
|
|
301
|
+
this.authService = inject(AuthService);
|
|
197
302
|
}
|
|
198
303
|
ngAfterViewInit() {
|
|
199
304
|
this.loadingSpinnerDirective.autoColor = true;
|
|
200
|
-
|
|
201
|
-
signIn() {
|
|
202
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
this.authService.isRedirecting$.pipe(this.takeUntilDestroyed()).subscribe(() => {
|
|
203
306
|
this.loadingSpinnerDirective.isLoading = true;
|
|
204
|
-
this.authService.signIn();
|
|
205
|
-
this.afterSignIn.emit();
|
|
206
307
|
});
|
|
207
308
|
}
|
|
208
309
|
}
|
|
209
|
-
|
|
210
|
-
|
|
310
|
+
AuthActionDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthActionDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
311
|
+
AuthActionDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: AuthActionDirective, ngImport: i0 });
|
|
312
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthActionDirective, decorators: [{
|
|
313
|
+
type: Directive
|
|
314
|
+
}] });
|
|
315
|
+
|
|
316
|
+
class SignInDirective extends AuthActionDirective {
|
|
317
|
+
constructor() {
|
|
318
|
+
super(...arguments);
|
|
319
|
+
// eslint-disable-next-line @angular-eslint/no-output-rename
|
|
320
|
+
this.afterSignIn = new EventEmitter();
|
|
321
|
+
}
|
|
322
|
+
handleClick() {
|
|
323
|
+
this.authService.signIn();
|
|
324
|
+
this.afterSignIn.next();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
SignInDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SignInDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
328
|
+
SignInDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: SignInDirective, isStandalone: true, selector: "[odxButton][odxAuthSignIn]", outputs: { afterSignIn: "odxAuthSignIn" }, host: { listeners: { "click": "handleClick()" } }, usesInheritance: true, hostDirectives: [{ directive: i1.LoadingSpinnerDirective }], ngImport: i0 });
|
|
211
329
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SignInDirective, decorators: [{
|
|
212
330
|
type: Directive,
|
|
213
331
|
args: [{
|
|
@@ -218,31 +336,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
218
336
|
}], propDecorators: { afterSignIn: [{
|
|
219
337
|
type: Output,
|
|
220
338
|
args: ['odxAuthSignIn']
|
|
221
|
-
}],
|
|
339
|
+
}], handleClick: [{
|
|
222
340
|
type: HostListener,
|
|
223
341
|
args: ['click']
|
|
224
342
|
}] } });
|
|
225
343
|
|
|
226
|
-
class SignOutDirective {
|
|
344
|
+
class SignOutDirective extends AuthActionDirective {
|
|
227
345
|
constructor() {
|
|
228
|
-
|
|
229
|
-
this.loadingSpinnerDirective = inject(LoadingSpinnerDirective, { self: true });
|
|
346
|
+
super(...arguments);
|
|
230
347
|
// eslint-disable-next-line @angular-eslint/no-output-rename
|
|
231
348
|
this.afterSignOut = new EventEmitter();
|
|
232
349
|
}
|
|
233
|
-
|
|
234
|
-
this.
|
|
235
|
-
|
|
236
|
-
signIn() {
|
|
237
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
this.loadingSpinnerDirective.isLoading = true;
|
|
239
|
-
this.authService.signOut();
|
|
240
|
-
this.afterSignOut.emit();
|
|
241
|
-
});
|
|
350
|
+
handleClick() {
|
|
351
|
+
this.authService.signOut();
|
|
352
|
+
this.afterSignOut.next();
|
|
242
353
|
}
|
|
243
354
|
}
|
|
244
|
-
SignOutDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SignOutDirective, deps:
|
|
245
|
-
SignOutDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: SignOutDirective, isStandalone: true, selector: "[odxButton][odxAuthSignOut]", outputs: { afterSignOut: "odxAuthSignOut" }, host: { listeners: { "click": "
|
|
355
|
+
SignOutDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SignOutDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
356
|
+
SignOutDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: SignOutDirective, isStandalone: true, selector: "[odxButton][odxAuthSignOut]", outputs: { afterSignOut: "odxAuthSignOut" }, host: { listeners: { "click": "handleClick()" } }, usesInheritance: true, hostDirectives: [{ directive: i1.LoadingSpinnerDirective }], ngImport: i0 });
|
|
246
357
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SignOutDirective, decorators: [{
|
|
247
358
|
type: Directive,
|
|
248
359
|
args: [{
|
|
@@ -253,15 +364,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
253
364
|
}], propDecorators: { afterSignOut: [{
|
|
254
365
|
type: Output,
|
|
255
366
|
args: ['odxAuthSignOut']
|
|
256
|
-
}],
|
|
367
|
+
}], handleClick: [{
|
|
257
368
|
type: HostListener,
|
|
258
369
|
args: ['click']
|
|
259
370
|
}] } });
|
|
260
371
|
|
|
261
372
|
class AuthComponent {
|
|
262
373
|
constructor() {
|
|
263
|
-
this.authService = inject(AuthService);
|
|
264
374
|
this.authConfig = injectAuthConfig();
|
|
375
|
+
this.authService = inject(AuthService);
|
|
265
376
|
this.dropdownOptions = {
|
|
266
377
|
position: Position.BOTTOM_END,
|
|
267
378
|
enableFallback: false,
|
|
@@ -272,10 +383,10 @@ class AuthComponent {
|
|
|
272
383
|
}
|
|
273
384
|
}
|
|
274
385
|
AuthComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
275
|
-
AuthComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: AuthComponent, isStandalone: true, selector: "odx-auth", inputs: { signInButtonText: "signInButtonText", signOutButtonText: "signOutButtonText" }, ngImport: i0, template: "<odx-action-group
|
|
386
|
+
AuthComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: AuthComponent, isStandalone: true, selector: "odx-auth", inputs: { signInButtonText: "signInButtonText", signOutButtonText: "signOutButtonText" }, 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 <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 }}\n <odx-icon name=\"arrow-right\" 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 }}\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 <ng-template [ngIf]=\"authConfig.showRedirectOverlay\">\n <div class=\"odx-auth-overlay\" [odxLoadingSpinner]=\"true\" *ngIf=\"authService.isLoading$ | async\"></div>\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-overlay{position:fixed;z-index:var(--odx-v-layer-5);inset:0}\n"], dependencies: [{ kind: "ngmodule", type: CoreModule }, { kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1$1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: i1$1.AsyncPipe, name: "async" }, { kind: "directive", type: i2.LetDirective, selector: "[ngrxLet]", inputs: ["ngrxLet", "ngrxLetSuspenseTpl"] }, { kind: "ngmodule", type: AreaHeaderModule }, { kind: "component", type: i3.AreaHeaderComponent, selector: "odx-area-header", inputs: ["size"] }, { kind: "directive", type: i3.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: i7.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: "directive", type: i1.LoadingSpinnerDirective, selector: "[odxLoadingSpinner]", inputs: ["odxLoadingSpinnerAutoColor", "odxLoadingSpinner", "odxLoadingSpinnerMinHeight"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
276
387
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AuthComponent, decorators: [{
|
|
277
388
|
type: Component,
|
|
278
|
-
args: [{ standalone: true, selector: 'odx-auth', imports: [CoreModule, AreaHeaderModule, DropdownModule, HeaderModule, LogoDirective, SignInDirective, SignOutDirective], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: "<odx-action-group
|
|
389
|
+
args: [{ standalone: true, selector: 'odx-auth', imports: [CoreModule, AreaHeaderModule, DropdownModule, HeaderModule, LogoDirective, SignInDirective, SignOutDirective, LoadingSpinnerModule], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, 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 <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 }}\n <odx-icon name=\"arrow-right\" 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 }}\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 <ng-template [ngIf]=\"authConfig.showRedirectOverlay\">\n <div class=\"odx-auth-overlay\" [odxLoadingSpinner]=\"true\" *ngIf=\"authService.isLoading$ | async\"></div>\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-overlay{position:fixed;z-index:var(--odx-v-layer-5);inset:0}\n"] }]
|
|
279
390
|
}], propDecorators: { signInButtonText: [{
|
|
280
391
|
type: Input
|
|
281
392
|
}], signOutButtonText: [{
|
|
@@ -294,7 +405,7 @@ class AuthDirective {
|
|
|
294
405
|
this.ngIfDirective.ngIfElse = value;
|
|
295
406
|
}
|
|
296
407
|
ngAfterViewInit() {
|
|
297
|
-
this.authService.
|
|
408
|
+
this.authService.identityClaims$.pipe(this.takeUntilDestroyed()).subscribe(() => {
|
|
298
409
|
const handler = isString(this.authorizationHandler) ? null : this.authorizationHandler;
|
|
299
410
|
this.ngIfDirective.ngIf = this.authService.isAuthorized(handler);
|
|
300
411
|
});
|
|
@@ -317,17 +428,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
317
428
|
args: ['odxAuthElse']
|
|
318
429
|
}] } });
|
|
319
430
|
|
|
320
|
-
|
|
431
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
432
|
+
function authGuard(authorizedHandler, redirectTo) {
|
|
321
433
|
return (_, state) => {
|
|
322
434
|
const authService = inject(AuthService);
|
|
323
|
-
const router = inject(Router);
|
|
324
|
-
const isAuthorized = () => authorizedHandler === null || authorizedHandler === void 0 ? void 0 : authorizedHandler(authService.getIdentityClaims(), router, authService);
|
|
435
|
+
const router = inject(Router, { optional: true });
|
|
325
436
|
return authService.isAuthenticated$.pipe(map((isAuthenticated) => {
|
|
326
437
|
var _a;
|
|
327
438
|
if (!isAuthenticated) {
|
|
328
439
|
authService.signIn(state.url);
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
return (_a = authorizedHandler === null || authorizedHandler === void 0 ? void 0 : authorizedHandler(authService.getIdentityClaims(), authService, router)) !== null && _a !== void 0 ? _a : isAuthenticated;
|
|
443
|
+
}), tap((isAuthorized) => {
|
|
444
|
+
if (isAuthorized || !router)
|
|
445
|
+
return;
|
|
446
|
+
if (isString(redirectTo)) {
|
|
447
|
+
router.navigateByUrl(redirectTo);
|
|
448
|
+
}
|
|
449
|
+
else if (Array.isArray(redirectTo)) {
|
|
450
|
+
router.navigate(redirectTo);
|
|
329
451
|
}
|
|
330
|
-
return (_a = isAuthorized()) !== null && _a !== void 0 ? _a : isAuthenticated;
|
|
331
452
|
}), take(1));
|
|
332
453
|
};
|
|
333
454
|
}
|
|
@@ -346,6 +467,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
346
467
|
}]
|
|
347
468
|
}] });
|
|
348
469
|
|
|
470
|
+
const coreIdentityPlugin = () => {
|
|
471
|
+
const { resolveEmail, resolveUsername, createInitials } = injectAuthConfig();
|
|
472
|
+
return (authService) => {
|
|
473
|
+
const claims = authService.getRawIdentityClaims();
|
|
474
|
+
if (!claims)
|
|
475
|
+
return of({});
|
|
476
|
+
const username = resolveUsername(claims);
|
|
477
|
+
return of({ email: resolveEmail(claims), username, initials: createInitials(username) });
|
|
478
|
+
};
|
|
479
|
+
};
|
|
480
|
+
|
|
349
481
|
function configureInterceptor() {
|
|
350
482
|
const { allowedUrls } = injectAuthConfig();
|
|
351
483
|
return {
|
|
@@ -401,6 +533,10 @@ function provideAuth(config) {
|
|
|
401
533
|
provide: OAuthStorage,
|
|
402
534
|
useFactory: () => { var _a; return (_a = inject(AuthConfig).storage) !== null && _a !== void 0 ? _a : inject(WindowRef).nativeWindow.localStorage; },
|
|
403
535
|
},
|
|
536
|
+
{
|
|
537
|
+
provide: ODX_AUTH_CORE_PLUGINS,
|
|
538
|
+
useValue: [coreIdentityPlugin],
|
|
539
|
+
},
|
|
404
540
|
]);
|
|
405
541
|
}
|
|
406
542
|
|
|
@@ -408,5 +544,5 @@ function provideAuth(config) {
|
|
|
408
544
|
* Generated bundle index. Do not edit.
|
|
409
545
|
*/
|
|
410
546
|
|
|
411
|
-
export { AuthComponent, AuthConfig, AuthDefaultConfig, AuthDirective, AuthModule, AuthService, DEFAULT_AUTH_SCOPES, DEFAULT_ISSUERS, SignInDirective, SignOutDirective, authGuard, configureInterceptor,
|
|
547
|
+
export { AuthActionDirective, AuthComponent, AuthConfig, AuthDefaultConfig, AuthDirective, AuthHttpCache, AuthModule, AuthPluginManager, AuthService, DEFAULT_AUTH_SCOPES, DEFAULT_ISSUERS, ODX_AUTH_CORE_PLUGINS, ODX_AUTH_HTTP_CACHE_STORAGE, ODX_AUTH_PLUGINS, SignInDirective, SignOutDirective, authGuard, configureInterceptor, coreIdentityPlugin, createInitials, initalizeAuthConfig, initializeAuthErrorHandler, injectAuthConfig, provideAuth, provideAuthConfig, resolveEmail, resolveUsername };
|
|
412
548
|
//# sourceMappingURL=odx-auth.mjs.map
|