imng-oidc-client 4.102.10
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 +50 -0
- package/esm2020/imng-oidc-client.mjs +5 -0
- package/esm2020/index.mjs +24 -0
- package/esm2020/lib/+state/oidc-user.facade.mjs +28 -0
- package/esm2020/lib/+state/oidc-user.selectors.mjs +13 -0
- package/esm2020/lib/+state/oidc.actions.mjs +37 -0
- package/esm2020/lib/+state/oidc.effects.mjs +66 -0
- package/esm2020/lib/+state/oidc.facade.mjs +136 -0
- package/esm2020/lib/+state/oidc.reducer.mjs +93 -0
- package/esm2020/lib/+state/oidc.selectors.mjs +40 -0
- package/esm2020/lib/components/access-denied.component.mjs +14 -0
- package/esm2020/lib/components/logout-success.component.mjs +18 -0
- package/esm2020/lib/img-oidc-client-routing.module.mjs +44 -0
- package/esm2020/lib/imng-oidc-client.module.mjs +96 -0
- package/esm2020/lib/models/arguments.model.mjs +2 -0
- package/esm2020/lib/models/constants.mjs +17 -0
- package/esm2020/lib/models/oidc-client-config.mjs +3 -0
- package/esm2020/lib/models/oidc-library-config.mjs +3 -0
- package/esm2020/lib/models/oidc-user-profile.mjs +2 -0
- package/esm2020/lib/models/oidc-user.mjs +2 -0
- package/esm2020/lib/services/auth-guard.mjs +40 -0
- package/esm2020/lib/services/oidc.service.mjs +166 -0
- package/esm2020/lib/services/permissions.guard.mjs +22 -0
- package/esm2020/lib/services/token-interceptor.service.mjs +35 -0
- package/esm2020/lib/support/support.component.mjs +85 -0
- package/esm2020/lib/util/jwt-decoder.mjs +11 -0
- package/esm2020/lib/util/oidc-client-configurator.mjs +24 -0
- package/fesm2015/imng-oidc-client.mjs +844 -0
- package/fesm2015/imng-oidc-client.mjs.map +1 -0
- package/fesm2020/imng-oidc-client.mjs +907 -0
- package/fesm2020/imng-oidc-client.mjs.map +1 -0
- package/imng-oidc-client.d.ts +5 -0
- package/index.d.ts +23 -0
- package/lib/+state/oidc-user.facade.d.ts +16 -0
- package/lib/+state/oidc-user.selectors.d.ts +7 -0
- package/lib/+state/oidc.actions.d.ts +72 -0
- package/lib/+state/oidc.effects.d.ts +58 -0
- package/lib/+state/oidc.facade.d.ts +56 -0
- package/lib/+state/oidc.reducer.d.ts +22 -0
- package/lib/+state/oidc.selectors.d.ts +20 -0
- package/lib/components/access-denied.component.d.ts +5 -0
- package/lib/components/logout-success.component.d.ts +5 -0
- package/lib/img-oidc-client-routing.module.d.ts +12 -0
- package/lib/imng-oidc-client.module.d.ts +17 -0
- package/lib/models/arguments.model.d.ts +21 -0
- package/lib/models/constants.d.ts +14 -0
- package/lib/models/oidc-client-config.d.ts +12 -0
- package/lib/models/oidc-library-config.d.ts +12 -0
- package/lib/models/oidc-user-profile.d.ts +4 -0
- package/lib/models/oidc-user.d.ts +15 -0
- package/lib/services/auth-guard.d.ts +14 -0
- package/lib/services/oidc.service.d.ts +37 -0
- package/lib/services/permissions.guard.d.ts +12 -0
- package/lib/services/token-interceptor.service.d.ts +12 -0
- package/lib/support/support.component.d.ts +15 -0
- package/lib/util/jwt-decoder.d.ts +1 -0
- package/lib/util/oidc-client-configurator.d.ts +3 -0
- package/package.json +54 -0
- package/src/assets/callback.html +44 -0
- package/src/assets/oidc-client.rsa256.slim.min.js +3 -0
- package/src/assets/renew-callback.html +18 -0
- package/src/assets/signout-callback.html +29 -0
|
@@ -0,0 +1,907 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, PLATFORM_ID, Injectable, Inject, Component, NgModule } from '@angular/core';
|
|
3
|
+
import * as i3 from '@angular/common';
|
|
4
|
+
import { isPlatformBrowser, DOCUMENT, CommonModule } from '@angular/common';
|
|
5
|
+
import * as i1$1 from '@ngrx/store';
|
|
6
|
+
import { createFeatureSelector, createSelector, createAction, createReducer, on, Store, StoreModule } from '@ngrx/store';
|
|
7
|
+
import { switchMap, filter, take, map, tap, catchError, concatMap, first, mergeMap } from 'rxjs/operators';
|
|
8
|
+
import { Log, UserManager, OidcClient } from 'oidc-client';
|
|
9
|
+
import { from, of, throwError } from 'rxjs';
|
|
10
|
+
import * as i1 from '@angular/common/http';
|
|
11
|
+
import { HttpErrorResponse, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
12
|
+
import { createPayloadAction } from 'imng-ngrx-utils';
|
|
13
|
+
import { isNullOrUndefined } from 'imng-nrsrx-client-utils';
|
|
14
|
+
import * as i1$2 from '@ngrx/effects';
|
|
15
|
+
import { createEffect, ofType, EffectsModule } from '@ngrx/effects';
|
|
16
|
+
import * as i3$1 from '@angular/router';
|
|
17
|
+
import { RouterModule } from '@angular/router';
|
|
18
|
+
|
|
19
|
+
// State Selectors
|
|
20
|
+
const selectOidcState = createFeatureSelector('oidc');
|
|
21
|
+
const getOidcLoading = createSelector(selectOidcState, (state) => state.loading);
|
|
22
|
+
const getOidcIdentity = createSelector(selectOidcState, (state) => state.identity);
|
|
23
|
+
const getAccessToken = createSelector(getOidcIdentity, (user) => (user || { access_token: undefined }).access_token);
|
|
24
|
+
const isIdentityExpiring = createSelector(selectOidcState, (state) => state.expiring);
|
|
25
|
+
const isIdentityExpired = createSelector(selectOidcState, (state) => state.expired);
|
|
26
|
+
const isLoggedIn = createSelector(selectOidcState, (state) => state.loggedIn);
|
|
27
|
+
// errors
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
29
|
+
const selectOidcErrorState = createSelector(selectOidcState, (state) => state.errors);
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
31
|
+
const hasErrors = createSelector(selectOidcErrorState, (state) => !!state.httpError || !!state.signInError || !!state.silentRenewError);
|
|
32
|
+
const getSignInError = createSelector(selectOidcErrorState, (errors) => errors.signInError);
|
|
33
|
+
const getSilentRenewError = createSelector(selectOidcErrorState, (errors) => errors.silentRenewError);
|
|
34
|
+
const getHttpError = createSelector(selectOidcErrorState, (errors) => errors.httpError);
|
|
35
|
+
const getPermissions$1 = createSelector(selectOidcState, (state) => state.permissions);
|
|
36
|
+
const getAudiences = createSelector(selectOidcState, (state) => state.audiences);
|
|
37
|
+
const getExpiresAt = createSelector(getOidcIdentity, (state) => state?.expires_at ? new Date(state.expires_at * 1000) : null //NOSONAR
|
|
38
|
+
);
|
|
39
|
+
const getUserMetadata = createSelector(selectOidcState, (state) => state.userMetadata);
|
|
40
|
+
const oidcQuery = {
|
|
41
|
+
getExpiresAt,
|
|
42
|
+
getPermissions: getPermissions$1,
|
|
43
|
+
selectOidcState,
|
|
44
|
+
getOidcLoading,
|
|
45
|
+
getOidcIdentity,
|
|
46
|
+
getAccessToken,
|
|
47
|
+
isIdentityExpiring,
|
|
48
|
+
getSilentRenewError,
|
|
49
|
+
isIdentityExpired,
|
|
50
|
+
isLoggedIn,
|
|
51
|
+
getSignInError,
|
|
52
|
+
getHttpError,
|
|
53
|
+
hasErrors,
|
|
54
|
+
getAudiences,
|
|
55
|
+
getUserMetadata,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var OidcEvent;
|
|
59
|
+
(function (OidcEvent) {
|
|
60
|
+
OidcEvent["AccessTokenExpired"] = "addAccessTokenExpired";
|
|
61
|
+
OidcEvent["AccessTokenExpiring"] = "addAccessTokenExpiring";
|
|
62
|
+
OidcEvent["SilentRenewError"] = "AddSilentRenewError";
|
|
63
|
+
OidcEvent["UserLoaded"] = "addUserLoaded";
|
|
64
|
+
OidcEvent["UserUnloaded"] = "addUserUnloaded";
|
|
65
|
+
OidcEvent["UserSignedOut"] = "addUserSignedOut";
|
|
66
|
+
OidcEvent["UserSessionChanged"] = "addUserSessionChanged";
|
|
67
|
+
})(OidcEvent || (OidcEvent = {}));
|
|
68
|
+
var StorageKeys;
|
|
69
|
+
(function (StorageKeys) {
|
|
70
|
+
StorageKeys["PopupCallback"] = "ngoidc:isPopupCallback";
|
|
71
|
+
StorageKeys["OidcSettings"] = "ngoidc:settings";
|
|
72
|
+
})(StorageKeys || (StorageKeys = {}));
|
|
73
|
+
const ACTION_NO_ACTION = 'NO_ACTION';
|
|
74
|
+
|
|
75
|
+
const OIDC_LIBRARY_CONFIG = new InjectionToken('OIDC_LIBRARY_CONFIG');
|
|
76
|
+
|
|
77
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
78
|
+
class OidcService {
|
|
79
|
+
constructor(oidcLibraryConfig,
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
81
|
+
platformId, httpClient) {
|
|
82
|
+
this.oidcLibraryConfig = oidcLibraryConfig;
|
|
83
|
+
this.platformId = platformId;
|
|
84
|
+
this.httpClient = httpClient;
|
|
85
|
+
const logSettings = this.oidcLibraryConfig.log;
|
|
86
|
+
let clientSettings = this.oidcLibraryConfig.oidc_config;
|
|
87
|
+
if (logSettings) {
|
|
88
|
+
Log.level = logSettings.level;
|
|
89
|
+
Log.logger = logSettings.logger;
|
|
90
|
+
}
|
|
91
|
+
if (clientSettings?.userStore != null) {
|
|
92
|
+
clientSettings = {
|
|
93
|
+
...clientSettings,
|
|
94
|
+
userStore: clientSettings.userStore,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
this._userManagerSettings = { ...clientSettings };
|
|
98
|
+
this.OidcUserManager = new UserManager(clientSettings);
|
|
99
|
+
this._oidcClient = new OidcClient(clientSettings);
|
|
100
|
+
}
|
|
101
|
+
getUserMetadata() {
|
|
102
|
+
return this.httpClient
|
|
103
|
+
.get(this.oidcLibraryConfig.oidc_config?.metadataUrl || '')
|
|
104
|
+
.pipe(switchMap((openidConfig) => this.httpClient.get(openidConfig.userinfo_endpoint)));
|
|
105
|
+
}
|
|
106
|
+
getUserManager() {
|
|
107
|
+
return this.OidcUserManager;
|
|
108
|
+
}
|
|
109
|
+
getOidcClient() {
|
|
110
|
+
return this._oidcClient;
|
|
111
|
+
}
|
|
112
|
+
getOidcUser() {
|
|
113
|
+
return from(this.OidcUserManager.getUser());
|
|
114
|
+
}
|
|
115
|
+
removeOidcUser() {
|
|
116
|
+
return from(this.OidcUserManager.removeUser());
|
|
117
|
+
}
|
|
118
|
+
registerOidcEvent(event, callback) {
|
|
119
|
+
switch (event) {
|
|
120
|
+
case OidcEvent.AccessTokenExpired:
|
|
121
|
+
this.OidcUserManager.events.addAccessTokenExpired(callback);
|
|
122
|
+
break;
|
|
123
|
+
case OidcEvent.AccessTokenExpiring:
|
|
124
|
+
this.OidcUserManager.events.addAccessTokenExpiring(callback);
|
|
125
|
+
break;
|
|
126
|
+
case OidcEvent.SilentRenewError:
|
|
127
|
+
this.OidcUserManager.events.addSilentRenewError(callback);
|
|
128
|
+
break;
|
|
129
|
+
case OidcEvent.UserLoaded:
|
|
130
|
+
this.OidcUserManager.events.addUserLoaded(callback);
|
|
131
|
+
break;
|
|
132
|
+
case OidcEvent.UserSessionChanged:
|
|
133
|
+
this.OidcUserManager.events.addUserSessionChanged(callback);
|
|
134
|
+
break;
|
|
135
|
+
case OidcEvent.UserSignedOut:
|
|
136
|
+
this.OidcUserManager.events.addUserSignedOut(callback);
|
|
137
|
+
break;
|
|
138
|
+
case OidcEvent.UserUnloaded:
|
|
139
|
+
this.OidcUserManager.events.addUserUnloaded(callback);
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
removeOidcEvent(event, callback) {
|
|
146
|
+
switch (event) {
|
|
147
|
+
case OidcEvent.AccessTokenExpired:
|
|
148
|
+
this.OidcUserManager.events.removeAccessTokenExpired(callback);
|
|
149
|
+
break;
|
|
150
|
+
case OidcEvent.AccessTokenExpiring:
|
|
151
|
+
this.OidcUserManager.events.removeAccessTokenExpiring(callback);
|
|
152
|
+
break;
|
|
153
|
+
case OidcEvent.SilentRenewError:
|
|
154
|
+
this.OidcUserManager.events.removeSilentRenewError(callback);
|
|
155
|
+
break;
|
|
156
|
+
case OidcEvent.UserLoaded:
|
|
157
|
+
this.OidcUserManager.events.removeUserLoaded(callback);
|
|
158
|
+
break;
|
|
159
|
+
case OidcEvent.UserSessionChanged:
|
|
160
|
+
this.OidcUserManager.events.removeUserSessionChanged(callback);
|
|
161
|
+
break;
|
|
162
|
+
case OidcEvent.UserSignedOut:
|
|
163
|
+
this.OidcUserManager.events.removeUserSignedOut(callback);
|
|
164
|
+
break;
|
|
165
|
+
case OidcEvent.UserUnloaded:
|
|
166
|
+
this.OidcUserManager.events.removeUserUnloaded(callback);
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
signInPopup(args) {
|
|
173
|
+
this.setCallbackInformation(true);
|
|
174
|
+
return from(this.OidcUserManager.signinPopup({ ...args }));
|
|
175
|
+
}
|
|
176
|
+
signInRedirect(args) {
|
|
177
|
+
this.setCallbackInformation(false);
|
|
178
|
+
return from(this.OidcUserManager.signinRedirect({ ...args }));
|
|
179
|
+
}
|
|
180
|
+
signOutPopup(args) {
|
|
181
|
+
this.setCallbackInformation(true);
|
|
182
|
+
return from(this.OidcUserManager.signoutPopup({ ...args }));
|
|
183
|
+
}
|
|
184
|
+
signOutRedirect(args) {
|
|
185
|
+
this.setCallbackInformation(false);
|
|
186
|
+
return from(this.OidcUserManager.signoutRedirect({ ...args }));
|
|
187
|
+
}
|
|
188
|
+
signInSilent(args) {
|
|
189
|
+
return from(this.OidcUserManager.signinSilent({ ...args }));
|
|
190
|
+
}
|
|
191
|
+
signinPopupCallback() {
|
|
192
|
+
return from(this.OidcUserManager.signinPopupCallback());
|
|
193
|
+
}
|
|
194
|
+
signinRedirectCallback() {
|
|
195
|
+
return from(this.OidcUserManager.signinRedirectCallback());
|
|
196
|
+
}
|
|
197
|
+
signoutPopupCallback() {
|
|
198
|
+
return from(this.OidcUserManager.signoutPopupCallback());
|
|
199
|
+
}
|
|
200
|
+
signoutRedirectCallback() {
|
|
201
|
+
return from(this.OidcUserManager.signoutRedirectCallback());
|
|
202
|
+
}
|
|
203
|
+
getSigninUrl(args) {
|
|
204
|
+
return from(this.OidcUserManager.createSigninRequest(args));
|
|
205
|
+
}
|
|
206
|
+
getSignoutUrl(args) {
|
|
207
|
+
return from(this.OidcUserManager.createSignoutRequest(args));
|
|
208
|
+
}
|
|
209
|
+
setCallbackInformation(isPopupCallback) {
|
|
210
|
+
// is browser and useCallbackFlag set to true or defaults to true
|
|
211
|
+
if (isPlatformBrowser(this.platformId) &&
|
|
212
|
+
this.oidcLibraryConfig.useCallbackFlag) {
|
|
213
|
+
localStorage.setItem(StorageKeys.PopupCallback, `${isPopupCallback}`);
|
|
214
|
+
localStorage.setItem(StorageKeys.OidcSettings, JSON.stringify(this._userManagerSettings));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
OidcService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcService, deps: [{ token: OIDC_LIBRARY_CONFIG }, { token: PLATFORM_ID }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
219
|
+
OidcService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcService, providedIn: 'root' });
|
|
220
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcService, decorators: [{
|
|
221
|
+
type: Injectable,
|
|
222
|
+
args: [{
|
|
223
|
+
providedIn: 'root',
|
|
224
|
+
}]
|
|
225
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
226
|
+
type: Inject,
|
|
227
|
+
args: [OIDC_LIBRARY_CONFIG]
|
|
228
|
+
}] }, { type: Object, decorators: [{
|
|
229
|
+
type: Inject,
|
|
230
|
+
args: [PLATFORM_ID]
|
|
231
|
+
}] }, { type: i1.HttpClient }]; } });
|
|
232
|
+
|
|
233
|
+
const clearCurrentEmployee = createAction('[Employees] Clear Current Employee');
|
|
234
|
+
// OIDC COMMANDS
|
|
235
|
+
const getOidcUser = createAction('[Oidc] get oidc user');
|
|
236
|
+
const removeOidcUser = createAction('[Oidc] remove oidc user');
|
|
237
|
+
const userExpired = createAction('[Oidc] user expired');
|
|
238
|
+
const userFound = createPayloadAction('[Oidc] user found');
|
|
239
|
+
const onSessionChanged = createAction('[Oidc] session changed');
|
|
240
|
+
const onAccessTokenExpired = createAction('[Oidc] on access token expired');
|
|
241
|
+
const onAccessTokenExpiring = createAction('[Oidc] user expiring');
|
|
242
|
+
const onUserLoading = createAction('[Oidc] user loading');
|
|
243
|
+
const userDoneLoading = createAction('[Oidc] user done loading');
|
|
244
|
+
const userDoneLoadingError = createPayloadAction('[Oidc] user done loading error');
|
|
245
|
+
const onUserMetadataLoaded = createPayloadAction('[Oidc] on User Metadata Loaded');
|
|
246
|
+
// OIDC EVENTS
|
|
247
|
+
const onSignInPopup = createPayloadAction('[Oidc] on SignInPopup');
|
|
248
|
+
const onSignInRedirect = createPayloadAction('[Oidc] on onSignInRedirect');
|
|
249
|
+
const onSignInSilent = createPayloadAction('[Oidc] on onSignInSilent');
|
|
250
|
+
const onUserLoaded = createPayloadAction('[Oidc] on user loaded');
|
|
251
|
+
const onUserloadError = createPayloadAction('[Oidc] user load error');
|
|
252
|
+
const onUserUnloaded = createAction('[Oidc] on user unloaded');
|
|
253
|
+
const onUserSignedOut = createAction('[Oidc] on user signed out');
|
|
254
|
+
const onSilentRenewError = createPayloadAction('[Oidc] on silent renew error');
|
|
255
|
+
const signInPopup = createPayloadAction('[Oidc] sign in popup');
|
|
256
|
+
const signInRedirect = createPayloadAction('[Oidc] sign in redirect');
|
|
257
|
+
const signInError = createPayloadAction('[Oidc] sign in popup error');
|
|
258
|
+
const signOutPopup = createPayloadAction('[Oidc] sign out popup');
|
|
259
|
+
const signOutPopupError = createPayloadAction('[Oidc] sign out popup error');
|
|
260
|
+
const signOutRedirect = createPayloadAction('[Oidc] sign out redirect');
|
|
261
|
+
const signOutRedirectError = createPayloadAction('[Oidc] sign out redirect error');
|
|
262
|
+
const signInSilent = createPayloadAction('[Oidc] sign in silent');
|
|
263
|
+
const oidcError = createPayloadAction('[Oidc] error');
|
|
264
|
+
// HTTP
|
|
265
|
+
const setHttpError = createPayloadAction('[HTTP] Set Http Error');
|
|
266
|
+
const clearErrors = createAction('[HTTP] Clear Errors');
|
|
267
|
+
|
|
268
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
269
|
+
class OidcFacade {
|
|
270
|
+
constructor(store, oidcService) {
|
|
271
|
+
this.store = store;
|
|
272
|
+
this.oidcService = oidcService;
|
|
273
|
+
this.loading$ = this.store.select(oidcQuery.getOidcLoading);
|
|
274
|
+
this.expiring$ = this.store.select(oidcQuery.isIdentityExpiring);
|
|
275
|
+
this.expired$ = this.store.select(oidcQuery.isIdentityExpired);
|
|
276
|
+
this.loggedIn$ = this.store.select(oidcQuery.isLoggedIn);
|
|
277
|
+
this.identity$ = this.store.select(oidcQuery.getOidcIdentity);
|
|
278
|
+
this.accessToken$ = this.store.select(oidcQuery.getAccessToken);
|
|
279
|
+
this.httpError$ = this.store.select(oidcQuery.getHttpError);
|
|
280
|
+
this.signInError$ = this.store.select(oidcQuery.getSignInError);
|
|
281
|
+
this.silentRenewError$ = this.store.select(oidcQuery.getSilentRenewError);
|
|
282
|
+
this.hasErrors$ = this.store.select(oidcQuery.hasErrors);
|
|
283
|
+
this.permissions$ = this.store.select(oidcQuery.getPermissions);
|
|
284
|
+
this.audiences$ = this.store.select(oidcQuery.getAudiences);
|
|
285
|
+
this.expiresAt$ = this.store.select(oidcQuery.getExpiresAt);
|
|
286
|
+
this.userMetadata$ = this.store.select(oidcQuery.getUserMetadata);
|
|
287
|
+
this.registerDefaultEvents();
|
|
288
|
+
}
|
|
289
|
+
// default bindings to events
|
|
290
|
+
addUserUnLoaded() {
|
|
291
|
+
if (this.store) {
|
|
292
|
+
this.store.dispatch(onUserUnloaded());
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
accessTokenExpired() {
|
|
296
|
+
if (this.store) {
|
|
297
|
+
this.store.dispatch(onAccessTokenExpired());
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
sessionStorage.clear();
|
|
301
|
+
localStorage.clear();
|
|
302
|
+
window.location.reload();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
accessTokenExpiring() {
|
|
306
|
+
if (this.store) {
|
|
307
|
+
this.store.dispatch(onAccessTokenExpiring());
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
this.accessTokenExpired();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
addSilentRenewError(...ev) {
|
|
314
|
+
this.store.dispatch(onSilentRenewError(ev[0]));
|
|
315
|
+
}
|
|
316
|
+
addUserLoaded(...ev) {
|
|
317
|
+
this.store.dispatch(onUserLoaded(ev[0]));
|
|
318
|
+
}
|
|
319
|
+
addUserSignedOut() {
|
|
320
|
+
this.oidcService.removeOidcUser();
|
|
321
|
+
this.store.dispatch(onUserSignedOut());
|
|
322
|
+
}
|
|
323
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
324
|
+
addUserSessionChanged() {
|
|
325
|
+
this.store.dispatch(onSessionChanged());
|
|
326
|
+
}
|
|
327
|
+
clearErrors() {
|
|
328
|
+
this.store.dispatch(clearErrors());
|
|
329
|
+
}
|
|
330
|
+
// OIDC Methods
|
|
331
|
+
getOidcUser() {
|
|
332
|
+
this.store.dispatch(getOidcUser());
|
|
333
|
+
}
|
|
334
|
+
removeOidcUser() {
|
|
335
|
+
this.store.dispatch(removeOidcUser());
|
|
336
|
+
}
|
|
337
|
+
getUserManager() {
|
|
338
|
+
return this.oidcService.getUserManager();
|
|
339
|
+
}
|
|
340
|
+
getOidcClient() {
|
|
341
|
+
return this.oidcService.getOidcClient();
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Convenient function to wait for loaded.
|
|
345
|
+
*/
|
|
346
|
+
waitForAuthenticationLoaded() {
|
|
347
|
+
return this.loading$.pipe(filter((loading) => loading === false), take(1), map(() => true));
|
|
348
|
+
}
|
|
349
|
+
signinPopup(args) {
|
|
350
|
+
this.store.dispatch(signInPopup(args));
|
|
351
|
+
}
|
|
352
|
+
signinRedirect(args) {
|
|
353
|
+
this.store.dispatch(signInRedirect(args));
|
|
354
|
+
}
|
|
355
|
+
signinSilent(args) {
|
|
356
|
+
this.store.dispatch(signInSilent(args));
|
|
357
|
+
}
|
|
358
|
+
signoutPopup(args) {
|
|
359
|
+
this.store.dispatch(signOutPopup(args));
|
|
360
|
+
}
|
|
361
|
+
signoutRedirect(args) {
|
|
362
|
+
this.store.dispatch(signOutRedirect(args));
|
|
363
|
+
}
|
|
364
|
+
getSigninUrl(args) {
|
|
365
|
+
return this.oidcService.getSigninUrl(args);
|
|
366
|
+
}
|
|
367
|
+
getSignoutUrl(args) {
|
|
368
|
+
return this.oidcService.getSignoutUrl(args);
|
|
369
|
+
}
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
371
|
+
registerEvent(event, callback) {
|
|
372
|
+
this.oidcService.registerOidcEvent(event, callback);
|
|
373
|
+
}
|
|
374
|
+
registerDefaultEvents() {
|
|
375
|
+
// add simple loggers
|
|
376
|
+
this.registerEvent(OidcEvent.AccessTokenExpired, this.accessTokenExpired);
|
|
377
|
+
this.registerEvent(OidcEvent.AccessTokenExpiring, this.accessTokenExpiring);
|
|
378
|
+
this.registerEvent(OidcEvent.SilentRenewError, this.addSilentRenewError);
|
|
379
|
+
this.registerEvent(OidcEvent.UserLoaded, this.addUserLoaded);
|
|
380
|
+
this.registerEvent(OidcEvent.UserUnloaded, this.addUserUnLoaded);
|
|
381
|
+
this.registerEvent(OidcEvent.UserSignedOut, this.addUserSignedOut);
|
|
382
|
+
this.registerEvent(OidcEvent.UserSessionChanged, this.addUserSessionChanged);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
OidcFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcFacade, deps: [{ token: i1$1.Store }, { token: OidcService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
386
|
+
OidcFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcFacade, providedIn: 'root' });
|
|
387
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcFacade, decorators: [{
|
|
388
|
+
type: Injectable,
|
|
389
|
+
args: [{
|
|
390
|
+
providedIn: 'root',
|
|
391
|
+
}]
|
|
392
|
+
}], ctorParameters: function () { return [{ type: i1$1.Store }, { type: OidcService }]; } });
|
|
393
|
+
|
|
394
|
+
class AuthGuard {
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
396
|
+
constructor(document, oidcFacade) {
|
|
397
|
+
this.document = document;
|
|
398
|
+
this.oidcFacade = oidcFacade;
|
|
399
|
+
this.isLoggedInPipe$ = this.oidcFacade.waitForAuthenticationLoaded().pipe(switchMap(() => this.oidcFacade.loggedIn$), tap(t => {
|
|
400
|
+
if (!t) {
|
|
401
|
+
this.oidcFacade.signinRedirect({
|
|
402
|
+
data: { redirect_url: this.document.location.href }
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}));
|
|
406
|
+
} //NOSONAR
|
|
407
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
408
|
+
canActivate(route, state) {
|
|
409
|
+
return this.isLoggedInPipe$;
|
|
410
|
+
}
|
|
411
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
412
|
+
canActivateChild(childRoute, state) {
|
|
413
|
+
return this.isLoggedInPipe$;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
AuthGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: AuthGuard, deps: [{ token: DOCUMENT }, { token: OidcFacade }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
417
|
+
AuthGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: AuthGuard, providedIn: 'root' });
|
|
418
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: AuthGuard, decorators: [{
|
|
419
|
+
type: Injectable,
|
|
420
|
+
args: [{
|
|
421
|
+
providedIn: 'root'
|
|
422
|
+
}]
|
|
423
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
424
|
+
type: Inject,
|
|
425
|
+
args: [DOCUMENT]
|
|
426
|
+
}] }, { type: OidcFacade }]; } });
|
|
427
|
+
|
|
428
|
+
function oidcConfigurator(oidcClientConfig, document) {
|
|
429
|
+
return {
|
|
430
|
+
oidc_config: {
|
|
431
|
+
authority: oidcClientConfig.authority,
|
|
432
|
+
client_id: oidcClientConfig.client_id,
|
|
433
|
+
extraQueryParams: { audience: oidcClientConfig.audience },
|
|
434
|
+
redirect_uri: `${document.location.origin}/callback.html`,
|
|
435
|
+
response_type: oidcClientConfig.response_type || 'id_token token',
|
|
436
|
+
scope: oidcClientConfig.scope || 'openid profile offline_access email',
|
|
437
|
+
post_logout_redirect_uri: `${document.location.origin}/signout-callback.html`,
|
|
438
|
+
silent_redirect_uri: `${document.location.origin}/renew-callback.html`,
|
|
439
|
+
automaticSilentRenew: isNullOrUndefined(oidcClientConfig.automaticSilentRenew)
|
|
440
|
+
? true
|
|
441
|
+
: oidcClientConfig.automaticSilentRenew,
|
|
442
|
+
metadataUrl: `${oidcClientConfig.authority}/.well-known/openid-configuration`,
|
|
443
|
+
},
|
|
444
|
+
getUserMetadata: oidcClientConfig.getUserMetadata,
|
|
445
|
+
useCallbackFlag: isNullOrUndefined(oidcClientConfig.useCallbackFlag)
|
|
446
|
+
? true
|
|
447
|
+
: oidcClientConfig.useCallbackFlag,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const OIDC_CLIENT_CONFIG = new InjectionToken('oidc-client-config');
|
|
452
|
+
|
|
453
|
+
const getProfile = createSelector(oidcQuery.getOidcIdentity, (identity) => identity?.profile);
|
|
454
|
+
const getPermissions = createSelector(oidcQuery.selectOidcState, (state) => state?.permissions);
|
|
455
|
+
const getEmail = createSelector(getProfile, (profile) => profile?.email);
|
|
456
|
+
const getProfilePicture = createSelector(getProfile, (profile) => profile?.picture);
|
|
457
|
+
const OidcUserSelectors = {
|
|
458
|
+
getProfile,
|
|
459
|
+
getEmail,
|
|
460
|
+
getProfilePicture,
|
|
461
|
+
getPermissions,
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
class OidcUserFacade {
|
|
465
|
+
constructor(store) {
|
|
466
|
+
this.store = store;
|
|
467
|
+
this.profile$ = this.store.select(OidcUserSelectors.getProfile);
|
|
468
|
+
this.email$ = this.store.select(OidcUserSelectors.getEmail);
|
|
469
|
+
this.profilePicture$ = this.store.select(OidcUserSelectors.getProfilePicture);
|
|
470
|
+
this.permissions$ = this.store.select(OidcUserSelectors.getPermissions);
|
|
471
|
+
}
|
|
472
|
+
hasPermissions(requiredPermissions) {
|
|
473
|
+
return this.permissions$.pipe(map((t) => -1 <
|
|
474
|
+
requiredPermissions.findIndex((f) => -1 < (t?.findIndex((i) => i === f) || -1))));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
OidcUserFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcUserFacade, deps: [{ token: i1$1.Store }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
478
|
+
OidcUserFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcUserFacade, providedIn: 'root' });
|
|
479
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcUserFacade, decorators: [{
|
|
480
|
+
type: Injectable,
|
|
481
|
+
args: [{
|
|
482
|
+
providedIn: 'root',
|
|
483
|
+
}]
|
|
484
|
+
}], ctorParameters: function () { return [{ type: i1$1.Store }]; } });
|
|
485
|
+
|
|
486
|
+
class SupportComponent {
|
|
487
|
+
constructor(facade, oidcUserFacade) {
|
|
488
|
+
this.facade = facade;
|
|
489
|
+
this.oidcUserFacade = oidcUserFacade;
|
|
490
|
+
this.profileValue$ = this.oidcUserFacade.profile$.pipe(map((x) => Object.keys(x).map((propertyKey) => ({
|
|
491
|
+
key: propertyKey,
|
|
492
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
493
|
+
value: x[propertyKey], //NOSONAR
|
|
494
|
+
}))));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
SupportComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: SupportComponent, deps: [{ token: OidcFacade }, { token: OidcUserFacade }], target: i0.ɵɵFactoryTarget.Component });
|
|
498
|
+
SupportComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.2", type: SupportComponent, selector: "imng-support", ngImport: i0, template: `<div class="container pt-5 mt-5">
|
|
499
|
+
<div class="row h3 text-center">
|
|
500
|
+
<div class="col-md-12 text-center">OIDC Support</div>
|
|
501
|
+
</div>
|
|
502
|
+
<div class="row">
|
|
503
|
+
<div class="col-md-3">Audiences</div>
|
|
504
|
+
<div class="col-md-8">
|
|
505
|
+
<span *ngFor="let item of facade.audiences$ | async; last as isLast">
|
|
506
|
+
{{ item }} <br *ngIf="!isLast" />
|
|
507
|
+
</span>
|
|
508
|
+
</div>
|
|
509
|
+
</div>
|
|
510
|
+
<div class="row">
|
|
511
|
+
<div class="col-md-3">Permissions</div>
|
|
512
|
+
<div class="col-md-8">
|
|
513
|
+
<span *ngFor="let item of facade.permissions$ | async; last as isLast">
|
|
514
|
+
{{ item }} <br *ngIf="!isLast" />
|
|
515
|
+
</span>
|
|
516
|
+
</div>
|
|
517
|
+
</div>
|
|
518
|
+
<div class="row">
|
|
519
|
+
<div class="col-md-3">Expires</div>
|
|
520
|
+
<div class="col-md-8">{{ facade.expiresAt$ | async }}</div>
|
|
521
|
+
</div>
|
|
522
|
+
<div class="row" *ngFor="let item of profileValue$ | async">
|
|
523
|
+
<div class="col-md-3">{{ item.key }}</div>
|
|
524
|
+
<div class="col-md-8">{{ item.value }}</div>
|
|
525
|
+
</div>
|
|
526
|
+
</div> `, isInline: true, directives: [{ type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i3.AsyncPipe } });
|
|
527
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: SupportComponent, decorators: [{
|
|
528
|
+
type: Component,
|
|
529
|
+
args: [{
|
|
530
|
+
selector: 'imng-support',
|
|
531
|
+
template: `<div class="container pt-5 mt-5">
|
|
532
|
+
<div class="row h3 text-center">
|
|
533
|
+
<div class="col-md-12 text-center">OIDC Support</div>
|
|
534
|
+
</div>
|
|
535
|
+
<div class="row">
|
|
536
|
+
<div class="col-md-3">Audiences</div>
|
|
537
|
+
<div class="col-md-8">
|
|
538
|
+
<span *ngFor="let item of facade.audiences$ | async; last as isLast">
|
|
539
|
+
{{ item }} <br *ngIf="!isLast" />
|
|
540
|
+
</span>
|
|
541
|
+
</div>
|
|
542
|
+
</div>
|
|
543
|
+
<div class="row">
|
|
544
|
+
<div class="col-md-3">Permissions</div>
|
|
545
|
+
<div class="col-md-8">
|
|
546
|
+
<span *ngFor="let item of facade.permissions$ | async; last as isLast">
|
|
547
|
+
{{ item }} <br *ngIf="!isLast" />
|
|
548
|
+
</span>
|
|
549
|
+
</div>
|
|
550
|
+
</div>
|
|
551
|
+
<div class="row">
|
|
552
|
+
<div class="col-md-3">Expires</div>
|
|
553
|
+
<div class="col-md-8">{{ facade.expiresAt$ | async }}</div>
|
|
554
|
+
</div>
|
|
555
|
+
<div class="row" *ngFor="let item of profileValue$ | async">
|
|
556
|
+
<div class="col-md-3">{{ item.key }}</div>
|
|
557
|
+
<div class="col-md-8">{{ item.value }}</div>
|
|
558
|
+
</div>
|
|
559
|
+
</div> `,
|
|
560
|
+
}]
|
|
561
|
+
}], ctorParameters: function () { return [{ type: OidcFacade }, { type: OidcUserFacade }]; } });
|
|
562
|
+
|
|
563
|
+
class AccessDeniedComponent {
|
|
564
|
+
}
|
|
565
|
+
AccessDeniedComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: AccessDeniedComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
566
|
+
AccessDeniedComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.2", type: AccessDeniedComponent, selector: "imng-access-denied", ngImport: i0, template: '<div class="p-5 m-5 text-danger">Access denied.</div>', isInline: true });
|
|
567
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: AccessDeniedComponent, decorators: [{
|
|
568
|
+
type: Component,
|
|
569
|
+
args: [{
|
|
570
|
+
selector: 'imng-access-denied',
|
|
571
|
+
template: '<div class="p-5 m-5 text-danger">Access denied.</div>'
|
|
572
|
+
}]
|
|
573
|
+
}] });
|
|
574
|
+
|
|
575
|
+
class LogoutSuccessComponent {
|
|
576
|
+
}
|
|
577
|
+
LogoutSuccessComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: LogoutSuccessComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
578
|
+
LogoutSuccessComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.2", type: LogoutSuccessComponent, selector: "imng-logout-success", ngImport: i0, template:
|
|
579
|
+
// eslint-disable-next-line max-len
|
|
580
|
+
'<div class="p-5 m-5 text-center">You have successfully logged out.<br/>Please close this browser window to ensure you are completely logged out of the session.</div>', isInline: true });
|
|
581
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: LogoutSuccessComponent, decorators: [{
|
|
582
|
+
type: Component,
|
|
583
|
+
args: [{
|
|
584
|
+
selector: 'imng-logout-success',
|
|
585
|
+
template:
|
|
586
|
+
// eslint-disable-next-line max-len
|
|
587
|
+
'<div class="p-5 m-5 text-center">You have successfully logged out.<br/>Please close this browser window to ensure you are completely logged out of the session.</div>'
|
|
588
|
+
}]
|
|
589
|
+
}] });
|
|
590
|
+
|
|
591
|
+
const routes = [
|
|
592
|
+
{ path: 'support', component: SupportComponent },
|
|
593
|
+
{ path: 'access-denied', component: AccessDeniedComponent },
|
|
594
|
+
{ path: 'logout', component: LogoutSuccessComponent },
|
|
595
|
+
];
|
|
596
|
+
class ImngOidcClientRoutingModule {
|
|
597
|
+
}
|
|
598
|
+
ImngOidcClientRoutingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientRoutingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
599
|
+
ImngOidcClientRoutingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientRoutingModule, imports: [i3$1.RouterModule], exports: [RouterModule] });
|
|
600
|
+
ImngOidcClientRoutingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientRoutingModule, imports: [[RouterModule.forChild(routes)], RouterModule] });
|
|
601
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientRoutingModule, decorators: [{
|
|
602
|
+
type: NgModule,
|
|
603
|
+
args: [{
|
|
604
|
+
imports: [RouterModule.forChild(routes)],
|
|
605
|
+
exports: [RouterModule],
|
|
606
|
+
}]
|
|
607
|
+
}] });
|
|
608
|
+
const oidcSupportRoute = {
|
|
609
|
+
path: 'oidc/support',
|
|
610
|
+
component: SupportComponent,
|
|
611
|
+
canActivate: [AuthGuard],
|
|
612
|
+
};
|
|
613
|
+
const oidcAccessDeniedRoute = {
|
|
614
|
+
path: 'oidc/access-denied',
|
|
615
|
+
component: AccessDeniedComponent,
|
|
616
|
+
};
|
|
617
|
+
const oidcLogoutRoute = {
|
|
618
|
+
path: 'oidc/logout',
|
|
619
|
+
component: LogoutSuccessComponent,
|
|
620
|
+
};
|
|
621
|
+
const oidcRoutes = [
|
|
622
|
+
oidcSupportRoute,
|
|
623
|
+
oidcAccessDeniedRoute,
|
|
624
|
+
oidcLogoutRoute,
|
|
625
|
+
];
|
|
626
|
+
|
|
627
|
+
class OidcEffects {
|
|
628
|
+
constructor(actions$, oidcService, oidcLibraryOptions, router) {
|
|
629
|
+
this.actions$ = actions$;
|
|
630
|
+
this.oidcService = oidcService;
|
|
631
|
+
this.oidcLibraryOptions = oidcLibraryOptions;
|
|
632
|
+
this.router = router;
|
|
633
|
+
this.getOidcUser$ = createEffect(() => this.actions$.pipe(ofType(getOidcUser), switchMap(() => this.oidcService.getOidcUser().pipe(map((userData) => this.makeOidcUserSerializable(userData)), filter((userData) => !!userData), map((userData) => userFound(userData)), catchError((err) => of(userDoneLoadingError(err)))))));
|
|
634
|
+
this.silentRenew$ = createEffect(() => this.actions$.pipe(ofType(userFound), filter((userFound) =>
|
|
635
|
+
// user expired, initiate silent sign-in if configured to automatic
|
|
636
|
+
(userFound.payload != null &&
|
|
637
|
+
userFound.payload.expired &&
|
|
638
|
+
this.oidcLibraryOptions.oidc_config?.automaticSilentRenew) ||
|
|
639
|
+
false), map((userFound) => signInSilent(userFound.payload))));
|
|
640
|
+
this.removeOidcUser$ = createEffect(() => this.actions$.pipe(ofType(removeOidcUser), concatMap(() => this.oidcService.removeOidcUser().pipe(map(() => userDoneLoading()), catchError((err) => of(oidcError(err)))))));
|
|
641
|
+
this.userDoneLoadingNoMetadata$ = createEffect(() => this.actions$.pipe(ofType(userFound), filter(() => !this.oidcLibraryOptions.getUserMetadata), map(() => userDoneLoading())));
|
|
642
|
+
this.userDoneLoadingWithMetadata$ = createEffect(() => this.actions$.pipe(ofType(userFound), filter(() => this.oidcLibraryOptions.getUserMetadata || false), switchMap(() => this.oidcService.getUserMetadata()), map((metadata) => onUserMetadataLoaded(metadata))));
|
|
643
|
+
this.onAccessTokenExpired$ = createEffect(() => this.actions$.pipe(ofType(onAccessTokenExpired), map(() => removeOidcUser())));
|
|
644
|
+
this.signInPopup$ = createEffect(() => this.actions$.pipe(ofType(signInPopup), concatMap((args) => this.oidcService.signInPopup(args.payload).pipe(map((user) => onSignInPopup(this.makeOidcUserSerializable(user))), catchError((err) => of(signInError(err)))))));
|
|
645
|
+
this.signInRedirect$ = createEffect(() => this.actions$.pipe(ofType(signInRedirect), concatMap((args) => this.oidcService.signInRedirect(args.payload).pipe(concatMap(() => this.oidcService.signinRedirectCallback()), map((user) => onSignInRedirect(this.makeOidcUserSerializable(user))), catchError((err) => of(signInError(err)))))));
|
|
646
|
+
this.signInSilent$ = createEffect(() => this.actions$.pipe(ofType(signInSilent), concatMap((args) => this.oidcService.signInSilent(args.payload).pipe(map((user) => onSignInSilent(this.makeOidcUserSerializable(user))), catchError((err) => of(onSilentRenewError(err)))))));
|
|
647
|
+
this.signOutPopup$ = createEffect(() => this.actions$.pipe(ofType(signOutPopup), concatMap((args) => this.oidcService.signOutPopup(args.payload).pipe(map(() => onUserSignedOut()), catchError((err) => of(signOutPopupError(err.message)))))));
|
|
648
|
+
this.signOutRedirect$ = createEffect(() => this.actions$.pipe(ofType(signOutRedirect), concatMap((args) => this.oidcService.signOutRedirect(args.payload).pipe(map(() => onUserSignedOut()), catchError((err) => of(signOutRedirectError(err.message)))))));
|
|
649
|
+
this.onUserSignedOut$ = createEffect(() => this.actions$.pipe(ofType(onUserSignedOut, signOutPopupError, signOutRedirectError), tap(() => {
|
|
650
|
+
localStorage.clear();
|
|
651
|
+
sessionStorage.clear();
|
|
652
|
+
this.router.navigateByUrl(oidcLogoutRoute.path || '');
|
|
653
|
+
})), { dispatch: false });
|
|
654
|
+
}
|
|
655
|
+
ngrxOnInitEffects() {
|
|
656
|
+
return getOidcUser();
|
|
657
|
+
}
|
|
658
|
+
makeOidcUserSerializable(user) {
|
|
659
|
+
if (user?.toStorageString) {
|
|
660
|
+
user = {
|
|
661
|
+
...user,
|
|
662
|
+
toStorageString: undefined,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
return user;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
OidcEffects.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcEffects, deps: [{ token: i1$2.Actions }, { token: OidcService }, { token: OIDC_LIBRARY_CONFIG }, { token: i3$1.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
669
|
+
OidcEffects.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcEffects, providedIn: 'root' });
|
|
670
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: OidcEffects, decorators: [{
|
|
671
|
+
type: Injectable,
|
|
672
|
+
args: [{
|
|
673
|
+
providedIn: 'root',
|
|
674
|
+
}]
|
|
675
|
+
}], ctorParameters: function () { return [{ type: i1$2.Actions }, { type: OidcService }, { type: undefined, decorators: [{
|
|
676
|
+
type: Inject,
|
|
677
|
+
args: [OIDC_LIBRARY_CONFIG]
|
|
678
|
+
}] }, { type: i3$1.Router }]; } });
|
|
679
|
+
|
|
680
|
+
function jwtDecoder(rawToken) {
|
|
681
|
+
const splits = rawToken?.split('.');
|
|
682
|
+
if (splits?.length > 1) {
|
|
683
|
+
const payload = splits[1];
|
|
684
|
+
return JSON.parse(window.atob(payload));
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
return null;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const OIDC_FEATURE_KEY = 'oidc';
|
|
692
|
+
const initialState = {
|
|
693
|
+
audiences: [],
|
|
694
|
+
permissions: [],
|
|
695
|
+
loading: true,
|
|
696
|
+
loggedIn: false,
|
|
697
|
+
expiring: false,
|
|
698
|
+
expired: false,
|
|
699
|
+
errors: {
|
|
700
|
+
silentRenewError: undefined,
|
|
701
|
+
signInError: undefined,
|
|
702
|
+
httpError: undefined,
|
|
703
|
+
},
|
|
704
|
+
};
|
|
705
|
+
const featureReducer = createReducer(initialState, on(getOidcUser, onUserLoading, (state) => ({
|
|
706
|
+
...state,
|
|
707
|
+
loading: true,
|
|
708
|
+
loggedIn: false,
|
|
709
|
+
})), on(removeOidcUser, (state) => ({
|
|
710
|
+
...state,
|
|
711
|
+
loading: true,
|
|
712
|
+
loggedIn: false,
|
|
713
|
+
identity: undefined,
|
|
714
|
+
})), on(setHttpError, (state, err) => ({
|
|
715
|
+
...state,
|
|
716
|
+
loading: false,
|
|
717
|
+
errors: {
|
|
718
|
+
...state.errors,
|
|
719
|
+
httpError: err.payload,
|
|
720
|
+
},
|
|
721
|
+
})), on(onUserMetadataLoaded, (state, userMetadata) => ({
|
|
722
|
+
...state,
|
|
723
|
+
userMetadata: userMetadata.payload,
|
|
724
|
+
loading: false,
|
|
725
|
+
})), on(clearErrors, (state) => ({ ...state, errors: {} })), on(userDoneLoading, (state) => ({ ...state, loading: false })), on(onAccessTokenExpiring, (state) => ({
|
|
726
|
+
...state,
|
|
727
|
+
expiring: true,
|
|
728
|
+
})), on(onAccessTokenExpired, (state) => ({
|
|
729
|
+
...state,
|
|
730
|
+
loggedIn: false,
|
|
731
|
+
expiring: false,
|
|
732
|
+
expired: true,
|
|
733
|
+
})), on(onUserLoaded, (state) => ({
|
|
734
|
+
...state,
|
|
735
|
+
loading: false,
|
|
736
|
+
expiring: false,
|
|
737
|
+
})), on(onUserUnloaded, onUserSignedOut, signOutPopupError, signOutRedirectError, (state) => ({
|
|
738
|
+
...state,
|
|
739
|
+
loggedIn: false,
|
|
740
|
+
identity: undefined,
|
|
741
|
+
expired: true,
|
|
742
|
+
expiring: false,
|
|
743
|
+
userMetadata: undefined,
|
|
744
|
+
})), on(signOutRedirect, signOutPopup, (state) => ({
|
|
745
|
+
...state,
|
|
746
|
+
identity: undefined,
|
|
747
|
+
userMetadata: null,
|
|
748
|
+
loggedIn: false,
|
|
749
|
+
})), on(userFound, onSignInPopup, onSignInRedirect, onSignInSilent, (state, { payload }) => ({
|
|
750
|
+
...state,
|
|
751
|
+
identity: payload,
|
|
752
|
+
loggedIn: true,
|
|
753
|
+
audiences: payload.access_token
|
|
754
|
+
? jwtDecoder(payload.access_token)?.aud
|
|
755
|
+
: undefined,
|
|
756
|
+
permissions: jwtDecoder(payload.access_token)
|
|
757
|
+
?.permissions,
|
|
758
|
+
})), on(userExpired, (state) => ({
|
|
759
|
+
...state,
|
|
760
|
+
loggedIn: false,
|
|
761
|
+
expiring: false,
|
|
762
|
+
})), on(onSilentRenewError, (state, err) => ({
|
|
763
|
+
...state,
|
|
764
|
+
loading: false,
|
|
765
|
+
errors: {
|
|
766
|
+
...state.errors,
|
|
767
|
+
silentRenewError: err.payload,
|
|
768
|
+
},
|
|
769
|
+
})), on(userDoneLoadingError, signInError, (state, err) => ({
|
|
770
|
+
...state,
|
|
771
|
+
loading: false,
|
|
772
|
+
errors: {
|
|
773
|
+
...state.errors,
|
|
774
|
+
signInError: err.payload,
|
|
775
|
+
},
|
|
776
|
+
})));
|
|
777
|
+
function oidcReducer(state, action) {
|
|
778
|
+
return featureReducer(state, action);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
class TokenInterceptorService {
|
|
782
|
+
constructor(store) {
|
|
783
|
+
this.store = store;
|
|
784
|
+
}
|
|
785
|
+
intercept(req, next) {
|
|
786
|
+
return this.store.select(oidcQuery.getAccessToken).pipe(first(), mergeMap(accessToken => {
|
|
787
|
+
if (accessToken) {
|
|
788
|
+
req = req.clone({
|
|
789
|
+
setHeaders: { Authorization: `Bearer ${accessToken}` },
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
return next.handle(req).pipe(catchError((err) => {
|
|
793
|
+
if (err instanceof HttpErrorResponse) {
|
|
794
|
+
this.store.dispatch(setHttpError(err));
|
|
795
|
+
}
|
|
796
|
+
return throwError(() => err);
|
|
797
|
+
}));
|
|
798
|
+
}));
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
TokenInterceptorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: TokenInterceptorService, deps: [{ token: i1$1.Store }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
802
|
+
TokenInterceptorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: TokenInterceptorService });
|
|
803
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: TokenInterceptorService, decorators: [{
|
|
804
|
+
type: Injectable
|
|
805
|
+
}], ctorParameters: function () { return [{ type: i1$1.Store }]; } });
|
|
806
|
+
|
|
807
|
+
class ImngOidcClientModule {
|
|
808
|
+
static forRoot(oidc0ptions) {
|
|
809
|
+
return {
|
|
810
|
+
ngModule: ImngOidcClientModule,
|
|
811
|
+
providers: [{ provide: OIDC_CLIENT_CONFIG, useValue: oidc0ptions }],
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
ImngOidcClientModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
816
|
+
ImngOidcClientModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientModule, declarations: [AccessDeniedComponent,
|
|
817
|
+
SupportComponent,
|
|
818
|
+
LogoutSuccessComponent], imports: [CommonModule,
|
|
819
|
+
HttpClientModule, i1$1.StoreFeatureModule, i1$2.EffectsFeatureModule, ImngOidcClientRoutingModule], exports: [AccessDeniedComponent, SupportComponent, LogoutSuccessComponent] });
|
|
820
|
+
ImngOidcClientModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientModule, providers: [
|
|
821
|
+
{
|
|
822
|
+
provide: OIDC_LIBRARY_CONFIG,
|
|
823
|
+
useFactory: oidcConfigurator,
|
|
824
|
+
deps: [OIDC_CLIENT_CONFIG, DOCUMENT],
|
|
825
|
+
},
|
|
826
|
+
OidcService,
|
|
827
|
+
OidcFacade,
|
|
828
|
+
OidcEffects,
|
|
829
|
+
OidcUserFacade,
|
|
830
|
+
AuthGuard,
|
|
831
|
+
{
|
|
832
|
+
provide: HTTP_INTERCEPTORS,
|
|
833
|
+
useClass: TokenInterceptorService,
|
|
834
|
+
multi: true,
|
|
835
|
+
deps: [Store],
|
|
836
|
+
},
|
|
837
|
+
], imports: [[
|
|
838
|
+
CommonModule,
|
|
839
|
+
HttpClientModule,
|
|
840
|
+
StoreModule.forFeature(OIDC_FEATURE_KEY, oidcReducer),
|
|
841
|
+
EffectsModule.forFeature([OidcEffects]),
|
|
842
|
+
ImngOidcClientRoutingModule,
|
|
843
|
+
]] });
|
|
844
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ImngOidcClientModule, decorators: [{
|
|
845
|
+
type: NgModule,
|
|
846
|
+
args: [{
|
|
847
|
+
declarations: [
|
|
848
|
+
AccessDeniedComponent,
|
|
849
|
+
SupportComponent,
|
|
850
|
+
LogoutSuccessComponent,
|
|
851
|
+
],
|
|
852
|
+
imports: [
|
|
853
|
+
CommonModule,
|
|
854
|
+
HttpClientModule,
|
|
855
|
+
StoreModule.forFeature(OIDC_FEATURE_KEY, oidcReducer),
|
|
856
|
+
EffectsModule.forFeature([OidcEffects]),
|
|
857
|
+
ImngOidcClientRoutingModule,
|
|
858
|
+
],
|
|
859
|
+
exports: [AccessDeniedComponent, SupportComponent, LogoutSuccessComponent],
|
|
860
|
+
providers: [
|
|
861
|
+
{
|
|
862
|
+
provide: OIDC_LIBRARY_CONFIG,
|
|
863
|
+
useFactory: oidcConfigurator,
|
|
864
|
+
deps: [OIDC_CLIENT_CONFIG, DOCUMENT],
|
|
865
|
+
},
|
|
866
|
+
OidcService,
|
|
867
|
+
OidcFacade,
|
|
868
|
+
OidcEffects,
|
|
869
|
+
OidcUserFacade,
|
|
870
|
+
AuthGuard,
|
|
871
|
+
{
|
|
872
|
+
provide: HTTP_INTERCEPTORS,
|
|
873
|
+
useClass: TokenInterceptorService,
|
|
874
|
+
multi: true,
|
|
875
|
+
deps: [Store],
|
|
876
|
+
},
|
|
877
|
+
],
|
|
878
|
+
}]
|
|
879
|
+
}] });
|
|
880
|
+
|
|
881
|
+
class PermissionsGuard {
|
|
882
|
+
constructor(oidcFacade, oidcUserFacade, router) {
|
|
883
|
+
this.oidcFacade = oidcFacade;
|
|
884
|
+
this.oidcUserFacade = oidcUserFacade;
|
|
885
|
+
this.router = router;
|
|
886
|
+
}
|
|
887
|
+
canActivate(
|
|
888
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
889
|
+
route,
|
|
890
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
891
|
+
state) {
|
|
892
|
+
return this.oidcFacade.waitForAuthenticationLoaded().pipe(switchMap(() => this.oidcUserFacade.hasPermissions(this.permissions)), tap((t) => {
|
|
893
|
+
if (!t) {
|
|
894
|
+
this.router.navigate(['oidc/access-denied'], {
|
|
895
|
+
relativeTo: this.router.routerState.root,
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
}));
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Generated bundle index. Do not edit.
|
|
904
|
+
*/
|
|
905
|
+
|
|
906
|
+
export { ACTION_NO_ACTION, AccessDeniedComponent, AuthGuard, ImngOidcClientModule, ImngOidcClientRoutingModule, LogoutSuccessComponent, OIDC_CLIENT_CONFIG, OidcEffects, OidcEvent, OidcFacade, OidcService, OidcUserFacade, OidcUserSelectors, PermissionsGuard, StorageKeys, SupportComponent, TokenInterceptorService, clearCurrentEmployee, clearErrors, getOidcUser, jwtDecoder, oidcAccessDeniedRoute, oidcConfigurator, oidcError, oidcLogoutRoute, oidcQuery, oidcReducer, oidcRoutes, oidcSupportRoute, onAccessTokenExpired, onAccessTokenExpiring, onSessionChanged, onSignInPopup, onSignInRedirect, onSignInSilent, onSilentRenewError, onUserLoaded, onUserLoading, onUserMetadataLoaded, onUserSignedOut, onUserUnloaded, onUserloadError, removeOidcUser, setHttpError, signInError, signInPopup, signInRedirect, signInSilent, signOutPopup, signOutPopupError, signOutRedirect, signOutRedirectError, userDoneLoading, userDoneLoadingError, userExpired, userFound };
|
|
907
|
+
//# sourceMappingURL=imng-oidc-client.mjs.map
|