@valtimo/keycloak 10.7.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{esm2020 → esm2022}/lib/callback.component.mjs +4 -4
- package/{esm2020 → esm2022}/lib/keycloak-routing.module.mjs +5 -5
- package/{esm2020 → esm2022}/lib/keycloak.module.mjs +5 -5
- package/{esm2020 → esm2022}/lib/services/keycloak-auth-guard.service.mjs +4 -4
- package/{esm2020 → esm2022}/lib/services/keycloak-options.service.mjs +4 -4
- package/{esm2020 → esm2022}/lib/services/keycloak-storage.service.mjs +4 -4
- package/{esm2020 → esm2022}/lib/services/keycloak-user.service.mjs +5 -5
- package/{fesm2020 → fesm2022}/valtimo-keycloak.mjs +27 -24
- package/fesm2022/valtimo-keycloak.mjs.map +1 -0
- package/lib/callback.component.d.ts +1 -1
- package/lib/services/keycloak-user.service.d.ts +1 -1
- package/lib/services/keycloak-user.service.d.ts.map +1 -1
- package/package.json +10 -16
- package/fesm2015/valtimo-keycloak.mjs +0 -534
- package/fesm2015/valtimo-keycloak.mjs.map +0 -1
- package/fesm2020/valtimo-keycloak.mjs.map +0 -1
- /package/{esm2020 → esm2022}/lib/constants/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/constants/storage-keys.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/keycloak.init.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/models/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/models/keycloak.config.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/services/index.mjs +0 -0
- /package/{esm2020 → esm2022}/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/valtimo-keycloak.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keycloak-user.service.d.ts","sourceRoot":"","sources":["../../../../../projects/valtimo/keycloak/src/lib/services/keycloak-user.service.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAa,SAAS,EAAC,MAAM,eAAe,CAAC;AACpD,OAAO,EAAqB,aAAa,EAA0C,MAAM,MAAM,CAAC;AAChG,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,EAAoB,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAC,aAAa,EAAE,YAAY,EAAE,WAAW,EAAsB,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAC,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"keycloak-user.service.d.ts","sourceRoot":"","sources":["../../../../../projects/valtimo/keycloak/src/lib/services/keycloak-user.service.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAa,SAAS,EAAC,MAAM,eAAe,CAAC;AACpD,OAAO,EAAqB,aAAa,EAA0C,MAAM,MAAM,CAAC;AAChG,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,EAAoB,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAC,aAAa,EAAE,YAAY,EAAE,WAAW,EAAsB,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAC,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAC,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;;AAElD,qBAGa,mBAAoB,YAAW,WAAW,EAAE,SAAS;IAiB9D,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IAxBzC,OAAO,CAAC,YAAY,CAA8B;IAElD,OAAO,CAAC,wBAAwB,CAAgB;IAChD,OAAO,CAAC,wBAAwB,CAAgB;IAChD,OAAO,CAAC,uBAAuB,CAAgB;IAE/C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;IAExD,OAAO,CAAC,aAAa,CAAU;IAE/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;IAC1C,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAA+B;IAEzE,OAAO,CAAC,QAAQ,CAAQ;gBAGL,eAAe,EAAE,eAAe,EAChC,sBAAsB,EAAE,sBAAsB,EAC9C,MAAM,EAAE,SAAS,EACjB,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,sBAAsB,EAAE,sBAAsB;IAMjE,WAAW,IAAI,IAAI;IAMnB,IAAI,IAAI,IAAI;IAmBZ,cAAc,IAAI,aAAa,CAAC,YAAY,CAAC;IAK7C,MAAM,IAAI,IAAI;IAKR,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAK3B,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxD,OAAO,CAAC,4BAA4B;IAUpC,OAAO,CAAC,4BAA4B;IAYpC,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,2BAA2B;IA6CnC,OAAO,CAAC,4BAA4B;IAIpC,OAAO,CAAC,sBAAsB;IA0B9B,OAAO,CAAC,OAAO;yCAlLJ,mBAAmB;6CAAnB,mBAAmB;CAiM/B"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valtimo/keycloak",
|
|
3
3
|
"license": "EUPL-1.2",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "11.0.0",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@angular/common": "^
|
|
7
|
-
"@angular/core": "^
|
|
6
|
+
"@angular/common": "^16.2.0",
|
|
7
|
+
"@angular/core": "^16.2.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"keycloak-angular": "
|
|
11
|
-
"keycloak-js": "
|
|
12
|
-
"tslib": "
|
|
10
|
+
"keycloak-angular": "14.0.0",
|
|
11
|
+
"keycloak-js": "22.0.1",
|
|
12
|
+
"tslib": "2.6.2"
|
|
13
13
|
},
|
|
14
|
-
"module": "
|
|
15
|
-
"es2020": "fesm2020/valtimo-keycloak.mjs",
|
|
16
|
-
"esm2020": "esm2020/valtimo-keycloak.mjs",
|
|
17
|
-
"fesm2020": "fesm2020/valtimo-keycloak.mjs",
|
|
18
|
-
"fesm2015": "fesm2015/valtimo-keycloak.mjs",
|
|
14
|
+
"module": "fesm2022/valtimo-keycloak.mjs",
|
|
19
15
|
"typings": "index.d.ts",
|
|
20
16
|
"exports": {
|
|
21
17
|
"./package.json": {
|
|
@@ -23,11 +19,9 @@
|
|
|
23
19
|
},
|
|
24
20
|
".": {
|
|
25
21
|
"types": "./index.d.ts",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"node": "./fesm2015/valtimo-keycloak.mjs",
|
|
30
|
-
"default": "./fesm2020/valtimo-keycloak.mjs"
|
|
22
|
+
"esm2022": "./esm2022/valtimo-keycloak.mjs",
|
|
23
|
+
"esm": "./esm2022/valtimo-keycloak.mjs",
|
|
24
|
+
"default": "./fesm2022/valtimo-keycloak.mjs"
|
|
31
25
|
}
|
|
32
26
|
},
|
|
33
27
|
"sideEffects": false
|
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Component, NgModule } from '@angular/core';
|
|
3
|
-
import * as i2 from 'keycloak-angular';
|
|
4
|
-
import { KeycloakAuthGuard, KeycloakEventType, KeycloakAngularModule, KeycloakService } from 'keycloak-angular';
|
|
5
|
-
import * as i1 from '@angular/router';
|
|
6
|
-
import { RouterModule } from '@angular/router';
|
|
7
|
-
import * as i3 from 'ngx-logger';
|
|
8
|
-
import { NGXLogger } from 'ngx-logger';
|
|
9
|
-
import * as i1$1 from '@valtimo/config';
|
|
10
|
-
import { ValtimoUserIdentity } from '@valtimo/config';
|
|
11
|
-
import { __awaiter } from 'tslib';
|
|
12
|
-
import { Subject, ReplaySubject, timer, map, switchMap, combineLatest } from 'rxjs';
|
|
13
|
-
import jwt_decode from 'jwt-decode';
|
|
14
|
-
import { take } from 'rxjs/operators';
|
|
15
|
-
import * as i4 from '@valtimo/user-interface';
|
|
16
|
-
import * as i5 from '@ngx-translate/core';
|
|
17
|
-
import { TranslateModule } from '@ngx-translate/core';
|
|
18
|
-
import * as i6 from '@angular/common';
|
|
19
|
-
import { CommonModule, DatePipe } from '@angular/common';
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
23
|
-
*
|
|
24
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
25
|
-
* you may not use this file except in compliance with the License.
|
|
26
|
-
* You may obtain a copy of the License at
|
|
27
|
-
*
|
|
28
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
29
|
-
*
|
|
30
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
31
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
32
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
33
|
-
* See the License for the specific language governing permissions and
|
|
34
|
-
* limitations under the License.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/*
|
|
38
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
39
|
-
*
|
|
40
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
41
|
-
* you may not use this file except in compliance with the License.
|
|
42
|
-
* You may obtain a copy of the License at
|
|
43
|
-
*
|
|
44
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
45
|
-
*
|
|
46
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
47
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
48
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
49
|
-
* See the License for the specific language governing permissions and
|
|
50
|
-
* limitations under the License.
|
|
51
|
-
*/
|
|
52
|
-
const STORAGE_KEYS = {
|
|
53
|
-
urlBeforeExpiration: 'urlBeforeExpiration',
|
|
54
|
-
urlBeforeExpirationParams: 'urlBeforeExpirationParams',
|
|
55
|
-
redirectTo: 'redirectTo',
|
|
56
|
-
redirectToParams: 'redirectToParams',
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
61
|
-
*
|
|
62
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
63
|
-
* you may not use this file except in compliance with the License.
|
|
64
|
-
* You may obtain a copy of the License at
|
|
65
|
-
*
|
|
66
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
67
|
-
*
|
|
68
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
69
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
70
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
71
|
-
* See the License for the specific language governing permissions and
|
|
72
|
-
* limitations under the License.
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/*
|
|
76
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
77
|
-
*
|
|
78
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
79
|
-
* you may not use this file except in compliance with the License.
|
|
80
|
-
* You may obtain a copy of the License at
|
|
81
|
-
*
|
|
82
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
83
|
-
*
|
|
84
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
85
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
86
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
87
|
-
* See the License for the specific language governing permissions and
|
|
88
|
-
* limitations under the License.
|
|
89
|
-
*/
|
|
90
|
-
class KeycloakAuthGuardService extends KeycloakAuthGuard {
|
|
91
|
-
constructor(router, keycloakAngular, logger) {
|
|
92
|
-
super(router, keycloakAngular);
|
|
93
|
-
this.router = router;
|
|
94
|
-
this.keycloakAngular = keycloakAngular;
|
|
95
|
-
this.logger = logger;
|
|
96
|
-
this.logger.debug('KeycloakAuthGuardService: ctor');
|
|
97
|
-
}
|
|
98
|
-
isAccessAllowed(route, state) {
|
|
99
|
-
this.logger.debug('KeycloakAuthGuardService: isAccessAllowed');
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
this.logger.debug('KeycloakAuthGuardService: isAccessAllowed checking access');
|
|
102
|
-
if (!this.authenticated) {
|
|
103
|
-
this.keycloakAngular
|
|
104
|
-
.login()
|
|
105
|
-
.catch(e => `KeycloakAuthGuardService error: ${this.logger.error(e)}`);
|
|
106
|
-
return reject(false);
|
|
107
|
-
}
|
|
108
|
-
const requiredRoles = route.data.roles;
|
|
109
|
-
if (!requiredRoles || requiredRoles.length === 0) {
|
|
110
|
-
return resolve(true);
|
|
111
|
-
}
|
|
112
|
-
if (!this.roles || this.roles.length === 0) {
|
|
113
|
-
resolve(false);
|
|
114
|
-
}
|
|
115
|
-
resolve(requiredRoles.some(role => this.roles.includes(role)));
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
KeycloakAuthGuardService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakAuthGuardService, deps: [{ token: i1.Router }, { token: i2.KeycloakService }, { token: i3.NGXLogger }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
120
|
-
KeycloakAuthGuardService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakAuthGuardService, providedIn: 'root' });
|
|
121
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakAuthGuardService, decorators: [{
|
|
122
|
-
type: Injectable,
|
|
123
|
-
args: [{
|
|
124
|
-
providedIn: 'root',
|
|
125
|
-
}]
|
|
126
|
-
}], ctorParameters: function () { return [{ type: i1.Router }, { type: i2.KeycloakService }, { type: i3.NGXLogger }]; } });
|
|
127
|
-
|
|
128
|
-
class KeycloakOptionsService {
|
|
129
|
-
constructor(configService) {
|
|
130
|
-
this.configService = configService;
|
|
131
|
-
this.valtimoKeycloakOptions = configService.config.authentication.options;
|
|
132
|
-
}
|
|
133
|
-
get keycloakOptions() {
|
|
134
|
-
return this.valtimoKeycloakOptions.keycloakOptions;
|
|
135
|
-
}
|
|
136
|
-
get logoutRedirectUri() {
|
|
137
|
-
return this.valtimoKeycloakOptions.logoutRedirectUri;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
KeycloakOptionsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakOptionsService, deps: [{ token: i1$1.ConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
141
|
-
KeycloakOptionsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakOptionsService, providedIn: 'root' });
|
|
142
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakOptionsService, decorators: [{
|
|
143
|
-
type: Injectable,
|
|
144
|
-
args: [{
|
|
145
|
-
providedIn: 'root',
|
|
146
|
-
}]
|
|
147
|
-
}], ctorParameters: function () { return [{ type: i1$1.ConfigService }]; } });
|
|
148
|
-
|
|
149
|
-
/*
|
|
150
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
151
|
-
*
|
|
152
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
153
|
-
* you may not use this file except in compliance with the License.
|
|
154
|
-
* You may obtain a copy of the License at
|
|
155
|
-
*
|
|
156
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
157
|
-
*
|
|
158
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
159
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
160
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
161
|
-
* See the License for the specific language governing permissions and
|
|
162
|
-
* limitations under the License.
|
|
163
|
-
*/
|
|
164
|
-
class KeycloakStorageService {
|
|
165
|
-
getCurrentUrlParams() {
|
|
166
|
-
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
167
|
-
const params = Object.fromEntries(urlSearchParams.entries());
|
|
168
|
-
return JSON.stringify(params);
|
|
169
|
-
}
|
|
170
|
-
getCurrentUrl() {
|
|
171
|
-
return window.location.pathname;
|
|
172
|
-
}
|
|
173
|
-
parseSavedParams(savedParams) {
|
|
174
|
-
return ((savedParams &&
|
|
175
|
-
typeof savedParams === 'string' &&
|
|
176
|
-
savedParams.length > 2 &&
|
|
177
|
-
JSON.parse(savedParams)) ||
|
|
178
|
-
{});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
KeycloakStorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
182
|
-
KeycloakStorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakStorageService, providedIn: 'root' });
|
|
183
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakStorageService, decorators: [{
|
|
184
|
-
type: Injectable,
|
|
185
|
-
args: [{
|
|
186
|
-
providedIn: 'root',
|
|
187
|
-
}]
|
|
188
|
-
}] });
|
|
189
|
-
|
|
190
|
-
class KeycloakUserService {
|
|
191
|
-
constructor(keycloakService, keycloakOptionsService, logger, promptService, translateService, datePipe, configService, router, keycloakStorageService) {
|
|
192
|
-
this.keycloakService = keycloakService;
|
|
193
|
-
this.keycloakOptionsService = keycloakOptionsService;
|
|
194
|
-
this.logger = logger;
|
|
195
|
-
this.promptService = promptService;
|
|
196
|
-
this.translateService = translateService;
|
|
197
|
-
this.datePipe = datePipe;
|
|
198
|
-
this.configService = configService;
|
|
199
|
-
this.router = router;
|
|
200
|
-
this.keycloakStorageService = keycloakStorageService;
|
|
201
|
-
this._refreshToken$ = new Subject();
|
|
202
|
-
this.FIVE_MINUTES_MS = 300000;
|
|
203
|
-
this.EXPIRE_TOKEN_CONFIRMATION = 'EXPIRE_TOKEN_CONFIRMATION';
|
|
204
|
-
this.openTokenRefreshSubscription();
|
|
205
|
-
this.openRefreshTokenSubscription();
|
|
206
|
-
}
|
|
207
|
-
ngOnDestroy() {
|
|
208
|
-
var _a, _b;
|
|
209
|
-
(_a = this.tokenRefreshSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
210
|
-
(_b = this.refreshTokenSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
211
|
-
this.closeExpiryTimerSubscription();
|
|
212
|
-
}
|
|
213
|
-
init() {
|
|
214
|
-
this.userIdentity = new ReplaySubject();
|
|
215
|
-
this.keycloakService.loadUserProfile().then(user => {
|
|
216
|
-
this.logger.debug('KeycloakUserService: loadUserProfile = ', user);
|
|
217
|
-
const roles = [];
|
|
218
|
-
this.keycloakService.getUserRoles(true).forEach(role => roles.push(role));
|
|
219
|
-
const valtimoUserIdentity = new ValtimoUserIdentity(user.email, user.firstName, user.lastName, roles, user.username);
|
|
220
|
-
this.logger.debug('KeycloakUserService: loaded user identity', valtimoUserIdentity);
|
|
221
|
-
this.userIdentity.next(valtimoUserIdentity);
|
|
222
|
-
});
|
|
223
|
-
this.setRefreshToken();
|
|
224
|
-
}
|
|
225
|
-
getUserSubject() {
|
|
226
|
-
this.logger.debug('KeycloakUserService: getUserIdentity');
|
|
227
|
-
return this.userIdentity;
|
|
228
|
-
}
|
|
229
|
-
logout() {
|
|
230
|
-
this.logger.debug('KeycloakUserService: logout');
|
|
231
|
-
this.keycloakService.logout(this.keycloakOptionsService.logoutRedirectUri);
|
|
232
|
-
}
|
|
233
|
-
getToken() {
|
|
234
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
this.logger.debug('KeycloakUserService: getToken');
|
|
236
|
-
return this.keycloakService.getToken();
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
updateToken(minValidity) {
|
|
240
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
this.logger.debug('KeycloakUserService: updateToken');
|
|
242
|
-
return this.keycloakService.updateToken(minValidity);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
openTokenRefreshSubscription() {
|
|
246
|
-
this.tokenRefreshSubscription = this.keycloakService.keycloakEvents$.subscribe(keycloakEvent => {
|
|
247
|
-
if (keycloakEvent.type === KeycloakEventType.OnAuthRefreshSuccess) {
|
|
248
|
-
this.setRefreshToken();
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
openRefreshTokenSubscription() {
|
|
253
|
-
this.refreshTokenSubscription = this._refreshToken$.subscribe(refreshToken => {
|
|
254
|
-
const decodedRefreshToken = jwt_decode(refreshToken);
|
|
255
|
-
const tokenExp = decodedRefreshToken.exp * 1000;
|
|
256
|
-
const expiryTimeMs = tokenExp - Date.now() - 1000;
|
|
257
|
-
this._expiryTimeMs = expiryTimeMs;
|
|
258
|
-
this.closeExpiryTimerSubscription();
|
|
259
|
-
this.openExpiryTimerSubscription();
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
setRefreshToken() {
|
|
263
|
-
var _a;
|
|
264
|
-
const refreshToken = (_a = this.keycloakService.getKeycloakInstance()) === null || _a === void 0 ? void 0 : _a.refreshToken;
|
|
265
|
-
if (refreshToken)
|
|
266
|
-
this._refreshToken$.next(refreshToken);
|
|
267
|
-
}
|
|
268
|
-
openExpiryTimerSubscription() {
|
|
269
|
-
this.expiryTimerSubscription = timer(0, 1000)
|
|
270
|
-
.pipe(map(() => {
|
|
271
|
-
this._expiryTimeMs = this._expiryTimeMs - 1000;
|
|
272
|
-
return this._expiryTimeMs;
|
|
273
|
-
}), switchMap(expiryTimeMs => {
|
|
274
|
-
if (expiryTimeMs <= this.FIVE_MINUTES_MS) {
|
|
275
|
-
this._counter = new Date(0, 0, 0, 0, 0, 0);
|
|
276
|
-
this._counter.setSeconds(expiryTimeMs / 1000);
|
|
277
|
-
}
|
|
278
|
-
return combineLatest([
|
|
279
|
-
this.promptService.promptVisible$,
|
|
280
|
-
this.translateService.stream('keycloak.expiryPromptTitle'),
|
|
281
|
-
this.translateService.stream('keycloak.expiryPromptDescription', {
|
|
282
|
-
expiryTime: this.datePipe.transform(this._counter, 'mm:ss'),
|
|
283
|
-
}),
|
|
284
|
-
this.translateService.stream('keycloak.expiryPromptCancel'),
|
|
285
|
-
this.translateService.stream('keycloak.expiryPromptConfirm'),
|
|
286
|
-
]);
|
|
287
|
-
}))
|
|
288
|
-
.subscribe(([promptVisible, headerText, bodyText, cancelButtonText, confirmButtonText]) => {
|
|
289
|
-
this.promptService.identifier$.pipe(take(1)).subscribe(identifier => {
|
|
290
|
-
if ((!promptVisible || identifier !== this.EXPIRE_TOKEN_CONFIRMATION) &&
|
|
291
|
-
this._expiryTimeMs <= this.FIVE_MINUTES_MS) {
|
|
292
|
-
this.openConfirmationPrompt(headerText, bodyText, cancelButtonText, confirmButtonText);
|
|
293
|
-
}
|
|
294
|
-
if (promptVisible && identifier === this.EXPIRE_TOKEN_CONFIRMATION) {
|
|
295
|
-
this.promptService.setBodyText(bodyText);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
if (this._expiryTimeMs < 2000) {
|
|
299
|
-
this.saveUrl();
|
|
300
|
-
this.logout();
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
closeExpiryTimerSubscription() {
|
|
305
|
-
var _a;
|
|
306
|
-
(_a = this.expiryTimerSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
307
|
-
}
|
|
308
|
-
openConfirmationPrompt(headerText, bodyText, cancelButtonText, confirmButtonText) {
|
|
309
|
-
this.promptService.openPrompt({
|
|
310
|
-
identifier: this.EXPIRE_TOKEN_CONFIRMATION,
|
|
311
|
-
headerText,
|
|
312
|
-
bodyText,
|
|
313
|
-
cancelButtonText,
|
|
314
|
-
confirmButtonText,
|
|
315
|
-
cancelMdiIcon: 'logout',
|
|
316
|
-
confirmMdiIcon: 'check',
|
|
317
|
-
closeOnConfirm: true,
|
|
318
|
-
closeOnCancel: false,
|
|
319
|
-
cancelCallbackFunction: () => {
|
|
320
|
-
this.keycloakService.logout();
|
|
321
|
-
},
|
|
322
|
-
confirmCallBackFunction: () => {
|
|
323
|
-
this.closeExpiryTimerSubscription();
|
|
324
|
-
this.updateToken(20);
|
|
325
|
-
},
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
saveUrl() {
|
|
329
|
-
var _a, _b, _c;
|
|
330
|
-
const returnToLastUrlAfterTokenExpiration = (_c = (_b = (_a = this.configService) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.featureToggles) === null || _c === void 0 ? void 0 : _c.returnToLastUrlAfterTokenExpiration;
|
|
331
|
-
if (returnToLastUrlAfterTokenExpiration) {
|
|
332
|
-
sessionStorage.setItem(STORAGE_KEYS.urlBeforeExpiration, this.keycloakStorageService.getCurrentUrl());
|
|
333
|
-
sessionStorage.setItem(STORAGE_KEYS.urlBeforeExpirationParams, this.keycloakStorageService.getCurrentUrlParams());
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
KeycloakUserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", 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 });
|
|
338
|
-
KeycloakUserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakUserService, providedIn: 'root' });
|
|
339
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakUserService, decorators: [{
|
|
340
|
-
type: Injectable,
|
|
341
|
-
args: [{
|
|
342
|
-
providedIn: 'root',
|
|
343
|
-
}]
|
|
344
|
-
}], 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 }]; } });
|
|
345
|
-
|
|
346
|
-
/*
|
|
347
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
348
|
-
*
|
|
349
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
350
|
-
* you may not use this file except in compliance with the License.
|
|
351
|
-
* You may obtain a copy of the License at
|
|
352
|
-
*
|
|
353
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
354
|
-
*
|
|
355
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
356
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
357
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
358
|
-
* See the License for the specific language governing permissions and
|
|
359
|
-
* limitations under the License.
|
|
360
|
-
*/
|
|
361
|
-
|
|
362
|
-
/*
|
|
363
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
364
|
-
*
|
|
365
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
366
|
-
* you may not use this file except in compliance with the License.
|
|
367
|
-
* You may obtain a copy of the License at
|
|
368
|
-
*
|
|
369
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
370
|
-
*
|
|
371
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
372
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
373
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
374
|
-
* See the License for the specific language governing permissions and
|
|
375
|
-
* limitations under the License.
|
|
376
|
-
*/
|
|
377
|
-
class CallbackComponent {
|
|
378
|
-
constructor(router, keycloakOptionsService, logger, keycloakStorageService) {
|
|
379
|
-
this.router = router;
|
|
380
|
-
this.keycloakOptionsService = keycloakOptionsService;
|
|
381
|
-
this.logger = logger;
|
|
382
|
-
this.keycloakStorageService = keycloakStorageService;
|
|
383
|
-
logger.debug('callback');
|
|
384
|
-
const savedRedirectTo = window.sessionStorage.getItem(STORAGE_KEYS.redirectTo);
|
|
385
|
-
const savedRedirectToParams = window.sessionStorage.getItem(STORAGE_KEYS.redirectToParams);
|
|
386
|
-
const parsedSavedRedirectToParams = this.keycloakStorageService.parseSavedParams(savedRedirectToParams);
|
|
387
|
-
const urlBeforeExpiration = sessionStorage.getItem(STORAGE_KEYS.urlBeforeExpiration);
|
|
388
|
-
const paramsBeforeExpiration = sessionStorage.getItem(STORAGE_KEYS.urlBeforeExpirationParams);
|
|
389
|
-
const parsedParamsBeforeExpiration = this.keycloakStorageService.parseSavedParams(paramsBeforeExpiration);
|
|
390
|
-
let redirectTo;
|
|
391
|
-
if (savedRedirectTo) {
|
|
392
|
-
redirectTo = savedRedirectTo;
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
redirectTo = '/';
|
|
396
|
-
}
|
|
397
|
-
logger.debug('keycloak callback redirect =', redirectTo);
|
|
398
|
-
logger.debug('keycloak callback redirect params =', savedRedirectToParams);
|
|
399
|
-
if (STORAGE_KEYS.urlBeforeExpiration in sessionStorage) {
|
|
400
|
-
this.router.navigate([urlBeforeExpiration], { queryParams: parsedParamsBeforeExpiration });
|
|
401
|
-
sessionStorage.removeItem(STORAGE_KEYS.urlBeforeExpiration);
|
|
402
|
-
sessionStorage.removeItem(STORAGE_KEYS.urlBeforeExpirationParams);
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
this.router.navigate([redirectTo], { queryParams: parsedSavedRedirectToParams });
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
CallbackComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CallbackComponent, deps: [{ token: i1.Router }, { token: KeycloakOptionsService }, { token: i3.NGXLogger }, { token: KeycloakStorageService }], target: i0.ɵɵFactoryTarget.Component });
|
|
410
|
-
CallbackComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: CallbackComponent, selector: "valtimo-keycloak-callback", ngImport: i0, template: '', isInline: true });
|
|
411
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CallbackComponent, decorators: [{
|
|
412
|
-
type: Component,
|
|
413
|
-
args: [{
|
|
414
|
-
selector: 'valtimo-keycloak-callback',
|
|
415
|
-
template: '',
|
|
416
|
-
}]
|
|
417
|
-
}], ctorParameters: function () { return [{ type: i1.Router }, { type: KeycloakOptionsService }, { type: i3.NGXLogger }, { type: KeycloakStorageService }]; } });
|
|
418
|
-
|
|
419
|
-
/*
|
|
420
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
421
|
-
*
|
|
422
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
423
|
-
* you may not use this file except in compliance with the License.
|
|
424
|
-
* You may obtain a copy of the License at
|
|
425
|
-
*
|
|
426
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
427
|
-
*
|
|
428
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
429
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
430
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
431
|
-
* See the License for the specific language governing permissions and
|
|
432
|
-
* limitations under the License.
|
|
433
|
-
*/
|
|
434
|
-
const routes = [
|
|
435
|
-
{
|
|
436
|
-
path: 'keycloak/callback',
|
|
437
|
-
component: CallbackComponent,
|
|
438
|
-
data: { title: 'Loading...' },
|
|
439
|
-
},
|
|
440
|
-
];
|
|
441
|
-
class KeycloakRoutingModule {
|
|
442
|
-
}
|
|
443
|
-
KeycloakRoutingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakRoutingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
444
|
-
KeycloakRoutingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: KeycloakRoutingModule, imports: [CommonModule, i1.RouterModule], exports: [RouterModule] });
|
|
445
|
-
KeycloakRoutingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakRoutingModule, imports: [CommonModule, RouterModule.forChild(routes), RouterModule] });
|
|
446
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakRoutingModule, decorators: [{
|
|
447
|
-
type: NgModule,
|
|
448
|
-
args: [{
|
|
449
|
-
imports: [CommonModule, RouterModule.forChild(routes)],
|
|
450
|
-
exports: [RouterModule],
|
|
451
|
-
}]
|
|
452
|
-
}] });
|
|
453
|
-
|
|
454
|
-
/*
|
|
455
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
456
|
-
*
|
|
457
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
458
|
-
* you may not use this file except in compliance with the License.
|
|
459
|
-
* You may obtain a copy of the License at
|
|
460
|
-
*
|
|
461
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
462
|
-
*
|
|
463
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
464
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
465
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
466
|
-
* See the License for the specific language governing permissions and
|
|
467
|
-
* limitations under the License.
|
|
468
|
-
*/
|
|
469
|
-
class KeycloakModule {
|
|
470
|
-
}
|
|
471
|
-
KeycloakModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
472
|
-
KeycloakModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: KeycloakModule, declarations: [CallbackComponent], imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule], exports: [CallbackComponent] });
|
|
473
|
-
KeycloakModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakModule, providers: [DatePipe], imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule] });
|
|
474
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: KeycloakModule, decorators: [{
|
|
475
|
-
type: NgModule,
|
|
476
|
-
args: [{
|
|
477
|
-
declarations: [CallbackComponent],
|
|
478
|
-
imports: [KeycloakRoutingModule, KeycloakAngularModule, TranslateModule],
|
|
479
|
-
exports: [CallbackComponent],
|
|
480
|
-
providers: [DatePipe],
|
|
481
|
-
}]
|
|
482
|
-
}] });
|
|
483
|
-
|
|
484
|
-
function keycloakInitializer(injector) {
|
|
485
|
-
const keycloakService = injector.get(KeycloakService);
|
|
486
|
-
const keycloakUserService = injector.get(KeycloakUserService);
|
|
487
|
-
const optionsService = injector.get(KeycloakOptionsService); // TODO possible removal of abstraction
|
|
488
|
-
const storageService = injector.get(KeycloakStorageService);
|
|
489
|
-
const logger = injector.get(NGXLogger);
|
|
490
|
-
return () => __awaiter(this, void 0, void 0, function* () {
|
|
491
|
-
try {
|
|
492
|
-
logger.debug('Keycloak initializer before init');
|
|
493
|
-
const keycloakOptions = optionsService.keycloakOptions;
|
|
494
|
-
const currentUrl = window.location.href.split('#')[0];
|
|
495
|
-
if (keycloakOptions.initOptions.redirectUri !== currentUrl) {
|
|
496
|
-
const redirectTo = storageService.getCurrentUrl();
|
|
497
|
-
logger.debug('Setting redirectTo =', redirectTo);
|
|
498
|
-
window.sessionStorage.setItem(STORAGE_KEYS.redirectTo, redirectTo);
|
|
499
|
-
window.sessionStorage.setItem(STORAGE_KEYS.redirectToParams, storageService.getCurrentUrlParams());
|
|
500
|
-
}
|
|
501
|
-
const initResult = yield keycloakService.init(keycloakOptions);
|
|
502
|
-
logger.debug('Keycloak initializer after init');
|
|
503
|
-
keycloakUserService.init();
|
|
504
|
-
return initResult;
|
|
505
|
-
}
|
|
506
|
-
catch (error) {
|
|
507
|
-
logger.debug('Keycloak initializer error', error);
|
|
508
|
-
throw error;
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
/*
|
|
514
|
-
* Copyright 2015-2023 Ritense BV, the Netherlands.
|
|
515
|
-
*
|
|
516
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
517
|
-
* you may not use this file except in compliance with the License.
|
|
518
|
-
* You may obtain a copy of the License at
|
|
519
|
-
*
|
|
520
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
521
|
-
*
|
|
522
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
523
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
524
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
525
|
-
* See the License for the specific language governing permissions and
|
|
526
|
-
* limitations under the License.
|
|
527
|
-
*/
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Generated bundle index. Do not edit.
|
|
531
|
-
*/
|
|
532
|
-
|
|
533
|
-
export { CallbackComponent, KeycloakAuthGuardService, KeycloakModule, KeycloakOptionsService, KeycloakUserService, STORAGE_KEYS, keycloakInitializer };
|
|
534
|
-
//# sourceMappingURL=valtimo-keycloak.mjs.map
|