@valtimo/keycloak 4.15.3-next-main.16 → 4.17.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.
@@ -2,304 +2,337 @@ import { ɵɵdefineInjectable, ɵɵinject, Injectable, Component, NgModule } fro
2
2
  import { KeycloakAngularModule, KeycloakAuthGuard, KeycloakService } from 'keycloak-angular';
3
3
  import { Router, RouterModule } from '@angular/router';
4
4
  import { NGXLogger } from 'ngx-logger';
5
- import { ConfigService } from '@valtimo/config';
5
+ import { ConfigService, ValtimoUserIdentity } from '@valtimo/config';
6
6
  import { CommonModule } from '@angular/common';
7
7
  import { __awaiter } from 'tslib';
8
8
  import { ReplaySubject } from 'rxjs';
9
- import { ValtimoUserIdentity } from '@valtimo/contract';
10
9
 
11
- class KeycloakOptionsService {
12
- constructor(configService) {
13
- this.configService = configService;
14
- this.valtimoKeycloakOptions = configService.config.authentication.options;
15
- }
16
- get keycloakOptions() {
17
- return this.valtimoKeycloakOptions.keycloakOptions;
18
- }
19
- get logoutRedirectUri() {
20
- return this.valtimoKeycloakOptions.logoutRedirectUri;
21
- }
22
- }
23
- KeycloakOptionsService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakOptionsService_Factory() { return new KeycloakOptionsService(ɵɵinject(ConfigService)); }, token: KeycloakOptionsService, providedIn: "root" });
24
- KeycloakOptionsService.decorators = [
25
- { type: Injectable, args: [{
26
- providedIn: 'root',
27
- },] }
28
- ];
29
- KeycloakOptionsService.ctorParameters = () => [
30
- { type: ConfigService }
10
+ /*
11
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
12
+ *
13
+ * Licensed under EUPL, Version 1.2 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" basis,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+
26
+ /*
27
+ *
28
+ * * Copyright 2015-2020 Ritense BV, the Netherlands.
29
+ * *
30
+ * * Licensed under EUPL, Version 1.2 (the "License");
31
+ * * you may not use this file except in compliance with the License.
32
+ * * You may obtain a copy of the License at
33
+ * *
34
+ * * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
35
+ * *
36
+ * * Unless required by applicable law or agreed to in writing, software
37
+ * * distributed under the License is distributed on an "AS IS" basis,
38
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39
+ * * See the License for the specific language governing permissions and
40
+ * * limitations under the License.
41
+ *
42
+ */
43
+
44
+ class KeycloakOptionsService {
45
+ constructor(configService) {
46
+ this.configService = configService;
47
+ this.valtimoKeycloakOptions = configService.config.authentication.options;
48
+ }
49
+ get keycloakOptions() {
50
+ return this.valtimoKeycloakOptions.keycloakOptions;
51
+ }
52
+ get logoutRedirectUri() {
53
+ return this.valtimoKeycloakOptions.logoutRedirectUri;
54
+ }
55
+ }
56
+ KeycloakOptionsService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakOptionsService_Factory() { return new KeycloakOptionsService(ɵɵinject(ConfigService)); }, token: KeycloakOptionsService, providedIn: "root" });
57
+ KeycloakOptionsService.decorators = [
58
+ { type: Injectable, args: [{
59
+ providedIn: 'root',
60
+ },] }
61
+ ];
62
+ KeycloakOptionsService.ctorParameters = () => [
63
+ { type: ConfigService }
31
64
  ];
32
65
 
