keycloak-angular 7.0.1 → 7.3.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/README.md +29 -21
- package/bundles/keycloak-angular.umd.js +309 -216
- package/bundles/keycloak-angular.umd.js.map +1 -1
- package/bundles/keycloak-angular.umd.min.js +15 -1
- package/bundles/keycloak-angular.umd.min.js.map +1 -1
- package/esm2015/keycloak-angular.js +2 -2
- package/esm2015/lib/core/core.module.js +18 -16
- package/esm2015/lib/core/interceptors/keycloak-bearer.interceptor.js +20 -14
- package/esm2015/lib/core/interfaces/keycloak-config.js +1 -8
- package/esm2015/lib/core/interfaces/keycloak-event.js +11 -23
- package/esm2015/lib/core/interfaces/keycloak-options.js +1 -21
- package/esm2015/lib/core/services/keycloak-auth-guard.js +4 -11
- package/esm2015/lib/core/services/keycloak.service.js +78 -134
- package/esm2015/lib/core/utils/to-promise.js +10 -0
- package/esm2015/lib/keycloak-angular.module.js +10 -8
- package/esm2015/public_api.js +1 -1
- package/esm5/keycloak-angular.js +2 -2
- package/esm5/lib/core/core.module.js +15 -14
- package/esm5/lib/core/interceptors/keycloak-bearer.interceptor.js +15 -10
- package/esm5/lib/core/interfaces/keycloak-config.js +1 -8
- package/esm5/lib/core/interfaces/keycloak-event.js +11 -23
- package/esm5/lib/core/interfaces/keycloak-options.js +1 -21
- package/esm5/lib/core/services/keycloak-auth-guard.js +5 -12
- package/esm5/lib/core/services/keycloak.service.js +131 -183
- package/esm5/lib/core/utils/to-promise.js +10 -0
- package/esm5/lib/keycloak-angular.module.js +7 -6
- package/esm5/public_api.js +1 -1
- package/fesm2015/keycloak-angular.js +134 -172
- package/fesm2015/keycloak-angular.js.map +1 -1
- package/fesm5/keycloak-angular.js +175 -208
- package/fesm5/keycloak-angular.js.map +1 -1
- package/keycloak-angular.metadata.json +1 -1
- package/lib/core/interceptors/keycloak-bearer.interceptor.d.ts +1 -0
- package/lib/core/interfaces/keycloak-config.d.ts +2 -2
- package/lib/core/interfaces/keycloak-options.d.ts +1 -2
- package/lib/core/services/keycloak-auth-guard.d.ts +3 -3
- package/lib/core/services/keycloak.service.d.ts +7 -7
- package/lib/core/utils/to-promise.d.ts +7 -0
- package/package.json +8 -9
- package/public_api.d.ts +1 -1
- package/esm2015/lib/core/interfaces/keycloak-init-options.js +0 -13
- package/esm5/lib/core/interfaces/keycloak-init-options.js +0 -13
- package/lib/core/interfaces/keycloak-init-options.d.ts +0 -15
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
import { __awaiter, __generator, __values, __spread } from 'tslib';
|
|
1
|
+
import { __awaiter, __generator, __values, __spread, __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { Injectable, NgModule } from '@angular/core';
|
|
3
3
|
import { HttpHeaders, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
4
|
-
import {
|
|
4
|
+
import { Subject, from } from 'rxjs';
|
|
5
|
+
import { map, mergeMap } from 'rxjs/operators';
|
|
5
6
|
import * as Keycloak_ from 'keycloak-js';
|
|
6
|
-
import { mergeMap } from 'rxjs/operators';
|
|
7
7
|
import { CommonModule } from '@angular/common';
|
|
8
8
|
|
|
9
|
-
var KeycloakEventType
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
KeycloakEventType
|
|
19
|
-
KeycloakEventType[KeycloakEventType.OnAuthLogout] = 'OnAuthLogout';
|
|
20
|
-
KeycloakEventType[KeycloakEventType.OnAuthRefreshError] = 'OnAuthRefreshError';
|
|
21
|
-
KeycloakEventType[KeycloakEventType.OnAuthRefreshSuccess] = 'OnAuthRefreshSuccess';
|
|
22
|
-
KeycloakEventType[KeycloakEventType.OnAuthSuccess] = 'OnAuthSuccess';
|
|
23
|
-
KeycloakEventType[KeycloakEventType.OnReady] = 'OnReady';
|
|
24
|
-
KeycloakEventType[KeycloakEventType.OnTokenExpired] = 'OnTokenExpired';
|
|
9
|
+
var KeycloakEventType;
|
|
10
|
+
(function (KeycloakEventType) {
|
|
11
|
+
KeycloakEventType[KeycloakEventType["OnAuthError"] = 0] = "OnAuthError";
|
|
12
|
+
KeycloakEventType[KeycloakEventType["OnAuthLogout"] = 1] = "OnAuthLogout";
|
|
13
|
+
KeycloakEventType[KeycloakEventType["OnAuthRefreshError"] = 2] = "OnAuthRefreshError";
|
|
14
|
+
KeycloakEventType[KeycloakEventType["OnAuthRefreshSuccess"] = 3] = "OnAuthRefreshSuccess";
|
|
15
|
+
KeycloakEventType[KeycloakEventType["OnAuthSuccess"] = 4] = "OnAuthSuccess";
|
|
16
|
+
KeycloakEventType[KeycloakEventType["OnReady"] = 5] = "OnReady";
|
|
17
|
+
KeycloakEventType[KeycloakEventType["OnTokenExpired"] = 6] = "OnTokenExpired";
|
|
18
|
+
})(KeycloakEventType || (KeycloakEventType = {}));
|
|
25
19
|
|
|
26
20
|
var KeycloakAuthGuard = (function () {
|
|
27
21
|
function KeycloakAuthGuard(router, keycloakAngular) {
|
|
@@ -30,7 +24,7 @@ var KeycloakAuthGuard = (function () {
|
|
|
30
24
|
}
|
|
31
25
|
KeycloakAuthGuard.prototype.canActivate = function (route, state) {
|
|
32
26
|
var _this = this;
|
|
33
|
-
return new Promise(
|
|
27
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
34
28
|
var _a, _b, result, error_1;
|
|
35
29
|
return __generator(this, function (_c) {
|
|
36
30
|
switch (_c.label) {
|
|
@@ -56,11 +50,21 @@ var KeycloakAuthGuard = (function () {
|
|
|
56
50
|
case 5: return [2];
|
|
57
51
|
}
|
|
58
52
|
});
|
|
59
|
-
}); })
|
|
53
|
+
}); });
|
|
60
54
|
};
|
|
61
55
|
return KeycloakAuthGuard;
|
|
62
56
|
}());
|
|
63
57
|
|
|
58
|
+
function toPromise(originalPromise) {
|
|
59
|
+
if (originalPromise instanceof Promise) {
|
|
60
|
+
return originalPromise;
|
|
61
|
+
}
|
|
62
|
+
return new Promise(function (resolve, reject) {
|
|
63
|
+
originalPromise.success(resolve);
|
|
64
|
+
originalPromise.error(reject);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
64
68
|
var Keycloak = Keycloak_;
|
|
65
69
|
var KeycloakService = (function () {
|
|
66
70
|
function KeycloakService() {
|
|
@@ -68,39 +72,39 @@ var KeycloakService = (function () {
|
|
|
68
72
|
}
|
|
69
73
|
KeycloakService.prototype.bindsKeycloakEvents = function () {
|
|
70
74
|
var _this = this;
|
|
71
|
-
this._instance.onAuthError =
|
|
75
|
+
this._instance.onAuthError = function (errorData) {
|
|
72
76
|
_this._keycloakEvents$.next({
|
|
73
77
|
args: errorData,
|
|
74
|
-
type: KeycloakEventType.OnAuthError
|
|
78
|
+
type: KeycloakEventType.OnAuthError,
|
|
75
79
|
});
|
|
76
|
-
}
|
|
77
|
-
this._instance.onAuthLogout =
|
|
80
|
+
};
|
|
81
|
+
this._instance.onAuthLogout = function () {
|
|
78
82
|
_this._keycloakEvents$.next({ type: KeycloakEventType.OnAuthLogout });
|
|
79
|
-
}
|
|
80
|
-
this._instance.onAuthRefreshSuccess =
|
|
83
|
+
};
|
|
84
|
+
this._instance.onAuthRefreshSuccess = function () {
|
|
81
85
|
_this._keycloakEvents$.next({
|
|
82
|
-
type: KeycloakEventType.OnAuthRefreshSuccess
|
|
86
|
+
type: KeycloakEventType.OnAuthRefreshSuccess,
|
|
83
87
|
});
|
|
84
|
-
}
|
|
85
|
-
this._instance.onAuthRefreshError =
|
|
88
|
+
};
|
|
89
|
+
this._instance.onAuthRefreshError = function () {
|
|
86
90
|
_this._keycloakEvents$.next({
|
|
87
|
-
type: KeycloakEventType.OnAuthRefreshError
|
|
91
|
+
type: KeycloakEventType.OnAuthRefreshError,
|
|
88
92
|
});
|
|
89
|
-
}
|
|
90
|
-
this._instance.onAuthSuccess =
|
|
93
|
+
};
|
|
94
|
+
this._instance.onAuthSuccess = function () {
|
|
91
95
|
_this._keycloakEvents$.next({ type: KeycloakEventType.OnAuthSuccess });
|
|
92
|
-
}
|
|
93
|
-
this._instance.onTokenExpired =
|
|
96
|
+
};
|
|
97
|
+
this._instance.onTokenExpired = function () {
|
|
94
98
|
_this._keycloakEvents$.next({
|
|
95
|
-
type: KeycloakEventType.OnTokenExpired
|
|
99
|
+
type: KeycloakEventType.OnTokenExpired,
|
|
96
100
|
});
|
|
97
|
-
}
|
|
98
|
-
this._instance.onReady =
|
|
101
|
+
};
|
|
102
|
+
this._instance.onReady = function (authenticated) {
|
|
99
103
|
_this._keycloakEvents$.next({
|
|
100
104
|
args: authenticated,
|
|
101
|
-
type: KeycloakEventType.OnReady
|
|
105
|
+
type: KeycloakEventType.OnReady,
|
|
102
106
|
});
|
|
103
|
-
}
|
|
107
|
+
};
|
|
104
108
|
};
|
|
105
109
|
KeycloakService.prototype.loadExcludedUrls = function (bearerExcludedUrls) {
|
|
106
110
|
var e_1, _a;
|
|
@@ -115,7 +119,7 @@ var KeycloakService = (function () {
|
|
|
115
119
|
else {
|
|
116
120
|
excludedUrl = {
|
|
117
121
|
urlPattern: new RegExp(item.url, 'i'),
|
|
118
|
-
httpMethods: item.httpMethods
|
|
122
|
+
httpMethods: item.httpMethods,
|
|
119
123
|
};
|
|
120
124
|
}
|
|
121
125
|
excludedUrls.push(excludedUrl);
|
|
@@ -140,90 +144,77 @@ var KeycloakService = (function () {
|
|
|
140
144
|
this._silentRefresh = initOptions ? initOptions.flow === 'implicit' : false;
|
|
141
145
|
};
|
|
142
146
|
KeycloakService.prototype.init = function (options) {
|
|
143
|
-
var _this = this;
|
|
144
147
|
if (options === void 0) { options = {}; }
|
|
145
|
-
return
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return [2];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}); }))
|
|
167
|
-
.error((function (kcError) {
|
|
168
|
-
var msg = 'An error happened during Keycloak initialization.';
|
|
169
|
-
if (kcError) {
|
|
170
|
-
var error = kcError.error, error_description = kcError.error_description;
|
|
171
|
-
msg = msg.concat("\nAdapter error details:\nError: " + error + "\nDescription: " + error_description);
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var config, initOptions, authenticated;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
this.initServiceValues(options);
|
|
154
|
+
config = options.config, initOptions = options.initOptions;
|
|
155
|
+
this._instance = Keycloak(config);
|
|
156
|
+
this.bindsKeycloakEvents();
|
|
157
|
+
return [4, toPromise(this._instance.init(initOptions))];
|
|
158
|
+
case 1:
|
|
159
|
+
authenticated = _a.sent();
|
|
160
|
+
if (!(authenticated && this._loadUserProfileAtStartUp)) return [3, 3];
|
|
161
|
+
return [4, this.loadUserProfile()];
|
|
162
|
+
case 2:
|
|
163
|
+
_a.sent();
|
|
164
|
+
_a.label = 3;
|
|
165
|
+
case 3: return [2, authenticated];
|
|
172
166
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}));
|
|
167
|
+
});
|
|
168
|
+
});
|
|
176
169
|
};
|
|
177
170
|
KeycloakService.prototype.login = function (options) {
|
|
178
|
-
var _this = this;
|
|
179
171
|
if (options === void 0) { options = {}; }
|
|
180
|
-
return
|
|
181
|
-
|
|
182
|
-
.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}); }))
|
|
198
|
-
.error((function () { return reject("An error happened during the login."); }));
|
|
199
|
-
}));
|
|
172
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
switch (_a.label) {
|
|
175
|
+
case 0: return [4, toPromise(this._instance.login(options))];
|
|
176
|
+
case 1:
|
|
177
|
+
_a.sent();
|
|
178
|
+
if (!this._loadUserProfileAtStartUp) return [3, 3];
|
|
179
|
+
return [4, this.loadUserProfile()];
|
|
180
|
+
case 2:
|
|
181
|
+
_a.sent();
|
|
182
|
+
_a.label = 3;
|
|
183
|
+
case 3: return [2];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
200
187
|
};
|
|
201
188
|
KeycloakService.prototype.logout = function (redirectUri) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
+
var options;
|
|
191
|
+
return __generator(this, function (_a) {
|
|
192
|
+
switch (_a.label) {
|
|
193
|
+
case 0:
|
|
194
|
+
options = {
|
|
195
|
+
redirectUri: redirectUri,
|
|
196
|
+
};
|
|
197
|
+
return [4, toPromise(this._instance.logout(options))];
|
|
198
|
+
case 1:
|
|
199
|
+
_a.sent();
|
|
200
|
+
this._userProfile = undefined;
|
|
201
|
+
return [2];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
215
205
|
};
|
|
216
206
|
KeycloakService.prototype.register = function (options) {
|
|
217
|
-
var _this = this;
|
|
218
207
|
if (options === void 0) { options = { action: 'register' }; }
|
|
219
|
-
return
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
208
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
209
|
+
return __generator(this, function (_a) {
|
|
210
|
+
switch (_a.label) {
|
|
211
|
+
case 0: return [4, toPromise(this._instance.register(options))];
|
|
212
|
+
case 1:
|
|
213
|
+
_a.sent();
|
|
214
|
+
return [2];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
227
218
|
};
|
|
228
219
|
KeycloakService.prototype.isUserInRole = function (role, resource) {
|
|
229
220
|
var hasRole;
|
|
@@ -278,61 +269,45 @@ var KeycloakService = (function () {
|
|
|
278
269
|
return this._instance.isTokenExpired(minValidity);
|
|
279
270
|
};
|
|
280
271
|
KeycloakService.prototype.updateToken = function (minValidity) {
|
|
281
|
-
var _this = this;
|
|
282
272
|
if (minValidity === void 0) { minValidity = 5; }
|
|
283
|
-
return
|
|
273
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
284
274
|
return __generator(this, function (_a) {
|
|
285
275
|
if (this._silentRefresh) {
|
|
286
276
|
if (this.isTokenExpired()) {
|
|
287
|
-
|
|
277
|
+
throw new Error('Failed to refresh the token, or the session is expired');
|
|
288
278
|
}
|
|
289
|
-
|
|
290
|
-
resolve(true);
|
|
291
|
-
}
|
|
292
|
-
return [2];
|
|
279
|
+
return [2, true];
|
|
293
280
|
}
|
|
294
281
|
if (!this._instance) {
|
|
295
|
-
|
|
296
|
-
return [2];
|
|
282
|
+
throw new Error('Keycloak Angular library is not initialized.');
|
|
297
283
|
}
|
|
298
|
-
this._instance
|
|
299
|
-
.updateToken(minValidity)
|
|
300
|
-
.success((function (refreshed) {
|
|
301
|
-
resolve(refreshed);
|
|
302
|
-
}))
|
|
303
|
-
.error((function () { return reject('Failed to refresh the token, or the session is expired'); }));
|
|
304
|
-
return [2];
|
|
284
|
+
return [2, toPromise(this._instance.updateToken(minValidity))];
|
|
305
285
|
});
|
|
306
|
-
});
|
|
286
|
+
});
|
|
307
287
|
};
|
|
308
288
|
KeycloakService.prototype.loadUserProfile = function (forceReload) {
|
|
309
|
-
var _this = this;
|
|
310
289
|
if (forceReload === void 0) { forceReload = false; }
|
|
311
|
-
return
|
|
312
|
-
var
|
|
313
|
-
return __generator(this, function (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
290
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
+
var _a;
|
|
292
|
+
return __generator(this, function (_b) {
|
|
293
|
+
switch (_b.label) {
|
|
294
|
+
case 0:
|
|
295
|
+
if (this._userProfile && !forceReload) {
|
|
296
|
+
return [2, this._userProfile];
|
|
297
|
+
}
|
|
298
|
+
if (!this._instance.authenticated) {
|
|
299
|
+
throw new Error('The user profile was not loaded as the user is not logged in.');
|
|
300
|
+
}
|
|
301
|
+
_a = this;
|
|
302
|
+
return [4, toPromise(this._instance.loadUserProfile())];
|
|
303
|
+
case 1: return [2, (_a._userProfile = _b.sent())];
|
|
321
304
|
}
|
|
322
|
-
this._instance
|
|
323
|
-
.loadUserProfile()
|
|
324
|
-
.success((function (result) {
|
|
325
|
-
_this._userProfile = ((result));
|
|
326
|
-
resolve(_this._userProfile);
|
|
327
|
-
}))
|
|
328
|
-
.error((function () { return reject('The user profile could not be loaded.'); }));
|
|
329
|
-
return [2];
|
|
330
305
|
});
|
|
331
|
-
});
|
|
306
|
+
});
|
|
332
307
|
};
|
|
333
|
-
KeycloakService.prototype.getToken = function () {
|
|
334
|
-
|
|
335
|
-
return
|
|
308
|
+
KeycloakService.prototype.getToken = function (forceLogin) {
|
|
309
|
+
if (forceLogin === void 0) { forceLogin = true; }
|
|
310
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
336
311
|
var error_2;
|
|
337
312
|
return __generator(this, function (_a) {
|
|
338
313
|
switch (_a.label) {
|
|
@@ -341,22 +316,26 @@ var KeycloakService = (function () {
|
|
|
341
316
|
return [4, this.updateToken(10)];
|
|
342
317
|
case 1:
|
|
343
318
|
_a.sent();
|
|
344
|
-
|
|
345
|
-
return [3, 3];
|
|
319
|
+
return [2, this._instance.token];
|
|
346
320
|
case 2:
|
|
347
321
|
error_2 = _a.sent();
|
|
348
|
-
|
|
322
|
+
if (forceLogin) {
|
|
323
|
+
this.login();
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
throw error_2;
|
|
327
|
+
}
|
|
349
328
|
return [3, 3];
|
|
350
329
|
case 3: return [2];
|
|
351
330
|
}
|
|
352
331
|
});
|
|
353
|
-
});
|
|
332
|
+
});
|
|
354
333
|
};
|
|
355
334
|
KeycloakService.prototype.getUsername = function () {
|
|
356
335
|
if (!this._userProfile) {
|
|
357
336
|
throw new Error('User not logged in or user profile was not loaded.');
|
|
358
337
|
}
|
|
359
|
-
return
|
|
338
|
+
return this._userProfile.username;
|
|
360
339
|
};
|
|
361
340
|
KeycloakService.prototype.clearToken = function () {
|
|
362
341
|
this._instance.clearToken();
|
|
@@ -364,27 +343,9 @@ var KeycloakService = (function () {
|
|
|
364
343
|
KeycloakService.prototype.addTokenToHeader = function (headers) {
|
|
365
344
|
var _this = this;
|
|
366
345
|
if (headers === void 0) { headers = new HttpHeaders(); }
|
|
367
|
-
return
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
switch (_a.label) {
|
|
371
|
-
case 0:
|
|
372
|
-
_a.trys.push([0, 2, , 3]);
|
|
373
|
-
return [4, this.getToken()];
|
|
374
|
-
case 1:
|
|
375
|
-
token = _a.sent();
|
|
376
|
-
headers = headers.set(this._authorizationHeaderName, this._bearerPrefix + token);
|
|
377
|
-
observer.next(headers);
|
|
378
|
-
observer.complete();
|
|
379
|
-
return [3, 3];
|
|
380
|
-
case 2:
|
|
381
|
-
error_3 = _a.sent();
|
|
382
|
-
observer.error(error_3);
|
|
383
|
-
return [3, 3];
|
|
384
|
-
case 3: return [2];
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
}); }));
|
|
346
|
+
return from(this.getToken()).pipe(map(function (token) {
|
|
347
|
+
return headers.set(_this._authorizationHeaderName, _this._bearerPrefix + token);
|
|
348
|
+
}));
|
|
388
349
|
};
|
|
389
350
|
KeycloakService.prototype.getKeycloakInstance = function () {
|
|
390
351
|
return this._instance;
|
|
@@ -410,9 +371,9 @@ var KeycloakService = (function () {
|
|
|
410
371
|
enumerable: true,
|
|
411
372
|
configurable: true
|
|
412
373
|
});
|
|
413
|
-
KeycloakService
|
|
414
|
-
|
|
415
|
-
];
|
|
374
|
+
KeycloakService = __decorate([
|
|
375
|
+
Injectable()
|
|
376
|
+
], KeycloakService);
|
|
416
377
|
return KeycloakService;
|
|
417
378
|
}());
|
|
418
379
|
|
|
@@ -434,51 +395,57 @@ var KeycloakBearerInterceptor = (function () {
|
|
|
434
395
|
if (!enableBearerInterceptor) {
|
|
435
396
|
return next.handle(req);
|
|
436
397
|
}
|
|
437
|
-
var shallPass = excludedUrls.findIndex(
|
|
398
|
+
var shallPass = excludedUrls.findIndex(function (item) { return _this.isUrlExcluded(req, item); }) > -1;
|
|
438
399
|
if (shallPass) {
|
|
439
400
|
return next.handle(req);
|
|
440
401
|
}
|
|
441
|
-
return this.keycloak.
|
|
402
|
+
return from(this.keycloak.isLoggedIn()).pipe(mergeMap(function (loggedIn) { return loggedIn
|
|
403
|
+
? _this.handleRequestWithTokenHeader(req, next)
|
|
404
|
+
: next.handle(req); }));
|
|
405
|
+
};
|
|
406
|
+
KeycloakBearerInterceptor.prototype.handleRequestWithTokenHeader = function (req, next) {
|
|
407
|
+
return this.keycloak.addTokenToHeader(req.headers).pipe(mergeMap(function (headersWithBearer) {
|
|
442
408
|
var kcReq = req.clone({ headers: headersWithBearer });
|
|
443
409
|
return next.handle(kcReq);
|
|
444
|
-
}))
|
|
410
|
+
}));
|
|
445
411
|
};
|
|
446
|
-
KeycloakBearerInterceptor.decorators = [
|
|
447
|
-
{ type: Injectable }
|
|
448
|
-
];
|
|
449
412
|
KeycloakBearerInterceptor.ctorParameters = function () { return [
|
|
450
413
|
{ type: KeycloakService }
|
|
451
414
|
]; };
|
|
415
|
+
KeycloakBearerInterceptor = __decorate([
|
|
416
|
+
Injectable(),
|
|
417
|
+
__metadata("design:paramtypes", [KeycloakService])
|
|
418
|
+
], KeycloakBearerInterceptor);
|
|
452
419
|
return KeycloakBearerInterceptor;
|
|
453
420
|
}());
|
|
454
421
|
|
|
455
422
|
var CoreModule = (function () {
|
|
456
423
|
function CoreModule() {
|
|
457
424
|
}
|
|
458
|
-
CoreModule
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
];
|
|
425
|
+
CoreModule = __decorate([
|
|
426
|
+
NgModule({
|
|
427
|
+
imports: [CommonModule],
|
|
428
|
+
providers: [
|
|
429
|
+
KeycloakService,
|
|
430
|
+
{
|
|
431
|
+
provide: HTTP_INTERCEPTORS,
|
|
432
|
+
useClass: KeycloakBearerInterceptor,
|
|
433
|
+
multi: true
|
|
434
|
+
}
|
|
435
|
+
]
|
|
436
|
+
})
|
|
437
|
+
], CoreModule);
|
|
471
438
|
return CoreModule;
|
|
472
439
|
}());
|
|
473
440
|
|
|
474
441
|
var KeycloakAngularModule = (function () {
|
|
475
442
|
function KeycloakAngularModule() {
|
|
476
443
|
}
|
|
477
|
-
KeycloakAngularModule
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
];
|
|
444
|
+
KeycloakAngularModule = __decorate([
|
|
445
|
+
NgModule({
|
|
446
|
+
imports: [CoreModule]
|
|
447
|
+
})
|
|
448
|
+
], KeycloakAngularModule);
|
|
482
449
|
return KeycloakAngularModule;
|
|
483
450
|
}());
|
|
484
451
|
|