@valtimo/keycloak 10.4.0 → 10.5.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/lib/callback.component.mjs +22 -16
- package/esm2020/lib/constants/index.mjs +17 -0
- package/esm2020/lib/constants/storage-keys.mjs +23 -0
- package/esm2020/lib/keycloak-routing.module.mjs +2 -2
- package/esm2020/lib/keycloak.init.mjs +8 -9
- package/esm2020/lib/keycloak.module.mjs +2 -2
- package/esm2020/lib/models/index.mjs +2 -2
- package/esm2020/lib/models/keycloak.config.mjs +2 -2
- package/esm2020/lib/services/index.mjs +20 -0
- package/esm2020/lib/services/keycloak-auth-guard.service.mjs +61 -0
- package/esm2020/lib/services/keycloak-options.service.mjs +24 -0
- package/esm2020/lib/services/keycloak-storage.service.mjs +43 -0
- package/esm2020/lib/services/keycloak-user.service.mjs +180 -0
- package/esm2020/public_api.mjs +6 -5
- package/fesm2015/valtimo-keycloak.mjs +262 -148
- package/fesm2015/valtimo-keycloak.mjs.map +1 -1
- package/fesm2020/valtimo-keycloak.mjs +264 -151
- package/fesm2020/valtimo-keycloak.mjs.map +1 -1
- package/lib/callback.component.d.ts +3 -2
- package/lib/callback.component.d.ts.map +1 -1
- package/lib/constants/index.d.ts +2 -0
- package/lib/constants/index.d.ts.map +1 -0
- package/lib/constants/storage-keys.d.ts +8 -0
- package/lib/constants/storage-keys.d.ts.map +1 -0
- package/lib/keycloak.init.d.ts.map +1 -1
- package/lib/services/index.d.ts +5 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/keycloak-auth-guard.service.d.ts.map +1 -0
- package/lib/services/keycloak-options.service.d.ts.map +1 -0
- package/lib/services/keycloak-storage.service.d.ts +11 -0
- package/lib/services/keycloak-storage.service.d.ts.map +1 -0
- package/lib/{keycloak-user.service.d.ts → services/keycloak-user.service.d.ts} +9 -2
- package/lib/services/keycloak-user.service.d.ts.map +1 -0
- package/package.json +1 -1
- package/public_api.d.ts +4 -3
- package/public_api.d.ts.map +1 -1
- package/esm2020/lib/keycloak-auth-guard.service.mjs +0 -61
- package/esm2020/lib/keycloak-options.service.mjs +0 -24
- package/esm2020/lib/keycloak-user.service.mjs +0 -162
- package/lib/keycloak-auth-guard.service.d.ts.map +0 -1
- package/lib/keycloak-options.service.d.ts.map +0 -1
- package/lib/keycloak-user.service.d.ts.map +0 -1
- /package/lib/{keycloak-auth-guard.service.d.ts → services/keycloak-auth-guard.service.d.ts} +0 -0
- /package/lib/{keycloak-options.service.d.ts → services/keycloak-options.service.d.ts} +0 -0
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable, Component, NgModule } from '@angular/core';
|
|
3
3
|
import * as i2 from 'keycloak-angular';
|
|
4
|
-
import {
|
|
5
|
-
import * as i1
|
|
4
|
+
import { KeycloakAuthGuard, KeycloakEventType, KeycloakAngularModule, KeycloakService } from 'keycloak-angular';
|
|
5
|
+
import * as i1 from '@angular/router';
|
|
6
6
|
import { RouterModule } from '@angular/router';
|
|
7
|
-
import * as i1 from '@valtimo/config';
|
|
8
|
-
import { ValtimoUserIdentity } from '@valtimo/config';
|
|
9
7
|
import * as i3 from 'ngx-logger';
|
|
10
8
|
import { NGXLogger } from 'ngx-logger';
|
|
11
|
-
import * as
|
|
12
|
-
import {
|
|
13
|
-
import * as i5 from '@ngx-translate/core';
|
|
14
|
-
import { TranslateModule } from '@ngx-translate/core';
|
|
9
|
+
import * as i1$1 from '@valtimo/config';
|
|
10
|
+
import { ValtimoUserIdentity } from '@valtimo/config';
|
|
15
11
|
import { Subject, ReplaySubject, timer, map, switchMap, combineLatest } from 'rxjs';
|
|
16
12
|
import jwt_decode from 'jwt-decode';
|
|
17
13
|
import { take } from 'rxjs/operators';
|
|
18
14
|
import * as i4 from '@valtimo/user-interface';
|
|
15
|
+
import * as i5 from '@ngx-translate/core';
|
|
16
|
+
import { TranslateModule } from '@ngx-translate/core';
|
|
17
|
+
import * as i6 from '@angular/common';
|
|
18
|
+
import { CommonModule, DatePipe } from '@angular/common';
|
|
19
19
|
|
|
20
20
|
/*
|
|
21
|
-
* Copyright 2015-
|
|
21
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
22
22
|
*
|
|
23
23
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
24
24
|
* you may not use this file except in compliance with the License.
|
|
@@ -34,7 +34,7 @@ import * as i4 from '@valtimo/user-interface';
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
/*
|
|
37
|
-
* Copyright 2015-
|
|
37
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
38
38
|
*
|
|
39
39
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
40
40
|
* you may not use this file except in compliance with the License.
|
|
@@ -49,81 +49,8 @@ import * as i4 from '@valtimo/user-interface';
|
|
|
49
49
|
* limitations under the License.
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
class KeycloakOptionsService {
|
|
53
|
-
constructor(configService) {
|
|
54
|
-
this.configService = configService;
|
|
55
|
-
this.valtimoKeycloakOptions = configService.config.authentication.options;
|
|
56
|
-
}
|
|
57
|
-
get keycloakOptions() {
|
|
58
|
-
return this.valtimoKeycloakOptions.keycloakOptions;
|
|
59
|
-
}
|
|
60
|
-
get logoutRedirectUri() {
|
|
61
|
-
return this.valtimoKeycloakOptions.logoutRedirectUri;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
KeycloakOptionsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakOptionsService, deps: [{ token: i1.ConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
65
|
-
KeycloakOptionsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakOptionsService, providedIn: 'root' });
|
|
66
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakOptionsService, decorators: [{
|
|
67
|
-
type: Injectable,
|
|
68
|
-
args: [{
|
|
69
|
-
providedIn: 'root',
|
|
70
|
-
}]
|
|
71
|
-
}], ctorParameters: function () { return [{ type: i1.ConfigService }]; } });
|
|
72
|
-
|
|
73
|
-
/*
|
|
74
|
-
* Copyright 2015-2020 Ritense BV, the Netherlands.
|
|
75
|
-
*
|
|
76
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
77
|
-
* you may not use this file except in compliance with the License.
|
|
78
|
-
* You may obtain a copy of the License at
|
|
79
|
-
*
|
|
80
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
81
|
-
*
|
|
82
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
83
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
84
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
85
|
-
* See the License for the specific language governing permissions and
|
|
86
|
-
* limitations under the License.
|
|
87
|
-
*/
|
|
88
|
-
class CallbackComponent {
|
|
89
|
-
constructor(router, keycloakOptionsService, logger) {
|
|
90
|
-
this.router = router;
|
|
91
|
-
this.keycloakOptionsService = keycloakOptionsService;
|
|
92
|
-
this.logger = logger;
|
|
93
|
-
logger.debug('callback');
|
|
94
|
-
const savedRedirectTo = window.sessionStorage.getItem('redirectTo');
|
|
95
|
-
const savedRedirectToParams = window.sessionStorage.getItem('redirectToParams');
|
|
96
|
-
const parsedSavedRedirectToParams = typeof savedRedirectToParams === 'string' &&
|
|
97
|
-
savedRedirectToParams.length > 2 &&
|
|
98
|
-
JSON.parse(savedRedirectToParams);
|
|
99
|
-
let redirectTo;
|
|
100
|
-
let redirectToParams;
|
|
101
|
-
if (savedRedirectTo) {
|
|
102
|
-
redirectTo = savedRedirectTo;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
redirectTo = '/';
|
|
106
|
-
}
|
|
107
|
-
if (savedRedirectToParams && parsedSavedRedirectToParams) {
|
|
108
|
-
redirectToParams = parsedSavedRedirectToParams;
|
|
109
|
-
}
|
|
110
|
-
logger.debug('keycloak callback redirect =', redirectTo);
|
|
111
|
-
logger.debug('keycloak callback redirect params =', savedRedirectToParams);
|
|
112
|
-
this.router.navigate([redirectTo], { queryParams: redirectToParams || {} });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
CallbackComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CallbackComponent, deps: [{ token: i1$1.Router }, { token: KeycloakOptionsService }, { token: i3.NGXLogger }], target: i0.ɵɵFactoryTarget.Component });
|
|
116
|
-
CallbackComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.12", type: CallbackComponent, selector: "valtimo-keycloak-callback", ngImport: i0, template: '', isInline: true });
|
|
117
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CallbackComponent, decorators: [{
|
|
118
|
-
type: Component,
|
|
119
|
-
args: [{
|
|
120
|
-
selector: 'valtimo-keycloak-callback',
|
|
121
|
-
template: '',
|
|
122
|
-
}]
|
|
123
|
-
}], ctorParameters: function () { return [{ type: i1$1.Router }, { type: KeycloakOptionsService }, { type: i3.NGXLogger }]; } });
|
|
124
|
-
|
|
125
52
|
/*
|
|
126
|
-
* Copyright 2015-
|
|
53
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
127
54
|
*
|
|
128
55
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
129
56
|
* you may not use this file except in compliance with the License.
|
|
@@ -137,28 +64,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
|
|
|
137
64
|
* See the License for the specific language governing permissions and
|
|
138
65
|
* limitations under the License.
|
|
139
66
|
*/
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
];
|
|
147
|
-
class KeycloakRoutingModule {
|
|
148
|
-
}
|
|
149
|
-
KeycloakRoutingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
150
|
-
KeycloakRoutingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, imports: [CommonModule, i1$1.RouterModule], exports: [RouterModule] });
|
|
151
|
-
KeycloakRoutingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, imports: [CommonModule, RouterModule.forChild(routes), RouterModule] });
|
|
152
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, decorators: [{
|
|
153
|
-
type: NgModule,
|
|
154
|
-
args: [{
|
|
155
|
-
imports: [CommonModule, RouterModule.forChild(routes)],
|
|
156
|
-
exports: [RouterModule],
|
|
157
|
-
}]
|
|
158
|
-
}] });
|
|
67
|
+
const STORAGE_KEYS = {
|
|
68
|
+
urlBeforeExpiration: 'urlBeforeExpiration',
|
|
69
|
+
urlBeforeExpirationParams: 'urlBeforeExpirationParams',
|
|
70
|
+
redirectTo: 'redirectTo',
|
|
71
|
+
redirectToParams: 'redirectToParams',
|
|
72
|
+
};
|
|
159
73
|
|
|
160
74
|
/*
|
|
161
|
-
* Copyright 2015-
|
|
75
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
162
76
|
*
|
|
163
77
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
164
78
|
* you may not use this file except in compliance with the License.
|
|
@@ -172,23 +86,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
|
|
|
172
86
|
* See the License for the specific language governing permissions and
|
|
173
87
|
* limitations under the License.
|
|
174
88
|
*/
|
|
175
|
-
class KeycloakModule {
|
|
176
|
-
}
|
|
177
|
-
KeycloakModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
178
|
-
KeycloakModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, declarations: [CallbackComponent], imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule], exports: [CallbackComponent] });
|
|
179
|
-
KeycloakModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, providers: [DatePipe], imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule] });
|
|
180
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, decorators: [{
|
|
181
|
-
type: NgModule,
|
|
182
|
-
args: [{
|
|
183
|
-
declarations: [CallbackComponent],
|
|
184
|
-
imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule],
|
|
185
|
-
exports: [CallbackComponent],
|
|
186
|
-
providers: [DatePipe],
|
|
187
|
-
}]
|
|
188
|
-
}] });
|
|
189
89
|
|
|
190
90
|
/*
|
|
191
|
-
* Copyright 2015-
|
|
91
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
192
92
|
*
|
|
193
93
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
194
94
|
* you may not use this file except in compliance with the License.
|
|
@@ -233,17 +133,79 @@ class KeycloakAuthGuardService extends KeycloakAuthGuard {
|
|
|
233
133
|
});
|
|
234
134
|
}
|
|
235
135
|
}
|
|
236
|
-
KeycloakAuthGuardService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakAuthGuardService, deps: [{ token: i1
|
|
136
|
+
KeycloakAuthGuardService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakAuthGuardService, deps: [{ token: i1.Router }, { token: i2.KeycloakService }, { token: i3.NGXLogger }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
237
137
|
KeycloakAuthGuardService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakAuthGuardService, providedIn: 'root' });
|
|
238
138
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakAuthGuardService, decorators: [{
|
|
239
139
|
type: Injectable,
|
|
240
140
|
args: [{
|
|
241
141
|
providedIn: 'root',
|
|
242
142
|
}]
|
|
243
|
-
}], ctorParameters: function () { return [{ type: i1
|
|
143
|
+
}], ctorParameters: function () { return [{ type: i1.Router }, { type: i2.KeycloakService }, { type: i3.NGXLogger }]; } });
|
|
144
|
+
|
|
145
|
+
class KeycloakOptionsService {
|
|
146
|
+
constructor(configService) {
|
|
147
|
+
this.configService = configService;
|
|
148
|
+
this.valtimoKeycloakOptions = configService.config.authentication.options;
|
|
149
|
+
}
|
|
150
|
+
get keycloakOptions() {
|
|
151
|
+
return this.valtimoKeycloakOptions.keycloakOptions;
|
|
152
|
+
}
|
|
153
|
+
get logoutRedirectUri() {
|
|
154
|
+
return this.valtimoKeycloakOptions.logoutRedirectUri;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
KeycloakOptionsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakOptionsService, deps: [{ token: i1$1.ConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
158
|
+
KeycloakOptionsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakOptionsService, providedIn: 'root' });
|
|
159
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakOptionsService, decorators: [{
|
|
160
|
+
type: Injectable,
|
|
161
|
+
args: [{
|
|
162
|
+
providedIn: 'root',
|
|
163
|
+
}]
|
|
164
|
+
}], ctorParameters: function () { return [{ type: i1$1.ConfigService }]; } });
|
|
244
165
|
|
|
245
166
|
/*
|
|
246
|
-
* Copyright 2015-
|
|
167
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
168
|
+
*
|
|
169
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
170
|
+
* you may not use this file except in compliance with the License.
|
|
171
|
+
* You may obtain a copy of the License at
|
|
172
|
+
*
|
|
173
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
174
|
+
*
|
|
175
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
176
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
177
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
178
|
+
* See the License for the specific language governing permissions and
|
|
179
|
+
* limitations under the License.
|
|
180
|
+
*/
|
|
181
|
+
class KeycloakStorageService {
|
|
182
|
+
getCurrentUrlParams() {
|
|
183
|
+
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
184
|
+
const params = Object.fromEntries(urlSearchParams.entries());
|
|
185
|
+
return JSON.stringify(params);
|
|
186
|
+
}
|
|
187
|
+
getCurrentUrl() {
|
|
188
|
+
return window.location.pathname;
|
|
189
|
+
}
|
|
190
|
+
parseSavedParams(savedParams) {
|
|
191
|
+
return ((savedParams &&
|
|
192
|
+
typeof savedParams === 'string' &&
|
|
193
|
+
savedParams.length > 2 &&
|
|
194
|
+
JSON.parse(savedParams)) ||
|
|
195
|
+
{});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
KeycloakStorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
199
|
+
KeycloakStorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakStorageService, providedIn: 'root' });
|
|
200
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakStorageService, decorators: [{
|
|
201
|
+
type: Injectable,
|
|
202
|
+
args: [{
|
|
203
|
+
providedIn: 'root',
|
|
204
|
+
}]
|
|
205
|
+
}] });
|
|
206
|
+
|
|
207
|
+
/*
|
|
208
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
247
209
|
*
|
|
248
210
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
249
211
|
* you may not use this file except in compliance with the License.
|
|
@@ -258,13 +220,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
|
|
|
258
220
|
* limitations under the License.
|
|
259
221
|
*/
|
|
260
222
|
class KeycloakUserService {
|
|
261
|
-
constructor(keycloakService, keycloakOptionsService, logger, promptService, translateService, datePipe) {
|
|
223
|
+
constructor(keycloakService, keycloakOptionsService, logger, promptService, translateService, datePipe, configService, router, keycloakStorageService) {
|
|
262
224
|
this.keycloakService = keycloakService;
|
|
263
225
|
this.keycloakOptionsService = keycloakOptionsService;
|
|
264
226
|
this.logger = logger;
|
|
265
227
|
this.promptService = promptService;
|
|
266
228
|
this.translateService = translateService;
|
|
267
229
|
this.datePipe = datePipe;
|
|
230
|
+
this.configService = configService;
|
|
231
|
+
this.router = router;
|
|
232
|
+
this.keycloakStorageService = keycloakStorageService;
|
|
268
233
|
this._refreshToken$ = new Subject();
|
|
269
234
|
this.FIVE_MINUTES_MS = 300000;
|
|
270
235
|
this.EXPIRE_TOKEN_CONFIRMATION = 'EXPIRE_TOKEN_CONFIRMATION';
|
|
@@ -350,30 +315,14 @@ class KeycloakUserService {
|
|
|
350
315
|
this.promptService.identifier$.pipe(take(1)).subscribe(identifier => {
|
|
351
316
|
if ((!promptVisible || identifier !== this.EXPIRE_TOKEN_CONFIRMATION) &&
|
|
352
317
|
this._expiryTimeMs <= this.FIVE_MINUTES_MS) {
|
|
353
|
-
this.
|
|
354
|
-
identifier: this.EXPIRE_TOKEN_CONFIRMATION,
|
|
355
|
-
headerText,
|
|
356
|
-
bodyText,
|
|
357
|
-
cancelButtonText,
|
|
358
|
-
confirmButtonText,
|
|
359
|
-
cancelMdiIcon: 'logout',
|
|
360
|
-
confirmMdiIcon: 'check',
|
|
361
|
-
closeOnConfirm: true,
|
|
362
|
-
closeOnCancel: false,
|
|
363
|
-
cancelCallbackFunction: () => {
|
|
364
|
-
this.keycloakService.logout();
|
|
365
|
-
},
|
|
366
|
-
confirmCallBackFunction: () => {
|
|
367
|
-
this.closeExpiryTimerSubscription();
|
|
368
|
-
this.updateToken(20);
|
|
369
|
-
},
|
|
370
|
-
});
|
|
318
|
+
this.openConfirmationPrompt(headerText, bodyText, cancelButtonText, confirmButtonText);
|
|
371
319
|
}
|
|
372
320
|
if (promptVisible && identifier === this.EXPIRE_TOKEN_CONFIRMATION) {
|
|
373
321
|
this.promptService.setBodyText(bodyText);
|
|
374
322
|
}
|
|
375
323
|
});
|
|
376
324
|
if (this._expiryTimeMs < 2000) {
|
|
325
|
+
this.saveUrl();
|
|
377
326
|
this.logout();
|
|
378
327
|
}
|
|
379
328
|
});
|
|
@@ -381,18 +330,183 @@ class KeycloakUserService {
|
|
|
381
330
|
closeExpiryTimerSubscription() {
|
|
382
331
|
this.expiryTimerSubscription?.unsubscribe();
|
|
383
332
|
}
|
|
333
|
+
openConfirmationPrompt(headerText, bodyText, cancelButtonText, confirmButtonText) {
|
|
334
|
+
this.promptService.openPrompt({
|
|
335
|
+
identifier: this.EXPIRE_TOKEN_CONFIRMATION,
|
|
336
|
+
headerText,
|
|
337
|
+
bodyText,
|
|
338
|
+
cancelButtonText,
|
|
339
|
+
confirmButtonText,
|
|
340
|
+
cancelMdiIcon: 'logout',
|
|
341
|
+
confirmMdiIcon: 'check',
|
|
342
|
+
closeOnConfirm: true,
|
|
343
|
+
closeOnCancel: false,
|
|
344
|
+
cancelCallbackFunction: () => {
|
|
345
|
+
this.keycloakService.logout();
|
|
346
|
+
},
|
|
347
|
+
confirmCallBackFunction: () => {
|
|
348
|
+
this.closeExpiryTimerSubscription();
|
|
349
|
+
this.updateToken(20);
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
saveUrl() {
|
|
354
|
+
const returnToLastUrlAfterTokenExpiration = this.configService?.config?.featureToggles?.returnToLastUrlAfterTokenExpiration;
|
|
355
|
+
if (returnToLastUrlAfterTokenExpiration) {
|
|
356
|
+
sessionStorage.setItem(STORAGE_KEYS.urlBeforeExpiration, this.keycloakStorageService.getCurrentUrl());
|
|
357
|
+
sessionStorage.setItem(STORAGE_KEYS.urlBeforeExpirationParams, this.keycloakStorageService.getCurrentUrlParams());
|
|
358
|
+
}
|
|
359
|
+
}
|
|
384
360
|
}
|
|
385
|
-
KeycloakUserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakUserService, deps: [{ token: i2.KeycloakService }, { token: KeycloakOptionsService }, { token: i3.NGXLogger }, { token: i4.PromptService }, { token: i5.TranslateService }, { token: i6.DatePipe }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
361
|
+
KeycloakUserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakUserService, deps: [{ token: i2.KeycloakService }, { token: KeycloakOptionsService }, { token: i3.NGXLogger }, { token: i4.PromptService }, { token: i5.TranslateService }, { token: i6.DatePipe }, { token: i1$1.ConfigService }, { token: i1.Router }, { token: KeycloakStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
386
362
|
KeycloakUserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakUserService, providedIn: 'root' });
|
|
387
363
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakUserService, decorators: [{
|
|
388
364
|
type: Injectable,
|
|
389
365
|
args: [{
|
|
390
366
|
providedIn: 'root',
|
|
391
367
|
}]
|
|
392
|
-
}], ctorParameters: function () { return [{ type: i2.KeycloakService }, { type: KeycloakOptionsService }, { type: i3.NGXLogger }, { type: i4.PromptService }, { type: i5.TranslateService }, { type: i6.DatePipe }]; } });
|
|
368
|
+
}], ctorParameters: function () { return [{ type: i2.KeycloakService }, { type: KeycloakOptionsService }, { type: i3.NGXLogger }, { type: i4.PromptService }, { type: i5.TranslateService }, { type: i6.DatePipe }, { type: i1$1.ConfigService }, { type: i1.Router }, { type: KeycloakStorageService }]; } });
|
|
369
|
+
|
|
370
|
+
/*
|
|
371
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
372
|
+
*
|
|
373
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
374
|
+
* you may not use this file except in compliance with the License.
|
|
375
|
+
* You may obtain a copy of the License at
|
|
376
|
+
*
|
|
377
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
378
|
+
*
|
|
379
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
380
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
381
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
382
|
+
* See the License for the specific language governing permissions and
|
|
383
|
+
* limitations under the License.
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
/*
|
|
387
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
388
|
+
*
|
|
389
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
390
|
+
* you may not use this file except in compliance with the License.
|
|
391
|
+
* You may obtain a copy of the License at
|
|
392
|
+
*
|
|
393
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
394
|
+
*
|
|
395
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
396
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
397
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
398
|
+
* See the License for the specific language governing permissions and
|
|
399
|
+
* limitations under the License.
|
|
400
|
+
*/
|
|
401
|
+
class CallbackComponent {
|
|
402
|
+
constructor(router, keycloakOptionsService, logger, keycloakStorageService) {
|
|
403
|
+
this.router = router;
|
|
404
|
+
this.keycloakOptionsService = keycloakOptionsService;
|
|
405
|
+
this.logger = logger;
|
|
406
|
+
this.keycloakStorageService = keycloakStorageService;
|
|
407
|
+
logger.debug('callback');
|
|
408
|
+
const savedRedirectTo = window.sessionStorage.getItem(STORAGE_KEYS.redirectTo);
|
|
409
|
+
const savedRedirectToParams = window.sessionStorage.getItem(STORAGE_KEYS.redirectToParams);
|
|
410
|
+
const parsedSavedRedirectToParams = this.keycloakStorageService.parseSavedParams(savedRedirectToParams);
|
|
411
|
+
const urlBeforeExpiration = sessionStorage.getItem(STORAGE_KEYS.urlBeforeExpiration);
|
|
412
|
+
const paramsBeforeExpiration = sessionStorage.getItem(STORAGE_KEYS.urlBeforeExpirationParams);
|
|
413
|
+
const parsedParamsBeforeExpiration = this.keycloakStorageService.parseSavedParams(paramsBeforeExpiration);
|
|
414
|
+
let redirectTo;
|
|
415
|
+
if (savedRedirectTo) {
|
|
416
|
+
redirectTo = savedRedirectTo;
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
redirectTo = '/';
|
|
420
|
+
}
|
|
421
|
+
logger.debug('keycloak callback redirect =', redirectTo);
|
|
422
|
+
logger.debug('keycloak callback redirect params =', savedRedirectToParams);
|
|
423
|
+
if (STORAGE_KEYS.urlBeforeExpiration in sessionStorage) {
|
|
424
|
+
this.router.navigate([urlBeforeExpiration], { queryParams: parsedParamsBeforeExpiration });
|
|
425
|
+
sessionStorage.removeItem(STORAGE_KEYS.urlBeforeExpiration);
|
|
426
|
+
sessionStorage.removeItem(STORAGE_KEYS.urlBeforeExpirationParams);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
this.router.navigate([redirectTo], { queryParams: parsedSavedRedirectToParams });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
CallbackComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CallbackComponent, deps: [{ token: i1.Router }, { token: KeycloakOptionsService }, { token: i3.NGXLogger }, { token: KeycloakStorageService }], target: i0.ɵɵFactoryTarget.Component });
|
|
434
|
+
CallbackComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.12", type: CallbackComponent, selector: "valtimo-keycloak-callback", ngImport: i0, template: '', isInline: true });
|
|
435
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CallbackComponent, decorators: [{
|
|
436
|
+
type: Component,
|
|
437
|
+
args: [{
|
|
438
|
+
selector: 'valtimo-keycloak-callback',
|
|
439
|
+
template: '',
|
|
440
|
+
}]
|
|
441
|
+
}], ctorParameters: function () { return [{ type: i1.Router }, { type: KeycloakOptionsService }, { type: i3.NGXLogger }, { type: KeycloakStorageService }]; } });
|
|
442
|
+
|
|
443
|
+
/*
|
|
444
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
445
|
+
*
|
|
446
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
447
|
+
* you may not use this file except in compliance with the License.
|
|
448
|
+
* You may obtain a copy of the License at
|
|
449
|
+
*
|
|
450
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
451
|
+
*
|
|
452
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
453
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
454
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
455
|
+
* See the License for the specific language governing permissions and
|
|
456
|
+
* limitations under the License.
|
|
457
|
+
*/
|
|
458
|
+
const routes = [
|
|
459
|
+
{
|
|
460
|
+
path: 'keycloak/callback',
|
|
461
|
+
component: CallbackComponent,
|
|
462
|
+
data: { title: 'Loading...' },
|
|
463
|
+
},
|
|
464
|
+
];
|
|
465
|
+
class KeycloakRoutingModule {
|
|
466
|
+
}
|
|
467
|
+
KeycloakRoutingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
468
|
+
KeycloakRoutingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, imports: [CommonModule, i1.RouterModule], exports: [RouterModule] });
|
|
469
|
+
KeycloakRoutingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, imports: [CommonModule, RouterModule.forChild(routes), RouterModule] });
|
|
470
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakRoutingModule, decorators: [{
|
|
471
|
+
type: NgModule,
|
|
472
|
+
args: [{
|
|
473
|
+
imports: [CommonModule, RouterModule.forChild(routes)],
|
|
474
|
+
exports: [RouterModule],
|
|
475
|
+
}]
|
|
476
|
+
}] });
|
|
477
|
+
|
|
478
|
+
/*
|
|
479
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
480
|
+
*
|
|
481
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
482
|
+
* you may not use this file except in compliance with the License.
|
|
483
|
+
* You may obtain a copy of the License at
|
|
484
|
+
*
|
|
485
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
486
|
+
*
|
|
487
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
488
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
489
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
490
|
+
* See the License for the specific language governing permissions and
|
|
491
|
+
* limitations under the License.
|
|
492
|
+
*/
|
|
493
|
+
class KeycloakModule {
|
|
494
|
+
}
|
|
495
|
+
KeycloakModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
496
|
+
KeycloakModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, declarations: [CallbackComponent], imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule], exports: [CallbackComponent] });
|
|
497
|
+
KeycloakModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, providers: [DatePipe], imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule] });
|
|
498
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: KeycloakModule, decorators: [{
|
|
499
|
+
type: NgModule,
|
|
500
|
+
args: [{
|
|
501
|
+
declarations: [CallbackComponent],
|
|
502
|
+
imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule],
|
|
503
|
+
exports: [CallbackComponent],
|
|
504
|
+
providers: [DatePipe],
|
|
505
|
+
}]
|
|
506
|
+
}] });
|
|
393
507
|
|
|
394
508
|
/*
|
|
395
|
-
* Copyright 2015-
|
|
509
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
396
510
|
*
|
|
397
511
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
398
512
|
* you may not use this file except in compliance with the License.
|
|
@@ -410,6 +524,7 @@ function keycloakInitializer(injector) {
|
|
|
410
524
|
const keycloakService = injector.get(KeycloakService);
|
|
411
525
|
const keycloakUserService = injector.get(KeycloakUserService);
|
|
412
526
|
const optionsService = injector.get(KeycloakOptionsService); // TODO possible removal of abstraction
|
|
527
|
+
const storageService = injector.get(KeycloakStorageService);
|
|
413
528
|
const logger = injector.get(NGXLogger);
|
|
414
529
|
return async () => {
|
|
415
530
|
try {
|
|
@@ -417,12 +532,10 @@ function keycloakInitializer(injector) {
|
|
|
417
532
|
const keycloakOptions = optionsService.keycloakOptions;
|
|
418
533
|
const currentUrl = window.location.href.split('#')[0];
|
|
419
534
|
if (keycloakOptions.initOptions.redirectUri !== currentUrl) {
|
|
420
|
-
const redirectTo =
|
|
421
|
-
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
422
|
-
const params = Object.fromEntries(urlSearchParams.entries());
|
|
535
|
+
const redirectTo = storageService.getCurrentUrl();
|
|
423
536
|
logger.debug('Setting redirectTo =', redirectTo);
|
|
424
|
-
window.sessionStorage.setItem(
|
|
425
|
-
window.sessionStorage.setItem(
|
|
537
|
+
window.sessionStorage.setItem(STORAGE_KEYS.redirectTo, redirectTo);
|
|
538
|
+
window.sessionStorage.setItem(STORAGE_KEYS.redirectToParams, storageService.getCurrentUrlParams());
|
|
426
539
|
}
|
|
427
540
|
const initResult = await keycloakService.init(keycloakOptions);
|
|
428
541
|
logger.debug('Keycloak initializer after init');
|
|
@@ -437,7 +550,7 @@ function keycloakInitializer(injector) {
|
|
|
437
550
|
}
|
|
438
551
|
|
|
439
552
|
/*
|
|
440
|
-
* Copyright 2015-
|
|
553
|
+
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
441
554
|
*
|
|
442
555
|
* Licensed under EUPL, Version 1.2 (the "License");
|
|
443
556
|
* you may not use this file except in compliance with the License.
|
|
@@ -456,5 +569,5 @@ function keycloakInitializer(injector) {
|
|
|
456
569
|
* Generated bundle index. Do not edit.
|
|
457
570
|
*/
|
|
458
571
|
|
|
459
|
-
export { CallbackComponent, KeycloakAuthGuardService, KeycloakModule, KeycloakOptionsService, KeycloakUserService, keycloakInitializer };
|
|
572
|
+
export { CallbackComponent, KeycloakAuthGuardService, KeycloakModule, KeycloakOptionsService, KeycloakUserService, STORAGE_KEYS, keycloakInitializer };
|
|
460
573
|
//# sourceMappingURL=valtimo-keycloak.mjs.map
|