33
- /*
34
- * Copyright 2015-2020 Ritense BV, the Netherlands.
35
- *
36
- * Licensed under EUPL, Version 1.2 (the "License");
37
- * you may not use this file except in compliance with the License.
38
- * You may obtain a copy of the License at
39
- *
40
- * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
41
- *
42
- * Unless required by applicable law or agreed to in writing, software
43
- * distributed under the License is distributed on an "AS IS" basis,
44
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45
- * See the License for the specific language governing permissions and
46
- * limitations under the License.
47
- */
48
- class CallbackComponent {
49
- constructor(router, keycloakOptionsService, logger) {
50
- this.router = router;
51
- this.keycloakOptionsService = keycloakOptionsService;
52
- this.logger = logger;
53
- logger.debug('callback');
54
- const savedRedirectTo = window.sessionStorage.getItem('redirectTo');
55
- let redirectTo;
56
- if (savedRedirectTo !== null) {
57
- redirectTo = window.sessionStorage.getItem('redirectTo');
58
- }
59
- else {
60
- redirectTo = '/';
61
- }
62
- logger.debug('keycloak callback redirect =', redirectTo);
63
- this.router.navigate([redirectTo]);
64
- }
65
- }
66
- CallbackComponent.decorators = [
67
- { type: Component, args: [{
68
- selector: 'valtimo-keycloak-callback',
69
- template: ''
70
- },] }
71
- ];
72
- CallbackComponent.ctorParameters = () => [
73
- { type: Router },
74
- { type: KeycloakOptionsService },
75
- { type: NGXLogger }
66
+ /*
67
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
68
+ *
69
+ * Licensed under EUPL, Version 1.2 (the "License");
70
+ * you may not use this file except in compliance with the License.
71
+ * You may obtain a copy of the License at
72
+ *
73
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
74
+ *
75
+ * Unless required by applicable law or agreed to in writing, software
76
+ * distributed under the License is distributed on an "AS IS" basis,
77
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78
+ * See the License for the specific language governing permissions and
79
+ * limitations under the License.
80
+ */
81
+ class CallbackComponent {
82
+ constructor(router, keycloakOptionsService, logger) {
83
+ this.router = router;
84
+ this.keycloakOptionsService = keycloakOptionsService;
85
+ this.logger = logger;
86
+ logger.debug('callback');
87
+ const savedRedirectTo = window.sessionStorage.getItem('redirectTo');
88
+ let redirectTo;
89
+ if (savedRedirectTo !== null) {
90
+ redirectTo = window.sessionStorage.getItem('redirectTo');
91
+ }
92
+ else {
93
+ redirectTo = '/';
94
+ }
95
+ logger.debug('keycloak callback redirect =', redirectTo);
96
+ this.router.navigate([redirectTo]);
97
+ }
98
+ }
99
+ CallbackComponent.decorators = [
100
+ { type: Component, args: [{
101
+ selector: 'valtimo-keycloak-callback',
102
+ template: ''
103
+ },] }
104
+ ];
105
+ CallbackComponent.ctorParameters = () => [
106
+ { type: Router },
107
+ { type: KeycloakOptionsService },
108
+ { type: NGXLogger }
76
109
  ];
77
110
 
78
- /*
79
- * Copyright 2015-2020 Ritense BV, the Netherlands.
80
- *
81
- * Licensed under EUPL, Version 1.2 (the "License");
82
- * you may not use this file except in compliance with the License.
83
- * You may obtain a copy of the License at
84
- *
85
- * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
86
- *
87
- * Unless required by applicable law or agreed to in writing, software
88
- * distributed under the License is distributed on an "AS IS" basis,
89
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90
- * See the License for the specific language governing permissions and
91
- * limitations under the License.
92
- */
93
- const ɵ0 = { title: 'Loading...' };
94
- const routes = [
95
- {
96
- path: 'keycloak/callback',
97
- component: CallbackComponent,
98
- data: ɵ0,
99
- },
100
- ];
101
- class KeycloakRoutingModule {
102
- }
103
- KeycloakRoutingModule.decorators = [
104
- { type: NgModule, args: [{
105
- imports: [CommonModule, RouterModule.forChild(routes)],
106
- exports: [RouterModule],
107
- },] }
111
+ /*
112
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
113
+ *
114
+ * Licensed under EUPL, Version 1.2 (the "License");
115
+ * you may not use this file except in compliance with the License.
116
+ * You may obtain a copy of the License at
117
+ *
118
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
119
+ *
120
+ * Unless required by applicable law or agreed to in writing, software
121
+ * distributed under the License is distributed on an "AS IS" basis,
122
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123
+ * See the License for the specific language governing permissions and
124
+ * limitations under the License.
125
+ */
126
+ const ɵ0 = { title: 'Loading...' };
127
+ const routes = [
128
+ {
129
+ path: 'keycloak/callback',
130
+ component: CallbackComponent,
131
+ data: ɵ0,
132
+ },
133
+ ];
134
+ class KeycloakRoutingModule {
135
+ }
136
+ KeycloakRoutingModule.decorators = [
137
+ { type: NgModule, args: [{
138
+ imports: [CommonModule, RouterModule.forChild(routes)],
139
+ exports: [RouterModule],
140
+ },] }
108
141
  ];
109
142
 
110
- /*
111
- * Copyright 2015-2020 Ritense BV, the Netherlands.
112
- *
113
- * Licensed under EUPL, Version 1.2 (the "License");
114
- * you may not use this file except in compliance with the License.
115
- * You may obtain a copy of the License at
116
- *
117
- * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
118
- *
119
- * Unless required by applicable law or agreed to in writing, software
120
- * distributed under the License is distributed on an "AS IS" basis,
121
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122
- * See the License for the specific language governing permissions and
123
- * limitations under the License.
124
- */
125
- class KeycloakModule {
126
- }
127
- KeycloakModule.decorators = [
128
- { type: NgModule, args: [{
129
- declarations: [CallbackComponent],
130
- imports: [KeycloakRoutingModule, KeycloakAngularModule],
131
- exports: [CallbackComponent],
132
- },] }
143
+ /*
144
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
145
+ *
146
+ * Licensed under EUPL, Version 1.2 (the "License");
147
+ * you may not use this file except in compliance with the License.
148
+ * You may obtain a copy of the License at
149
+ *
150
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
151
+ *
152
+ * Unless required by applicable law or agreed to in writing, software
153
+ * distributed under the License is distributed on an "AS IS" basis,
154
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
155
+ * See the License for the specific language governing permissions and
156
+ * limitations under the License.
157
+ */
158
+ class KeycloakModule {
159
+ }
160
+ KeycloakModule.decorators = [
161
+ { type: NgModule, args: [{
162
+ declarations: [CallbackComponent],
163
+ imports: [KeycloakRoutingModule, KeycloakAngularModule],
164
+ exports: [CallbackComponent],
165
+ },] }
133
166
  ];
134
167
 
135
- /*
136
- * Copyright 2015-2020 Ritense BV, the Netherlands.
137
- *
138
- * Licensed under EUPL, Version 1.2 (the "License");
139
- * you may not use this file except in compliance with the License.
140
- * You may obtain a copy of the License at
141
- *
142
- * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
143
- *
144
- * Unless required by applicable law or agreed to in writing, software
145
- * distributed under the License is distributed on an "AS IS" basis,
146
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147
- * See the License for the specific language governing permissions and
148
- * limitations under the License.
149
- */
150
- class KeycloakAuthGuardService extends KeycloakAuthGuard {
151
- constructor(router, keycloakAngular, logger) {
152
- super(router, keycloakAngular);
153
- this.router = router;
154
- this.keycloakAngular = keycloakAngular;
155
- this.logger = logger;
156
- this.logger.debug('KeycloakAuthGuardService: ctor');
157
- }
158
- isAccessAllowed(route, state) {
159
- this.logger.debug('KeycloakAuthGuardService: isAccessAllowed');
160
- return new Promise((resolve, reject) => {
161
- this.logger.debug('KeycloakAuthGuardService: isAccessAllowed checking access');
162
- if (!this.authenticated) {
163
- this.keycloakAngular
164
- .login()
165
- .catch(e => `KeycloakAuthGuardService error: ${this.logger.error(e)}`);
166
- return reject(false);
167
- }
168
- const requiredRoles = route.data.roles;
169
- if (!requiredRoles || requiredRoles.length === 0) {
170
- return resolve(true);
171
- }
172
- else {
173
- if (!this.roles || this.roles.length === 0) {
174
- resolve(false);
175
- }
176
- resolve(requiredRoles.some(role => this.roles.includes(role)));
177
- }
178
- });
179
- }
180
- }
181
- KeycloakAuthGuardService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakAuthGuardService_Factory() { return new KeycloakAuthGuardService(ɵɵinject(Router), ɵɵinject(KeycloakService), ɵɵinject(NGXLogger)); }, token: KeycloakAuthGuardService, providedIn: "root" });
182
- KeycloakAuthGuardService.decorators = [
183
- { type: Injectable, args: [{
184
- providedIn: 'root',
185
- },] }
186
- ];
187
- KeycloakAuthGuardService.ctorParameters = () => [
188
- { type: Router },
189
- { type: KeycloakService },
190
- { type: NGXLogger }
168
+ /*
169
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
170
+ *
171
+ * Licensed under EUPL, Version 1.2 (the "License");
172
+ * you may not use this file except in compliance with the License.
173
+ * You may obtain a copy of the License at
174
+ *
175
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
176
+ *
177
+ * Unless required by applicable law or agreed to in writing, software
178
+ * distributed under the License is distributed on an "AS IS" basis,
179
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180
+ * See the License for the specific language governing permissions and
181
+ * limitations under the License.
182
+ */
183
+ class KeycloakAuthGuardService extends KeycloakAuthGuard {
184
+ constructor(router, keycloakAngular, logger) {
185
+ super(router, keycloakAngular);
186
+ this.router = router;
187
+ this.keycloakAngular = keycloakAngular;
188
+ this.logger = logger;
189
+ this.logger.debug('KeycloakAuthGuardService: ctor');
190
+ }
191
+ isAccessAllowed(route, state) {
192
+ this.logger.debug('KeycloakAuthGuardService: isAccessAllowed');
193
+ return new Promise((resolve, reject) => {
194
+ this.logger.debug('KeycloakAuthGuardService: isAccessAllowed checking access');
195
+ if (!this.authenticated) {
196
+ this.keycloakAngular
197
+ .login()
198
+ .catch(e => `KeycloakAuthGuardService error: ${this.logger.error(e)}`);
199
+ return reject(false);
200
+ }
201
+ const requiredRoles = route.data.roles;
202
+ if (!requiredRoles || requiredRoles.length === 0) {
203
+ return resolve(true);
204
+ }
205
+ else {
206
+ if (!this.roles || this.roles.length === 0) {
207
+ resolve(false);
208
+ }
209
+ resolve(requiredRoles.some(role => this.roles.includes(role)));
210
+ }
211
+ });
212
+ }
213
+ }
214
+ KeycloakAuthGuardService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakAuthGuardService_Factory() { return new KeycloakAuthGuardService(ɵɵinject(Router), ɵɵinject(KeycloakService), ɵɵinject(NGXLogger)); }, token: KeycloakAuthGuardService, providedIn: "root" });
215
+ KeycloakAuthGuardService.decorators = [
216
+ { type: Injectable, args: [{
217
+ providedIn: 'root',
218
+ },] }
219
+ ];
220
+ KeycloakAuthGuardService.ctorParameters = () => [
221
+ { type: Router },
222
+ { type: KeycloakService },
223
+ { type: NGXLogger }
191
224
  ];
