@odx/auth 1.0.0-alpha.1 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/index.mjs +6 -3
- package/esm2020/lib/auth-error-handler.mjs +20 -0
- package/esm2020/lib/auth.component.mjs +13 -21
- package/esm2020/lib/auth.config.mjs +11 -3
- package/esm2020/lib/auth.directive.mjs +41 -0
- package/esm2020/lib/auth.guard.mjs +18 -0
- package/esm2020/lib/auth.module.mjs +10 -12
- package/esm2020/lib/auth.providers.mjs +53 -42
- package/esm2020/lib/auth.service.mjs +87 -21
- package/esm2020/lib/auth.typings.mjs +2 -0
- package/esm2020/lib/directives/sign-in.directive.mjs +6 -6
- package/esm2020/lib/directives/sign-out.directive.mjs +6 -6
- package/esm2020/lib/helpers/create-inititals.mjs +12 -0
- package/esm2020/lib/helpers/index.mjs +3 -3
- package/esm2020/lib/helpers/parse-identity-claims.mjs +10 -0
- package/esm2020/lib/models/authorized-handler.mjs +2 -0
- package/esm2020/lib/models/index.mjs +2 -2
- package/fesm2015/odx-auth.mjs +255 -134
- package/fesm2015/odx-auth.mjs.map +1 -1
- package/fesm2020/odx-auth.mjs +252 -135
- package/fesm2020/odx-auth.mjs.map +1 -1
- package/index.d.ts +5 -2
- package/lib/auth-error-handler.d.ts +12 -0
- package/lib/auth.component.d.ts +2 -3
- package/lib/auth.config.d.ts +11 -6
- package/lib/auth.directive.d.ts +15 -0
- package/lib/auth.guard.d.ts +3 -0
- package/lib/auth.module.d.ts +4 -4
- package/lib/auth.providers.d.ts +9 -6
- package/lib/auth.service.d.ts +27 -11
- package/lib/auth.typings.d.ts +19 -0
- package/lib/directives/sign-in.directive.d.ts +3 -3
- package/lib/directives/sign-out.directive.d.ts +3 -3
- package/lib/helpers/create-inititals.d.ts +1 -0
- package/lib/helpers/index.d.ts +2 -2
- package/lib/helpers/parse-identity-claims.d.ts +1 -0
- package/lib/models/auth-environment.d.ts +1 -1
- package/lib/models/authorized-handler.d.ts +4 -0
- package/lib/models/index.d.ts +1 -1
- package/package.json +3 -4
- package/esm2020/lib/auth.interceptor.mjs +0 -25
- package/esm2020/lib/helpers/get-user-initials.mjs +0 -12
- package/esm2020/lib/helpers/resolve-issuer.mjs +0 -13
- package/esm2020/lib/models/user.mjs +0 -2
- package/lib/auth.interceptor.d.ts +0 -11
- package/lib/helpers/get-user-initials.d.ts +0 -2
- package/lib/helpers/resolve-issuer.d.ts +0 -2
- package/lib/models/user.d.ts +0 -4
package/fesm2015/odx-auth.mjs
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { OKTA_AUTH, OktaAuthStateService, OktaCallbackComponent, OKTA_CONFIG, OktaAuthModule } from '@okta/okta-angular';
|
|
2
|
-
export { OktaAuthGuard as AuthGuard } from '@okta/okta-angular';
|
|
3
|
-
import { __awaiter, __decorate, __metadata } from 'tslib';
|
|
4
1
|
import * as i0 from '@angular/core';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { CoreModule, WindowRef } from '@odx/angular';
|
|
2
|
+
import { Injectable, inject, EventEmitter, Directive, Output, HostListener, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, makeEnvironmentProviders, APP_INITIALIZER, NgModule } from '@angular/core';
|
|
3
|
+
import { WindowRef, CoreModule } from '@odx/angular';
|
|
8
4
|
import * as i3 from '@odx/angular/components/area-header';
|
|
9
5
|
import { AreaHeaderModule } from '@odx/angular/components/area-header';
|
|
10
6
|
import * as i8 from '@odx/angular/components/dropdown';
|
|
@@ -12,64 +8,176 @@ import { DropdownModule } from '@odx/angular/components/dropdown';
|
|
|
12
8
|
import * as i9 from '@odx/angular/components/header';
|
|
13
9
|
import { HeaderModule } from '@odx/angular/components/header';
|
|
14
10
|
import { LogoDirective } from '@odx/angular/components/logo';
|
|
15
|
-
import { createModuleConfigTokens,
|
|
16
|
-
import {
|
|
11
|
+
import { createModuleConfigTokens, Position, untilDestroyed, isString, buildUrl, provideModuleConfig } from '@odx/angular/utils';
|
|
12
|
+
import { __awaiter } from 'tslib';
|
|
13
|
+
import { Router } from '@angular/router';
|
|
14
|
+
import { OAuthService, OAuthErrorEvent, provideOAuthClient, OAuthModuleConfig, OAuthStorage } from 'angular-oauth2-oidc';
|
|
15
|
+
import { BehaviorSubject, fromEvent, filter, startWith, share, combineLatest, switchMap, map, distinctUntilChanged, shareReplay, merge, tap, take } from 'rxjs';
|
|
17
16
|
import * as i1 from '@odx/angular/components/loading-spinner';
|
|
18
17
|
import { LoadingSpinnerDirective } from '@odx/angular/components/loading-spinner';
|
|
19
18
|
import * as i1$1 from '@angular/common';
|
|
19
|
+
import { NgIf } from '@angular/common';
|
|
20
|
+
import * as i2 from '@ngrx/component';
|
|
20
21
|
import * as i4 from '@odx/angular/components/avatar';
|
|
21
22
|
import * as i5 from '@odx/angular/components/action-group';
|
|
22
23
|
import * as i6 from '@odx/angular/components/button';
|
|
23
24
|
import * as i7 from '@odx/angular/components/icon';
|
|
24
|
-
import { HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
25
|
-
import { Router } from '@angular/router';
|
|
26
|
-
import { OktaAuth } from '@okta/okta-auth-js';
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
class AuthErrorHandler {
|
|
27
|
+
}
|
|
28
|
+
AuthErrorHandler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthErrorHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
29
|
+
AuthErrorHandler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthErrorHandler });
|
|
30
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthErrorHandler, decorators: [{
|
|
31
|
+
type: Injectable
|
|
32
|
+
}] });
|
|
33
|
+
class NoopAuthErrorHandler extends AuthErrorHandler {
|
|
34
|
+
handleError(error) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
NoopAuthErrorHandler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: NoopAuthErrorHandler, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
39
|
+
NoopAuthErrorHandler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: NoopAuthErrorHandler });
|
|
40
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: NoopAuthErrorHandler, decorators: [{
|
|
41
|
+
type: Injectable
|
|
42
|
+
}] });
|
|
43
|
+
|
|
44
|
+
const DEFAULT_AUTH_SCOPES = ['openid', 'profile', 'email', 'offline_access'];
|
|
45
|
+
const DEFAULT_ISSUERS = {
|
|
46
|
+
dev: 'https://dev.login.draeger.com/oauth2/default',
|
|
47
|
+
stage: 'https://test.login.draeger.com/oauth2/default',
|
|
48
|
+
prod: 'https://login.draeger.com/oauth2/default',
|
|
49
|
+
};
|
|
29
50
|
const { AuthDefaultModuleConfig, AuthModuleConfig, injectAuthModuleConfig } = createModuleConfigTokens('Auth', '@odx/auth', {
|
|
30
51
|
environment: 'prod',
|
|
31
52
|
redirectPath: 'login/callback',
|
|
32
|
-
|
|
53
|
+
allowedUrls: [],
|
|
54
|
+
timeoutFactor: 0.75,
|
|
55
|
+
maxOfflineTime: 24 * 60 * 60,
|
|
56
|
+
loadUserProfile: false,
|
|
33
57
|
});
|
|
34
58
|
|
|
59
|
+
function createInititals(value) {
|
|
60
|
+
if (!value)
|
|
61
|
+
return '';
|
|
62
|
+
const parts = value.trim().split(' ');
|
|
63
|
+
return parts.reduce((initials, curr, index) => {
|
|
64
|
+
if (index === 0 || index === parts.length - 1) {
|
|
65
|
+
initials = `${initials}${curr.charAt(0).toUpperCase()}`;
|
|
66
|
+
}
|
|
67
|
+
return initials;
|
|
68
|
+
}, '');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
+
function parseIdentityClaims(identityClaims) {
|
|
73
|
+
var _a, _b, _c;
|
|
74
|
+
return Object.assign(Object.assign({}, identityClaims), { email: (_b = (_a = identityClaims === null || identityClaims === void 0 ? void 0 : identityClaims.email) !== null && _a !== void 0 ? _a : identityClaims.email_address) !== null && _b !== void 0 ? _b : (_c = identityClaims.emails) === null || _c === void 0 ? void 0 : _c[0], initials: createInititals(identityClaims.name) });
|
|
75
|
+
}
|
|
76
|
+
|
|
35
77
|
class AuthService {
|
|
36
78
|
constructor() {
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
79
|
+
this.authConfig = injectAuthModuleConfig();
|
|
80
|
+
this.errorHandler = inject(AuthErrorHandler);
|
|
81
|
+
this.oauthService = inject(OAuthService);
|
|
82
|
+
this.router = inject(Router);
|
|
83
|
+
this.windowRef = inject(WindowRef);
|
|
84
|
+
this.isInitialized$$ = new BehaviorSubject(false);
|
|
85
|
+
this.onAccessTokenUpdate$ = fromEvent(this.windowRef.nativeWindow, 'storage').pipe(filter(({ key }) => key === 'access_token' || key === null), startWith(null), share());
|
|
86
|
+
this.onAuthStateChange$ = combineLatest([this.oauthService.events.pipe(startWith(null)), this.windowRef.isOnline$, this.onAccessTokenUpdate$]);
|
|
87
|
+
this.isAuthenticated$ = this.isInitialized$$.pipe(filter(Boolean), switchMap(() => this.onAuthStateChange$), map(() => this.isAuthenticated()), distinctUntilChanged(), shareReplay({ refCount: true }));
|
|
88
|
+
this.identityClaims$ = this.isAuthenticated$.pipe(map(() => this.getIdentityClaims()), shareReplay({ refCount: true }));
|
|
89
|
+
this.errors$ = this.oauthService.events.pipe(filter((event) => event instanceof OAuthErrorEvent), share());
|
|
90
|
+
this.subscription = merge(this.errors$.pipe(tap((error) => {
|
|
91
|
+
this.errorHandler.handleError(error);
|
|
92
|
+
})), this.windowRef.isOnline$.pipe(tap((isOnline) => {
|
|
93
|
+
if (isOnline) {
|
|
94
|
+
this.oauthService.setupAutomaticSilentRefresh();
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.oauthService.stopAutomaticRefresh();
|
|
98
|
+
}
|
|
99
|
+
}))).subscribe();
|
|
41
100
|
}
|
|
42
|
-
|
|
101
|
+
ngOnDestroy() {
|
|
102
|
+
this.subscription.unsubscribe();
|
|
103
|
+
}
|
|
104
|
+
initialize(config) {
|
|
43
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
|
|
106
|
+
this.oauthService.configure(config);
|
|
107
|
+
try {
|
|
108
|
+
yield this.oauthService.loadDiscoveryDocument(this.authConfig.discoveryUrl);
|
|
109
|
+
yield this.oauthService.tryLoginCodeFlow();
|
|
110
|
+
if (this.getRefreshToken() && !this.isAuthenticated()) {
|
|
111
|
+
yield this.oauthService.refreshToken();
|
|
112
|
+
}
|
|
113
|
+
this.isInitialized$$.next(true);
|
|
114
|
+
if (this.authConfig.loadUserProfile && this.oauthService.hasValidAccessToken()) {
|
|
115
|
+
yield this.loadUserProfile();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (_a) {
|
|
119
|
+
// ignore errors
|
|
120
|
+
}
|
|
121
|
+
if (this.oauthService.hasValidAccessToken()) {
|
|
122
|
+
yield this.routeToRequestedUrl();
|
|
123
|
+
}
|
|
45
124
|
});
|
|
46
125
|
}
|
|
126
|
+
signIn(url) {
|
|
127
|
+
this.oauthService.initCodeFlow(url);
|
|
128
|
+
}
|
|
47
129
|
signOut() {
|
|
130
|
+
this.oauthService.logOut(!this.getAccessToken());
|
|
131
|
+
}
|
|
132
|
+
loadUserProfile() {
|
|
48
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
yield this.
|
|
134
|
+
yield this.oauthService.loadUserProfile();
|
|
50
135
|
});
|
|
51
136
|
}
|
|
52
137
|
getAccessToken() {
|
|
53
138
|
var _a;
|
|
54
|
-
return (_a = this.
|
|
139
|
+
return (_a = this.oauthService.getAccessToken()) !== null && _a !== void 0 ? _a : null;
|
|
55
140
|
}
|
|
56
141
|
getRefreshToken() {
|
|
57
142
|
var _a;
|
|
58
|
-
return (_a = this.
|
|
143
|
+
return (_a = this.oauthService.getRefreshToken()) !== null && _a !== void 0 ? _a : null;
|
|
59
144
|
}
|
|
60
|
-
|
|
61
|
-
|
|
145
|
+
getIdToken() {
|
|
146
|
+
var _a;
|
|
147
|
+
return (_a = this.oauthService.getIdToken()) !== null && _a !== void 0 ? _a : null;
|
|
62
148
|
}
|
|
63
|
-
|
|
64
|
-
return this.
|
|
149
|
+
getIdentityClaims() {
|
|
150
|
+
return this.getIdToken() ? parseIdentityClaims(this.oauthService.getIdentityClaims()) : null;
|
|
151
|
+
}
|
|
152
|
+
isAuthenticated() {
|
|
153
|
+
if (this.windowRef.isOnline()) {
|
|
154
|
+
return this.oauthService.hasValidAccessToken() && this.oauthService.hasValidIdToken();
|
|
155
|
+
}
|
|
156
|
+
return this.hasValidOfflineToken();
|
|
157
|
+
}
|
|
158
|
+
isAuthorized(authorizedHandler) {
|
|
159
|
+
var _a;
|
|
160
|
+
return this.isAuthenticated() && ((_a = authorizedHandler === null || authorizedHandler === void 0 ? void 0 : authorizedHandler(this.getIdentityClaims(), this)) !== null && _a !== void 0 ? _a : true);
|
|
161
|
+
}
|
|
162
|
+
routeToRequestedUrl() {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
if (this.oauthService.state) {
|
|
165
|
+
yield this.router.navigateByUrl(decodeURIComponent(this.oauthService.state));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
hasValidOfflineToken() {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
const issuedAt = (_b = (_a = this.getIdentityClaims()) === null || _a === void 0 ? void 0 : _a.iat) !== null && _b !== void 0 ? _b : 0;
|
|
172
|
+
return Date.now() - issuedAt * 1000 <= this.authConfig.maxOfflineTime * 1000;
|
|
65
173
|
}
|
|
66
174
|
}
|
|
67
|
-
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
68
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.
|
|
69
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
175
|
+
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
176
|
+
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
177
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthService, decorators: [{
|
|
70
178
|
type: Injectable,
|
|
71
179
|
args: [{ providedIn: 'root' }]
|
|
72
|
-
}] });
|
|
180
|
+
}], ctorParameters: function () { return []; } });
|
|
73
181
|
|
|
74
182
|
class SignInDirective {
|
|
75
183
|
constructor() {
|
|
@@ -78,20 +186,20 @@ class SignInDirective {
|
|
|
78
186
|
// eslint-disable-next-line @angular-eslint/no-output-rename
|
|
79
187
|
this.afterSignIn = new EventEmitter();
|
|
80
188
|
}
|
|
81
|
-
|
|
189
|
+
ngAfterViewInit() {
|
|
82
190
|
this.loadingSpinnerDirective.autoColor = true;
|
|
83
191
|
}
|
|
84
192
|
signIn() {
|
|
85
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
194
|
this.loadingSpinnerDirective.isLoading = true;
|
|
87
|
-
|
|
195
|
+
this.authService.signIn();
|
|
88
196
|
this.afterSignIn.emit();
|
|
89
197
|
});
|
|
90
198
|
}
|
|
91
199
|
}
|
|
92
|
-
SignInDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
93
|
-
SignInDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
94
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
200
|
+
SignInDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: SignInDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
201
|
+
SignInDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.1", type: SignInDirective, isStandalone: true, selector: "[odxButton][odxAuthSignIn]", outputs: { afterSignIn: "odxAuthSignIn" }, host: { listeners: { "click": "signIn()" } }, hostDirectives: [{ directive: i1.LoadingSpinnerDirective }], ngImport: i0 });
|
|
202
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: SignInDirective, decorators: [{
|
|
95
203
|
type: Directive,
|
|
96
204
|
args: [{
|
|
97
205
|
standalone: true,
|
|
@@ -113,20 +221,20 @@ class SignOutDirective {
|
|
|
113
221
|
// eslint-disable-next-line @angular-eslint/no-output-rename
|
|
114
222
|
this.afterSignOut = new EventEmitter();
|
|
115
223
|
}
|
|
116
|
-
|
|
224
|
+
ngAfterViewInit() {
|
|
117
225
|
this.loadingSpinnerDirective.autoColor = true;
|
|
118
226
|
}
|
|
119
227
|
signIn() {
|
|
120
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
229
|
this.loadingSpinnerDirective.isLoading = true;
|
|
122
|
-
|
|
230
|
+
this.authService.signOut();
|
|
123
231
|
this.afterSignOut.emit();
|
|
124
232
|
});
|
|
125
233
|
}
|
|
126
234
|
}
|
|
127
|
-
SignOutDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
128
|
-
SignOutDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
129
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
235
|
+
SignOutDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: SignOutDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
236
|
+
SignOutDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.1", type: SignOutDirective, isStandalone: true, selector: "[odxButton][odxAuthSignOut]", outputs: { afterSignOut: "odxAuthSignOut" }, host: { listeners: { "click": "signIn()" } }, hostDirectives: [{ directive: i1.LoadingSpinnerDirective }], ngImport: i0 });
|
|
237
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: SignOutDirective, decorators: [{
|
|
130
238
|
type: Directive,
|
|
131
239
|
args: [{
|
|
132
240
|
standalone: true,
|
|
@@ -141,137 +249,150 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.0", ngImpor
|
|
|
141
249
|
args: ['click']
|
|
142
250
|
}] } });
|
|
143
251
|
|
|
144
|
-
function getUserInitials(user) {
|
|
145
|
-
if (!(user === null || user === void 0 ? void 0 : user.name))
|
|
146
|
-
return '';
|
|
147
|
-
const names = user.name.trim().split(' ');
|
|
148
|
-
return names.reduce((initials, curr, index) => {
|
|
149
|
-
if (index === 0 || index === names.length - 1) {
|
|
150
|
-
initials = `${initials}${curr.charAt(0).toUpperCase()}`;
|
|
151
|
-
}
|
|
152
|
-
return initials;
|
|
153
|
-
}, '');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function resolveIssuer(environment, issuerOverride) {
|
|
157
|
-
if (issuerOverride)
|
|
158
|
-
return issuerOverride;
|
|
159
|
-
switch (environment) {
|
|
160
|
-
case 'dev':
|
|
161
|
-
return 'https://dev.login.draeger.com/oauth2/default';
|
|
162
|
-
case 'stage':
|
|
163
|
-
return 'https://test.login.draeger.com/oauth2/default';
|
|
164
|
-
default:
|
|
165
|
-
return 'https://login.draeger.com/oauth2/default';
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
252
|
class AuthComponent {
|
|
170
253
|
constructor() {
|
|
171
|
-
this.config = injectAuthModuleConfig();
|
|
172
254
|
this.authService = inject(AuthService);
|
|
255
|
+
this.dropdownOptions = {
|
|
256
|
+
position: Position.BOTTOM_END,
|
|
257
|
+
enableFallback: false,
|
|
258
|
+
containerClass: 'odx-auth-user-profile',
|
|
259
|
+
};
|
|
173
260
|
this.signInButtonText = 'Sign in';
|
|
174
261
|
this.signOutButtonText = 'Sign out';
|
|
175
262
|
}
|
|
176
|
-
getInitials(user) {
|
|
177
|
-
return getUserInitials(user);
|
|
178
|
-
}
|
|
179
263
|
}
|
|
180
|
-
AuthComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
181
|
-
AuthComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.
|
|
182
|
-
|
|
183
|
-
Pure,
|
|
184
|
-
__metadata("design:type", Function),
|
|
185
|
-
__metadata("design:paramtypes", [Object]),
|
|
186
|
-
__metadata("design:returntype", String)
|
|
187
|
-
], AuthComponent.prototype, "getInitials", null);
|
|
188
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.0", ngImport: i0, type: AuthComponent, decorators: [{
|
|
264
|
+
AuthComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
265
|
+
AuthComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.1", type: AuthComponent, isStandalone: true, selector: "odx-auth", inputs: { signInButtonText: "signInButtonText", signOutButtonText: "signOutButtonText" }, ngImport: i0, template: "<odx-action-group *ngrxLet=\"{ idClaims: authService.identityClaims$, isAuthenticated: authService.isAuthenticated$ } as vm\">\n <ng-template [ngIf]=\"vm.isAuthenticated\" [ngIfElse]=\"notAuthenticated\">\n <button odxButton odxHeaderAvatar [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?.name }}\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=\"primary\" 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</odx-action-group>\n", styles: [".odx-auth-user-profile .odx-dropdown__inner>.odx-area-header{max-width:max(360px,25vw);min-width:296px}\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: "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"] }, { kind: "ngmodule", type: DropdownModule }, { kind: "directive", type: i8.DropdownDirective, selector: "[odxDropdown]", inputs: ["odxDropdown", "odxDropdownDisabled", "odxDropdownShowLoader", "odxDropdownOptions", "odxDropdownReferenceElement", "odxDropdownTriggerElement", "odxDropdownHost", "odxDropdownOpenTrigger", "odxDropdownCloseTrigger"], outputs: ["odxDropdownBeforeOpen", "odxDropdownAfterOpen", "odxDropdownBeforeClose", "odxDropdownAfterClose"], exportAs: ["odxDropdown"] }, { kind: "ngmodule", type: HeaderModule }, { kind: "directive", type: i9.HeaderAvatarDirective, selector: "button[odxButton][odxHeaderAvatar]" }, { 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"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
266
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthComponent, decorators: [{
|
|
189
267
|
type: Component,
|
|
190
|
-
args: [{ standalone: true, selector: 'odx-auth', imports: [CoreModule, AreaHeaderModule, DropdownModule, HeaderModule, LogoDirective, SignInDirective, SignOutDirective], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: "<odx-action-group *
|
|
268
|
+
args: [{ standalone: true, selector: 'odx-auth', imports: [CoreModule, AreaHeaderModule, DropdownModule, HeaderModule, LogoDirective, SignInDirective, SignOutDirective], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: "<odx-action-group *ngrxLet=\"{ idClaims: authService.identityClaims$, isAuthenticated: authService.isAuthenticated$ } as vm\">\n <ng-template [ngIf]=\"vm.isAuthenticated\" [ngIfElse]=\"notAuthenticated\">\n <button odxButton odxHeaderAvatar [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?.name }}\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=\"primary\" 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</odx-action-group>\n", styles: [".odx-auth-user-profile .odx-dropdown__inner>.odx-area-header{max-width:max(360px,25vw);min-width:296px}\n"] }]
|
|
191
269
|
}], propDecorators: { signInButtonText: [{
|
|
192
270
|
type: Input
|
|
193
271
|
}], signOutButtonText: [{
|
|
194
272
|
type: Input
|
|
195
|
-
}]
|
|
273
|
+
}] } });
|
|
196
274
|
|
|
197
|
-
class
|
|
275
|
+
class AuthDirective {
|
|
198
276
|
constructor() {
|
|
199
|
-
this.config = injectAuthModuleConfig();
|
|
200
277
|
this.authService = inject(AuthService);
|
|
278
|
+
this.ngIfDirective = inject(NgIf, { host: true });
|
|
279
|
+
this.takeUntilDestroyed = untilDestroyed();
|
|
280
|
+
this.authorizationHandler = null;
|
|
201
281
|
}
|
|
202
|
-
|
|
203
|
-
|
|
282
|
+
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
283
|
+
set elseTemplate(value) {
|
|
284
|
+
this.ngIfDirective.ngIfElse = value;
|
|
204
285
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
286
|
+
ngAfterViewInit() {
|
|
287
|
+
this.authService.isAuthenticated$.pipe(this.takeUntilDestroyed()).subscribe(() => {
|
|
288
|
+
const handler = isString(this.authorizationHandler) ? null : this.authorizationHandler;
|
|
289
|
+
this.ngIfDirective.ngIf = this.authService.isAuthorized(handler);
|
|
290
|
+
});
|
|
210
291
|
}
|
|
211
292
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
215
|
-
type:
|
|
216
|
-
|
|
293
|
+
AuthDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
294
|
+
AuthDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.1", type: AuthDirective, isStandalone: true, selector: "ng-template[odxAuth]", inputs: { authorizationHandler: ["odxAuth", "authorizationHandler"], elseTemplate: ["odxAuthElse", "elseTemplate"] }, hostDirectives: [{ directive: i1$1.NgIf }], ngImport: i0 });
|
|
295
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthDirective, decorators: [{
|
|
296
|
+
type: Directive,
|
|
297
|
+
args: [{
|
|
298
|
+
standalone: true,
|
|
299
|
+
selector: 'ng-template[odxAuth]',
|
|
300
|
+
hostDirectives: [NgIf],
|
|
301
|
+
}]
|
|
302
|
+
}], propDecorators: { authorizationHandler: [{
|
|
303
|
+
type: Input,
|
|
304
|
+
args: ['odxAuth']
|
|
305
|
+
}], elseTemplate: [{
|
|
306
|
+
type: Input,
|
|
307
|
+
args: ['odxAuthElse']
|
|
308
|
+
}] } });
|
|
217
309
|
|
|
218
|
-
function
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
310
|
+
function authGuard(authorizedHandler) {
|
|
311
|
+
return (_, state) => {
|
|
312
|
+
const authService = inject(AuthService);
|
|
313
|
+
const router = inject(Router);
|
|
314
|
+
const isAuthorized = () => authorizedHandler === null || authorizedHandler === void 0 ? void 0 : authorizedHandler(authService.getIdentityClaims(), router, authService);
|
|
315
|
+
return authService.isAuthenticated$.pipe(map((isAuthenticated) => {
|
|
316
|
+
var _a;
|
|
317
|
+
if (!isAuthenticated) {
|
|
318
|
+
authService.signIn(state.url);
|
|
319
|
+
}
|
|
320
|
+
return (_a = isAuthorized()) !== null && _a !== void 0 ? _a : isAuthenticated;
|
|
321
|
+
}), take(1));
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function configureInterceptor() {
|
|
326
|
+
const { allowedUrls } = injectAuthModuleConfig();
|
|
327
|
+
return {
|
|
328
|
+
resourceServer: {
|
|
329
|
+
customUrlValidation: (url) => allowedUrls.some((allowedUrl) => !!url.match(allowedUrl)),
|
|
330
|
+
sendAccessToken: true,
|
|
331
|
+
},
|
|
223
332
|
};
|
|
224
333
|
}
|
|
225
334
|
function initalizeAuthConfig() {
|
|
226
|
-
const { clientId, scopes, redirectPath, environment,
|
|
335
|
+
const { clientId, scopes, redirectPath, environment, postLogoutRedirectUrl, issuer, timeoutFactor, discoveryUrl } = injectAuthModuleConfig();
|
|
336
|
+
const authService = inject(AuthService);
|
|
227
337
|
const origin = inject(WindowRef).getOrigin();
|
|
228
|
-
const
|
|
338
|
+
const scope = Array.from(new Set(DEFAULT_AUTH_SCOPES.concat(scopes !== null && scopes !== void 0 ? scopes : []))).join(' ');
|
|
339
|
+
return () => authService.initialize({
|
|
340
|
+
clientId,
|
|
341
|
+
issuer: issuer !== null && issuer !== void 0 ? issuer : DEFAULT_ISSUERS[environment],
|
|
342
|
+
scope,
|
|
343
|
+
redirectUri: buildUrl(origin, redirectPath),
|
|
344
|
+
postLogoutRedirectUri: postLogoutRedirectUrl,
|
|
345
|
+
preserveRequestedRoute: true,
|
|
346
|
+
strictDiscoveryDocumentValidation: !discoveryUrl,
|
|
347
|
+
responseType: 'code',
|
|
348
|
+
showDebugInformation: environment === 'dev',
|
|
349
|
+
timeoutFactor,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
function provideAuthErrorHandler(errorHandler) {
|
|
229
353
|
return {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
clientId,
|
|
233
|
-
redirectUri: buildUrl(origin, redirectPath),
|
|
234
|
-
scopes: Array.from(new Set(DEFAULT_AUTH_SCOPES.concat(scopes !== null && scopes !== void 0 ? scopes : []))),
|
|
235
|
-
pkce: true,
|
|
236
|
-
devMode: environment === 'dev',
|
|
237
|
-
postLogoutRedirectUri,
|
|
238
|
-
}),
|
|
354
|
+
provide: AuthErrorHandler,
|
|
355
|
+
useClass: errorHandler,
|
|
239
356
|
};
|
|
240
357
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
358
|
+
function provideAuth(config) {
|
|
359
|
+
return makeEnvironmentProviders([
|
|
360
|
+
provideModuleConfig(AuthModuleConfig, config),
|
|
361
|
+
provideOAuthClient(),
|
|
362
|
+
provideAuthErrorHandler(NoopAuthErrorHandler),
|
|
363
|
+
{
|
|
364
|
+
provide: OAuthModuleConfig,
|
|
365
|
+
useFactory: configureInterceptor,
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
provide: APP_INITIALIZER,
|
|
369
|
+
useFactory: initalizeAuthConfig,
|
|
370
|
+
multi: true,
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
provide: OAuthStorage,
|
|
374
|
+
useFactory: () => inject(WindowRef).nativeWindow.localStorage,
|
|
375
|
+
},
|
|
376
|
+
]);
|
|
377
|
+
}
|
|
257
378
|
|
|
258
|
-
const modules = [AuthComponent, SignInDirective, SignOutDirective];
|
|
379
|
+
const modules = [AuthComponent, AuthDirective, SignInDirective, SignOutDirective];
|
|
259
380
|
class AuthModule {
|
|
260
381
|
static forRoot(config) {
|
|
261
382
|
return {
|
|
262
383
|
ngModule: AuthModule,
|
|
263
|
-
providers: [
|
|
384
|
+
providers: [provideAuth(config)],
|
|
264
385
|
};
|
|
265
386
|
}
|
|
266
387
|
}
|
|
267
|
-
AuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
268
|
-
AuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.
|
|
269
|
-
AuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.
|
|
270
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
388
|
+
AuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
389
|
+
AuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.1", ngImport: i0, type: AuthModule, imports: [AuthComponent, AuthDirective, SignInDirective, SignOutDirective], exports: [AuthComponent, AuthDirective, SignInDirective, SignOutDirective] });
|
|
390
|
+
AuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthModule, imports: [AuthComponent] });
|
|
391
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: AuthModule, decorators: [{
|
|
271
392
|
type: NgModule,
|
|
272
393
|
args: [{
|
|
273
394
|
imports: [...modules],
|
|
274
|
-
exports: [
|
|
395
|
+
exports: [...modules],
|
|
275
396
|
}]
|
|
276
397
|
}] });
|
|
277
398
|
|
|
@@ -279,5 +400,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.0", ngImpor
|
|
|
279
400
|
* Generated bundle index. Do not edit.
|
|
280
401
|
*/
|
|
281
402
|
|
|
282
|
-
export { AuthComponent, AuthDefaultModuleConfig,
|
|
403
|
+
export { AuthComponent, AuthDefaultModuleConfig, AuthDirective, AuthErrorHandler, AuthModule, AuthModuleConfig, AuthService, DEFAULT_AUTH_SCOPES, DEFAULT_ISSUERS, NoopAuthErrorHandler, SignInDirective, SignOutDirective, authGuard, configureInterceptor, createInititals, initalizeAuthConfig, injectAuthModuleConfig, parseIdentityClaims, provideAuth, provideAuthErrorHandler };
|
|
283
404
|
//# sourceMappingURL=odx-auth.mjs.map
|