@valtimo/keycloak 4.15.3-next-main.14 → 4.15.3-next-main.15
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/bundles/valtimo-keycloak.umd.js +581 -581
- package/esm2015/lib/callback.component.js +48 -48
- package/esm2015/lib/keycloak-auth-guard.service.js +63 -63
- package/esm2015/lib/keycloak-options.service.js +25 -25
- package/esm2015/lib/keycloak-routing.module.js +36 -36
- package/esm2015/lib/keycloak-user.service.js +75 -75
- package/esm2015/lib/keycloak.init.js +46 -46
- package/esm2015/lib/keycloak.module.js +31 -31
- package/esm2015/public_api.js +23 -23
- package/esm2015/valtimo-keycloak.js +6 -6
- package/fesm2015/valtimo-keycloak.js +277 -277
- package/lib/callback.component.d.ts +9 -9
- package/lib/keycloak-auth-guard.service.d.ts +10 -10
- package/lib/keycloak-options.service.d.ts +8 -8
- package/lib/keycloak-routing.module.d.ts +2 -2
- package/lib/keycloak-user.service.d.ts +17 -17
- package/lib/keycloak.init.d.ts +2 -2
- package/lib/keycloak.module.d.ts +2 -2
- package/package.json +1 -1
- package/public_api.d.ts +5 -5
- package/valtimo-keycloak.d.ts +6 -6
|
@@ -8,299 +8,299 @@ import { __awaiter } from 'tslib';
|
|
|
8
8
|
import { ReplaySubject } from 'rxjs';
|
|
9
9
|
import { ValtimoUserIdentity } from '@valtimo/contract';
|
|
10
10
|
|
|
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 }
|
|
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 }
|
|
31
31
|
];
|
|
32
32
|
|
|
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 }
|
|
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 }
|
|
76
76
|
];
|
|
77
77
|
|
|
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
|
-
},] }
|
|
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
|
+
},] }
|
|
108
108
|
];
|
|
109
109
|
|
|
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: [
|
|
131
|
-
KeycloakRoutingModule,
|
|
132
|
-
KeycloakAngularModule
|
|
133
|
-
],
|
|
134
|
-
exports: [CallbackComponent]
|
|
135
|
-
},] }
|
|
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: [
|
|
131
|
+
KeycloakRoutingModule,
|
|
132
|
+
KeycloakAngularModule
|
|
133
|
+
],
|
|
134
|
+
exports: [CallbackComponent]
|
|
135
|
+
},] }
|
|
136
136
|
];
|
|
137
137
|
|
|
138
|
-
/*
|
|
139
|
-
* Copyright 2015-2020 Ritense BV, the Netherlands.
|
|
140
|
-
*
|
|
141
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
142
|
-
* you may not use this file except in compliance with the License.
|
|
143
|
-
* You may obtain a copy of the License at
|
|
144
|
-
*
|
|
145
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
146
|
-
*
|
|
147
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
148
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
149
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
150
|
-
* See the License for the specific language governing permissions and
|
|
151
|
-
* limitations under the License.
|
|
152
|
-
*/
|
|
153
|
-
class KeycloakAuthGuardService extends KeycloakAuthGuard {
|
|
154
|
-
constructor(router, keycloakAngular, logger) {
|
|
155
|
-
super(router, keycloakAngular);
|
|
156
|
-
this.router = router;
|
|
157
|
-
this.keycloakAngular = keycloakAngular;
|
|
158
|
-
this.logger = logger;
|
|
159
|
-
this.logger.debug('KeycloakAuthGuardService: ctor');
|
|
160
|
-
}
|
|
161
|
-
isAccessAllowed(route, state) {
|
|
162
|
-
this.logger.debug('KeycloakAuthGuardService: isAccessAllowed');
|
|
163
|
-
return new Promise((resolve, reject) => {
|
|
164
|
-
this.logger.debug('KeycloakAuthGuardService: isAccessAllowed checking access');
|
|
165
|
-
if (!this.authenticated) {
|
|
166
|
-
this.keycloakAngular.login().catch(e => `KeycloakAuthGuardService error: ${this.logger.error(e)}`);
|
|
167
|
-
return reject(false);
|
|
168
|
-
}
|
|
169
|
-
const requiredRoles = route.data.roles;
|
|
170
|
-
if (!requiredRoles || requiredRoles.length === 0) {
|
|
171
|
-
return resolve(true);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
if (!this.roles || this.roles.length === 0) {
|
|
175
|
-
resolve(false);
|
|
176
|
-
}
|
|
177
|
-
resolve(requiredRoles.some(role => this.roles.includes(role)));
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
KeycloakAuthGuardService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakAuthGuardService_Factory() { return new KeycloakAuthGuardService(ɵɵinject(Router), ɵɵinject(KeycloakService), ɵɵinject(NGXLogger)); }, token: KeycloakAuthGuardService, providedIn: "root" });
|
|
183
|
-
KeycloakAuthGuardService.decorators = [
|
|
184
|
-
{ type: Injectable, args: [{
|
|
185
|
-
providedIn: 'root'
|
|
186
|
-
},] }
|
|
187
|
-
];
|
|
188
|
-
KeycloakAuthGuardService.ctorParameters = () => [
|
|
189
|
-
{ type: Router },
|
|
190
|
-
{ type: KeycloakService },
|
|
191
|
-
{ type: NGXLogger }
|
|
138
|
+
/*
|
|
139
|
+
* Copyright 2015-2020 Ritense BV, the Netherlands.
|
|
140
|
+
*
|
|
141
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
142
|
+
* you may not use this file except in compliance with the License.
|
|
143
|
+
* You may obtain a copy of the License at
|
|
144
|
+
*
|
|
145
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
146
|
+
*
|
|
147
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
148
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
149
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
150
|
+
* See the License for the specific language governing permissions and
|
|
151
|
+
* limitations under the License.
|
|
152
|
+
*/
|
|
153
|
+
class KeycloakAuthGuardService extends KeycloakAuthGuard {
|
|
154
|
+
constructor(router, keycloakAngular, logger) {
|
|
155
|
+
super(router, keycloakAngular);
|
|
156
|
+
this.router = router;
|
|
157
|
+
this.keycloakAngular = keycloakAngular;
|
|
158
|
+
this.logger = logger;
|
|
159
|
+
this.logger.debug('KeycloakAuthGuardService: ctor');
|
|
160
|
+
}
|
|
161
|
+
isAccessAllowed(route, state) {
|
|
162
|
+
this.logger.debug('KeycloakAuthGuardService: isAccessAllowed');
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
this.logger.debug('KeycloakAuthGuardService: isAccessAllowed checking access');
|
|
165
|
+
if (!this.authenticated) {
|
|
166
|
+
this.keycloakAngular.login().catch(e => `KeycloakAuthGuardService error: ${this.logger.error(e)}`);
|
|
167
|
+
return reject(false);
|
|
168
|
+
}
|
|
169
|
+
const requiredRoles = route.data.roles;
|
|
170
|
+
if (!requiredRoles || requiredRoles.length === 0) {
|
|
171
|
+
return resolve(true);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
if (!this.roles || this.roles.length === 0) {
|
|
175
|
+
resolve(false);
|
|
176
|
+
}
|
|
177
|
+
resolve(requiredRoles.some(role => this.roles.includes(role)));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
KeycloakAuthGuardService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakAuthGuardService_Factory() { return new KeycloakAuthGuardService(ɵɵinject(Router), ɵɵinject(KeycloakService), ɵɵinject(NGXLogger)); }, token: KeycloakAuthGuardService, providedIn: "root" });
|
|
183
|
+
KeycloakAuthGuardService.decorators = [
|
|
184
|
+
{ type: Injectable, args: [{
|
|
185
|
+
providedIn: 'root'
|
|
186
|
+
},] }
|
|
187
|
+
];
|
|
188
|
+
KeycloakAuthGuardService.ctorParameters = () => [
|
|
189
|
+
{ type: Router },
|
|
190
|
+
{ type: KeycloakService },
|
|
191
|
+
{ type: NGXLogger }
|
|
192
192
|
];
|
|
193
193
|
|
|
194
|
-
class KeycloakUserService {
|
|
195
|
-
constructor(keycloakService, keycloakOptionsService, logger) {
|
|
196
|
-
this.keycloakService = keycloakService;
|
|
197
|
-
this.keycloakOptionsService = keycloakOptionsService;
|
|
198
|
-
this.logger = logger;
|
|
199
|
-
}
|
|
200
|
-
init() {
|
|
201
|
-
this.userIdentity = new ReplaySubject();
|
|
202
|
-
this.keycloakService.loadUserProfile().then(user => {
|
|
203
|
-
this.logger.debug('KeycloakUserService: loadUserProfile = ', user);
|
|
204
|
-
const roles = [];
|
|
205
|
-
this.keycloakService.getUserRoles(true).forEach(role => roles.push(role));
|
|
206
|
-
const valtimoUserIdentity = new ValtimoUserIdentity(user.email, user.firstName, user.lastName, roles, user.username);
|
|
207
|
-
this.logger.debug('KeycloakUserService: loaded user identity', valtimoUserIdentity);
|
|
208
|
-
this.userIdentity.next(valtimoUserIdentity);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
getUserSubject() {
|
|
212
|
-
this.logger.debug('KeycloakUserService: getUserIdentity');
|
|
213
|
-
return this.userIdentity;
|
|
214
|
-
}
|
|
215
|
-
logout() {
|
|
216
|
-
this.logger.debug('KeycloakUserService: logout');
|
|
217
|
-
this.keycloakService.logout(this.keycloakOptionsService.logoutRedirectUri);
|
|
218
|
-
}
|
|
219
|
-
getToken() {
|
|
220
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
-
this.logger.debug('KeycloakUserService: getToken');
|
|
222
|
-
return this.keycloakService.getToken();
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
updateToken(minValidity) {
|
|
226
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
-
this.logger.debug('KeycloakUserService: updateToken');
|
|
228
|
-
return this.keycloakService.updateToken(minValidity);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
KeycloakUserService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakUserService_Factory() { return new KeycloakUserService(ɵɵinject(KeycloakService), ɵɵinject(KeycloakOptionsService), ɵɵinject(NGXLogger)); }, token: KeycloakUserService, providedIn: "root" });
|
|
233
|
-
KeycloakUserService.decorators = [
|
|
234
|
-
{ type: Injectable, args: [{
|
|
235
|
-
providedIn: 'root'
|
|
236
|
-
},] }
|
|
237
|
-
];
|
|
238
|
-
KeycloakUserService.ctorParameters = () => [
|
|
239
|
-
{ type: KeycloakService },
|
|
240
|
-
{ type: KeycloakOptionsService },
|
|
241
|
-
{ type: NGXLogger }
|
|
194
|
+
class KeycloakUserService {
|
|
195
|
+
constructor(keycloakService, keycloakOptionsService, logger) {
|
|
196
|
+
this.keycloakService = keycloakService;
|
|
197
|
+
this.keycloakOptionsService = keycloakOptionsService;
|
|
198
|
+
this.logger = logger;
|
|
199
|
+
}
|
|
200
|
+
init() {
|
|
201
|
+
this.userIdentity = new ReplaySubject();
|
|
202
|
+
this.keycloakService.loadUserProfile().then(user => {
|
|
203
|
+
this.logger.debug('KeycloakUserService: loadUserProfile = ', user);
|
|
204
|
+
const roles = [];
|
|
205
|
+
this.keycloakService.getUserRoles(true).forEach(role => roles.push(role));
|
|
206
|
+
const valtimoUserIdentity = new ValtimoUserIdentity(user.email, user.firstName, user.lastName, roles, user.username);
|
|
207
|
+
this.logger.debug('KeycloakUserService: loaded user identity', valtimoUserIdentity);
|
|
208
|
+
this.userIdentity.next(valtimoUserIdentity);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
getUserSubject() {
|
|
212
|
+
this.logger.debug('KeycloakUserService: getUserIdentity');
|
|
213
|
+
return this.userIdentity;
|
|
214
|
+
}
|
|
215
|
+
logout() {
|
|
216
|
+
this.logger.debug('KeycloakUserService: logout');
|
|
217
|
+
this.keycloakService.logout(this.keycloakOptionsService.logoutRedirectUri);
|
|
218
|
+
}
|
|
219
|
+
getToken() {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
this.logger.debug('KeycloakUserService: getToken');
|
|
222
|
+
return this.keycloakService.getToken();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
updateToken(minValidity) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
this.logger.debug('KeycloakUserService: updateToken');
|
|
228
|
+
return this.keycloakService.updateToken(minValidity);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
KeycloakUserService.ɵprov = ɵɵdefineInjectable({ factory: function KeycloakUserService_Factory() { return new KeycloakUserService(ɵɵinject(KeycloakService), ɵɵinject(KeycloakOptionsService), ɵɵinject(NGXLogger)); }, token: KeycloakUserService, providedIn: "root" });
|
|
233
|
+
KeycloakUserService.decorators = [
|
|
234
|
+
{ type: Injectable, args: [{
|
|
235
|
+
providedIn: 'root'
|
|
236
|
+
},] }
|
|
237
|
+
];
|
|
238
|
+
KeycloakUserService.ctorParameters = () => [
|
|
239
|
+
{ type: KeycloakService },
|
|
240
|
+
{ type: KeycloakOptionsService },
|
|
241
|
+
{ type: NGXLogger }
|
|
242
242
|
];
|
|
243
243
|
|
|
244
|
-
/*
|
|
245
|
-
* Copyright 2015-2020 Ritense BV, the Netherlands.
|
|
246
|
-
*
|
|
247
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
248
|
-
* you may not use this file except in compliance with the License.
|
|
249
|
-
* You may obtain a copy of the License at
|
|
250
|
-
*
|
|
251
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
252
|
-
*
|
|
253
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
254
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
255
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
256
|
-
* See the License for the specific language governing permissions and
|
|
257
|
-
* limitations under the License.
|
|
258
|
-
*/
|
|
259
|
-
function keycloakInitializer(injector) {
|
|
260
|
-
const keycloakService = injector.get(KeycloakService);
|
|
261
|
-
const keycloakUserService = injector.get(KeycloakUserService);
|
|
262
|
-
const optionsService = injector.get(KeycloakOptionsService); // TODO possible removal of abstraction
|
|
263
|
-
const logger = injector.get(NGXLogger);
|
|
264
|
-
return () => __awaiter(this, void 0, void 0, function* () {
|
|
265
|
-
try {
|
|
266
|
-
logger.debug('Keycloak initializer before init');
|
|
267
|
-
const keycloakOptions = optionsService.keycloakOptions;
|
|
268
|
-
const currentUrl = window.location.href.split('#')[0];
|
|
269
|
-
if (keycloakOptions.initOptions.redirectUri !== currentUrl) {
|
|
270
|
-
const redirectTo = window.location.pathname;
|
|
271
|
-
logger.debug('Setting redirectTo =', redirectTo);
|
|
272
|
-
window.sessionStorage.setItem('redirectTo', redirectTo);
|
|
273
|
-
}
|
|
274
|
-
const initResult = yield keycloakService.init(keycloakOptions);
|
|
275
|
-
logger.debug('Keycloak initializer after init');
|
|
276
|
-
keycloakUserService.init();
|
|
277
|
-
return initResult;
|
|
278
|
-
}
|
|
279
|
-
catch (error) {
|
|
280
|
-
logger.debug('Keycloak initializer error', error);
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
244
|
+
/*
|
|
245
|
+
* Copyright 2015-2020 Ritense BV, the Netherlands.
|
|
246
|
+
*
|
|
247
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
248
|
+
* you may not use this file except in compliance with the License.
|
|
249
|
+
* You may obtain a copy of the License at
|
|
250
|
+
*
|
|
251
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
252
|
+
*
|
|
253
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
254
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
255
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
256
|
+
* See the License for the specific language governing permissions and
|
|
257
|
+
* limitations under the License.
|
|
258
|
+
*/
|
|
259
|
+
function keycloakInitializer(injector) {
|
|
260
|
+
const keycloakService = injector.get(KeycloakService);
|
|
261
|
+
const keycloakUserService = injector.get(KeycloakUserService);
|
|
262
|
+
const optionsService = injector.get(KeycloakOptionsService); // TODO possible removal of abstraction
|
|
263
|
+
const logger = injector.get(NGXLogger);
|
|
264
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
try {
|
|
266
|
+
logger.debug('Keycloak initializer before init');
|
|
267
|
+
const keycloakOptions = optionsService.keycloakOptions;
|
|
268
|
+
const currentUrl = window.location.href.split('#')[0];
|
|
269
|
+
if (keycloakOptions.initOptions.redirectUri !== currentUrl) {
|
|
270
|
+
const redirectTo = window.location.pathname;
|
|
271
|
+
logger.debug('Setting redirectTo =', redirectTo);
|
|
272
|
+
window.sessionStorage.setItem('redirectTo', redirectTo);
|
|
273
|
+
}
|
|
274
|
+
const initResult = yield keycloakService.init(keycloakOptions);
|
|
275
|
+
logger.debug('Keycloak initializer after init');
|
|
276
|
+
keycloakUserService.init();
|
|
277
|
+
return initResult;
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
logger.debug('Keycloak initializer error', error);
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
/*
|
|
287
|
-
* Copyright 2015-2020 Ritense BV, the Netherlands.
|
|
288
|
-
*
|
|
289
|
-
* Licensed under EUPL, Version 1.2 (the "License");
|
|
290
|
-
* you may not use this file except in compliance with the License.
|
|
291
|
-
* You may obtain a copy of the License at
|
|
292
|
-
*
|
|
293
|
-
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
294
|
-
*
|
|
295
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
296
|
-
* distributed under the License is distributed on an "AS IS" basis,
|
|
297
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
298
|
-
* See the License for the specific language governing permissions and
|
|
299
|
-
* limitations under the License.
|
|
286
|
+
/*
|
|
287
|
+
* Copyright 2015-2020 Ritense BV, the Netherlands.
|
|
288
|
+
*
|
|
289
|
+
* Licensed under EUPL, Version 1.2 (the "License");
|
|
290
|
+
* you may not use this file except in compliance with the License.
|
|
291
|
+
* You may obtain a copy of the License at
|
|
292
|
+
*
|
|
293
|
+
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
|
|
294
|
+
*
|
|
295
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
296
|
+
* distributed under the License is distributed on an "AS IS" basis,
|
|
297
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
298
|
+
* See the License for the specific language governing permissions and
|
|
299
|
+
* limitations under the License.
|
|
300
300
|
*/
|
|
301
301
|
|
|
302
|
-
/**
|
|
303
|
-
* Generated bundle index. Do not edit.
|
|
302
|
+
/**
|
|
303
|
+
* Generated bundle index. Do not edit.
|
|
304
304
|
*/
|
|
305
305
|
|
|
306
306
|
export { KeycloakAuthGuardService, KeycloakModule, KeycloakOptionsService, KeycloakUserService, keycloakInitializer, CallbackComponent as ɵa, KeycloakRoutingModule as ɵb };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Router } from '@angular/router';
|
|
2
|
-
import { NGXLogger } from 'ngx-logger';
|
|
3
|
-
import { KeycloakOptionsService } from './keycloak-options.service';
|
|
4
|
-
export declare class CallbackComponent {
|
|
5
|
-
private router;
|
|
6
|
-
private keycloakOptionsService;
|
|
7
|
-
private logger;
|
|
8
|
-
constructor(router: Router, keycloakOptionsService: KeycloakOptionsService, logger: NGXLogger);
|
|
9
|
-
}
|
|
1
|
+
import { Router } from '@angular/router';
|
|
2
|
+
import { NGXLogger } from 'ngx-logger';
|
|
3
|
+
import { KeycloakOptionsService } from './keycloak-options.service';
|
|
4
|
+
export declare class CallbackComponent {
|
|
5
|
+
private router;
|
|
6
|
+
private keycloakOptionsService;
|
|
7
|
+
private logger;
|
|
8
|
+
constructor(router: Router, keycloakOptionsService: KeycloakOptionsService, logger: NGXLogger);
|
|
9
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { KeycloakAuthGuard, KeycloakService } from 'keycloak-angular';
|
|
2
|
-
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
|
|
3
|
-
import { NGXLogger } from 'ngx-logger';
|
|
4
|
-
export declare class KeycloakAuthGuardService extends KeycloakAuthGuard implements CanActivate {
|
|
5
|
-
protected router: Router;
|
|
6
|
-
protected keycloakAngular: KeycloakService;
|
|
7
|
-
private logger;
|
|
8
|
-
constructor(router: Router, keycloakAngular: KeycloakService, logger: NGXLogger);
|
|
9
|
-
isAccessAllowed(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean>;
|
|
10
|
-
}
|
|
1
|
+
import { KeycloakAuthGuard, KeycloakService } from 'keycloak-angular';
|
|
2
|
+
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
|
|
3
|
+
import { NGXLogger } from 'ngx-logger';
|
|
4
|
+
export declare class KeycloakAuthGuardService extends KeycloakAuthGuard implements CanActivate {
|
|
5
|
+
protected router: Router;
|
|
6
|
+
protected keycloakAngular: KeycloakService;
|
|
7
|
+
private logger;
|
|
8
|
+
constructor(router: Router, keycloakAngular: KeycloakService, logger: NGXLogger);
|
|
9
|
+
isAccessAllowed(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean>;
|
|
10
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ConfigService } from '@valtimo/config';
|
|
2
|
-
export declare class KeycloakOptionsService {
|
|
3
|
-
private configService;
|
|
4
|
-
private readonly valtimoKeycloakOptions;
|
|
5
|
-
constructor(configService: ConfigService);
|
|
6
|
-
get keycloakOptions(): import("keycloak-angular").KeycloakOptions;
|
|
7
|
-
get logoutRedirectUri(): string;
|
|
8
|
-
}
|
|
1
|
+
import { ConfigService } from '@valtimo/config';
|
|
2
|
+
export declare class KeycloakOptionsService {
|
|
3
|
+
private configService;
|
|
4
|
+
private readonly valtimoKeycloakOptions;
|
|
5
|
+
constructor(configService: ConfigService);
|
|
6
|
+
get keycloakOptions(): import("keycloak-angular").KeycloakOptions;
|
|
7
|
+
get logoutRedirectUri(): string;
|
|
8
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare class KeycloakRoutingModule {
|
|
2
|
-
}
|
|
1
|
+
export declare class KeycloakRoutingModule {
|
|
2
|
+
}
|