192
225
 
193
- class KeycloakUserService {
194
- constructor(keycloakService, keycloakOptionsService, logger) {
195
- this.keycloakService = keycloakService;
196
- this.keycloakOptionsService = keycloakOptionsService;
197
- this.logger = logger;
198
- }
199
- init() {
200
- this.userIdentity = new ReplaySubject();
201
- this.keycloakService.loadUserProfile().then(user => {
202
- this.logger.debug('KeycloakUserService: loadUserProfile = ', user);
203
- const roles = [];
204
- this.keycloakService.getUserRoles(true).forEach(role => roles.push(role));
205
- const valtimoUserIdentity = new ValtimoUserIdentity(user.email, user.firstName, user.lastName, roles, user.username);
206
- this.logger.debug('KeycloakUserService: loaded user identity', valtimoUserIdentity);
207
- this.userIdentity.next(valtimoUserIdentity);
208
- });
209
- }
210
- getUserSubject() {
211
- this.logger.debug('KeycloakUserService: getUserIdentity');
212
- return this.userIdentity;
213
- }
214
- logout() {
215
- this.logger.debug('KeycloakUserService: logout');
216
- this.keycloakService.logout(this.keycloakOptionsService.logoutRedirectUri);
217
- }
218
- getToken() {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- this.logger.debug('KeycloakUserService: getToken');
221
- return this.keycloakService.getToken();
222
- });
223
- }
224
- updateToken(minValidity) {
225
- return __awaiter(this, void 0, void 0, function* () {
226
- this.logger.debug('KeycloakUserService: updateToken');
227
- return this.keycloakService.updateToken(minValidity);
228
- });
229
- }
230
- }
231
- KeycloakUserService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakUserService_Factory() { return new KeycloakUserService(ɵɵinject(KeycloakService), ɵɵinject(KeycloakOptionsService), ɵɵinject(NGXLogger)); }, token: KeycloakUserService, providedIn: "root" });
232
- KeycloakUserService.decorators = [
233
- { type: Injectable, args: [{
234
- providedIn: 'root',
235
- },] }
236
- ];
237
- KeycloakUserService.ctorParameters = () => [
238
- { type: KeycloakService },
239
- { type: KeycloakOptionsService },
240
- { type: NGXLogger }
226
+ class KeycloakUserService {
227
+ constructor(keycloakService, keycloakOptionsService, logger) {
228
+ this.keycloakService = keycloakService;
229
+ this.keycloakOptionsService = keycloakOptionsService;
230
+ this.logger = logger;
231
+ }
232
+ init() {
233
+ this.userIdentity = new ReplaySubject();
234
+ this.keycloakService.loadUserProfile().then(user => {
235
+ this.logger.debug('KeycloakUserService: loadUserProfile = ', user);
236
+ const roles = [];
237
+ this.keycloakService.getUserRoles(true).forEach(role => roles.push(role));
238
+ const valtimoUserIdentity = new ValtimoUserIdentity(user.email, user.firstName, user.lastName, roles, user.username);
239
+ this.logger.debug('KeycloakUserService: loaded user identity', valtimoUserIdentity);
240
+ this.userIdentity.next(valtimoUserIdentity);
241
+ });
242
+ }
243
+ getUserSubject() {
244
+ this.logger.debug('KeycloakUserService: getUserIdentity');
245
+ return this.userIdentity;
246
+ }
247
+ logout() {
248
+ this.logger.debug('KeycloakUserService: logout');
249
+ this.keycloakService.logout(this.keycloakOptionsService.logoutRedirectUri);
250
+ }
251
+ getToken() {
252
+ return __awaiter(this, void 0, void 0, function* () {
253
+ this.logger.debug('KeycloakUserService: getToken');
254
+ return this.keycloakService.getToken();
255
+ });
256
+ }
257
+ updateToken(minValidity) {
258
+ return __awaiter(this, void 0, void 0, function* () {
259
+ this.logger.debug('KeycloakUserService: updateToken');
260
+ return this.keycloakService.updateToken(minValidity);
261
+ });
262
+ }
263
+ }
264
+ KeycloakUserService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakUserService_Factory() { return new KeycloakUserService(ɵɵinject(KeycloakService), ɵɵinject(KeycloakOptionsService), ɵɵinject(NGXLogger)); }, token: KeycloakUserService, providedIn: "root" });
265
+ KeycloakUserService.decorators = [
266
+ { type: Injectable, args: [{
267
+ providedIn: 'root',
268
+ },] }
269
+ ];
270
+ KeycloakUserService.ctorParameters = () => [
271
+ { type: KeycloakService },
272
+ { type: KeycloakOptionsService },
273
+ { type: NGXLogger }
241
274
  ];
242
275
 
243
- /*
244
- * Copyright 2015-2020 Ritense BV, the Netherlands.
245
- *
246
- * Licensed under EUPL, Version 1.2 (the "License");
247
- * you may not use this file except in compliance with the License.
248
- * You may obtain a copy of the License at
249
- *
250
- * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
251
- *
252
- * Unless required by applicable law or agreed to in writing, software
253
- * distributed under the License is distributed on an "AS IS" basis,
254
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
255
- * See the License for the specific language governing permissions and
256
- * limitations under the License.
257
- */
258
- function keycloakInitializer(injector) {
259
- const keycloakService = injector.get(KeycloakService);
260
- const keycloakUserService = injector.get(KeycloakUserService);
261
- const optionsService = injector.get(KeycloakOptionsService); // TODO possible removal of abstraction
262
- const logger = injector.get(NGXLogger);
263
- return () => __awaiter(this, void 0, void 0, function* () {
264
- try {
265
- logger.debug('Keycloak initializer before init');
266
- const keycloakOptions = optionsService.keycloakOptions;
267
- const currentUrl = window.location.href.split('#')[0];
268
- if (keycloakOptions.initOptions.redirectUri !== currentUrl) {
269
- const redirectTo = window.location.pathname;
270
- logger.debug('Setting redirectTo =', redirectTo);
271
- window.sessionStorage.setItem('redirectTo', redirectTo);
272
- }
273
- const initResult = yield keycloakService.init(keycloakOptions);
274
- logger.debug('Keycloak initializer after init');
275
- keycloakUserService.init();
276
- return initResult;
277
- }
278
- catch (error) {
279
- logger.debug('Keycloak initializer error', error);
280
- throw error;
281
- }
282
- });
276
+ /*
277
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
278
+ *
279
+ * Licensed under EUPL, Version 1.2 (the "License");
280
+ * you may not use this file except in compliance with the License.
281
+ * You may obtain a copy of the License at
282
+ *
283
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
284
+ *
285
+ * Unless required by applicable law or agreed to in writing, software
286
+ * distributed under the License is distributed on an "AS IS" basis,
287
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
288
+ * See the License for the specific language governing permissions and
289
+ * limitations under the License.
290
+ */
291
+ function keycloakInitializer(injector) {
292
+ const keycloakService = injector.get(KeycloakService);
293
+ const keycloakUserService = injector.get(KeycloakUserService);
294
+ const optionsService = injector.get(KeycloakOptionsService); // TODO possible removal of abstraction
295
+ const logger = injector.get(NGXLogger);
296
+ return () => __awaiter(this, void 0, void 0, function* () {
297
+ try {
298
+ logger.debug('Keycloak initializer before init');
299
+ const keycloakOptions = optionsService.keycloakOptions;
300
+ const currentUrl = window.location.href.split('#')[0];
301
+ if (keycloakOptions.initOptions.redirectUri !== currentUrl) {
302
+ const redirectTo = window.location.pathname;
303
+ logger.debug('Setting redirectTo =', redirectTo);
304
+ window.sessionStorage.setItem('redirectTo', redirectTo);
305
+ }
306
+ const initResult = yield keycloakService.init(keycloakOptions);
307
+ logger.debug('Keycloak initializer after init');
308
+ keycloakUserService.init();
309
+ return initResult;
310
+ }
311
+ catch (error) {
312
+ logger.debug('Keycloak initializer error', error);
313
+ throw error;
314
+ }
315
+ });
283
316
  }
284
317
 
285
- /*
286
- * Copyright 2015-2020 Ritense BV, the Netherlands.
287
- *
288
- * Licensed under EUPL, Version 1.2 (the "License");
289
- * you may not use this file except in compliance with the License.
290
- * You may obtain a copy of the License at
291
- *
292
- * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
293
- *
294
- * Unless required by applicable law or agreed to in writing, software
295
- * distributed under the License is distributed on an "AS IS" basis,
296
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
297
- * See the License for the specific language governing permissions and
298
- * limitations under the License.
318
+ /*
319
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
320
+ *
321
+ * Licensed under EUPL, Version 1.2 (the "License");
322
+ * you may not use this file except in compliance with the License.
323
+ * You may obtain a copy of the License at
324
+ *
325
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
326
+ *
327
+ * Unless required by applicable law or agreed to in writing, software
328
+ * distributed under the License is distributed on an "AS IS" basis,
329
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
330
+ * See the License for the specific language governing permissions and
331
+ * limitations under the License.
299
332
  */
300
333
 
301
- /**
302
- * Generated bundle index. Do not edit.
334
+ /**
335
+ * Generated bundle index. Do not edit.
303
336
  */
304
337
 
305
338
  export { KeycloakAuthGuardService, KeycloakModule, KeycloakOptionsService, KeycloakUserService, keycloakInitializer, CallbackComponent as ɵa, KeycloakRoutingModule as ɵb };