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,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http'), require('rxjs'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define('keycloak-angular', ['exports', '@angular/core', '@angular/common/http', 'rxjs', '
|
|
4
|
-
(global = global || self, factory(global['keycloak-angular'] = {}, global.ng.core, global.ng.common.http, global.rxjs, global.
|
|
5
|
-
}(this, function (exports, core, http, rxjs,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http'), require('rxjs'), require('rxjs/operators'), require('keycloak-js'), require('@angular/common')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('keycloak-angular', ['exports', '@angular/core', '@angular/common/http', 'rxjs', 'rxjs/operators', 'keycloak-js', '@angular/common'], factory) :
|
|
4
|
+
(global = global || self, factory(global['keycloak-angular'] = {}, global.ng.core, global.ng.common.http, global.rxjs, global.rxjs.operators, global.Keycloak, global.ng.common));
|
|
5
|
+
}(this, (function (exports, core, http, rxjs, operators, Keycloak_, common) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*! *****************************************************************************
|
|
8
8
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -18,12 +18,65 @@
|
|
|
18
18
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
19
19
|
and limitations under the License.
|
|
20
20
|
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise */
|
|
22
|
+
|
|
23
|
+
var extendStatics = function(d, b) {
|
|
24
|
+
extendStatics = Object.setPrototypeOf ||
|
|
25
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
26
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
27
|
+
return extendStatics(d, b);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function __extends(d, b) {
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
function __() { this.constructor = d; }
|
|
33
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var __assign = function() {
|
|
37
|
+
__assign = Object.assign || function __assign(t) {
|
|
38
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
+
s = arguments[i];
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
41
|
+
}
|
|
42
|
+
return t;
|
|
43
|
+
};
|
|
44
|
+
return __assign.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function __rest(s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
50
|
+
t[p] = s[p];
|
|
51
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
52
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
53
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
54
|
+
t[p[i]] = s[p[i]];
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function __decorate(decorators, target, key, desc) {
|
|
60
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
61
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
62
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
63
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function __param(paramIndex, decorator) {
|
|
67
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function __metadata(metadataKey, metadataValue) {
|
|
71
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
72
|
+
}
|
|
21
73
|
|
|
22
74
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
75
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
76
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
77
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
78
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
79
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
80
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
81
|
});
|
|
29
82
|
}
|
|
@@ -56,15 +109,20 @@
|
|
|
56
109
|
}
|
|
57
110
|
}
|
|
58
111
|
|
|
112
|
+
function __exportStar(m, exports) {
|
|
113
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
114
|
+
}
|
|
115
|
+
|
|
59
116
|
function __values(o) {
|
|
60
|
-
var
|
|
117
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
61
118
|
if (m) return m.call(o);
|
|
62
|
-
return {
|
|
119
|
+
if (o && typeof o.length === "number") return {
|
|
63
120
|
next: function () {
|
|
64
121
|
if (o && i >= o.length) o = void 0;
|
|
65
122
|
return { value: o && o[i++], done: !o };
|
|
66
123
|
}
|
|
67
124
|
};
|
|
125
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
68
126
|
}
|
|
69
127
|
|
|
70
128
|
function __read(o, n) {
|
|
@@ -88,24 +146,87 @@
|
|
|
88
146
|
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
89
147
|
ar = ar.concat(__read(arguments[i]));
|
|
90
148
|
return ar;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function __spreadArrays() {
|
|
152
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
153
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
154
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
155
|
+
r[k] = a[j];
|
|
156
|
+
return r;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
function __await(v) {
|
|
160
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
164
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
165
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
166
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
167
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
168
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
169
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
170
|
+
function fulfill(value) { resume("next", value); }
|
|
171
|
+
function reject(value) { resume("throw", value); }
|
|
172
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function __asyncDelegator(o) {
|
|
176
|
+
var i, p;
|
|
177
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
178
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function __asyncValues(o) {
|
|
182
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
183
|
+
var m = o[Symbol.asyncIterator], i;
|
|
184
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
185
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
186
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function __makeTemplateObject(cooked, raw) {
|
|
190
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
191
|
+
return cooked;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
function __importStar(mod) {
|
|
195
|
+
if (mod && mod.__esModule) return mod;
|
|
196
|
+
var result = {};
|
|
197
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
198
|
+
result.default = mod;
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function __importDefault(mod) {
|
|
203
|
+
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function __classPrivateFieldGet(receiver, privateMap) {
|
|
207
|
+
if (!privateMap.has(receiver)) {
|
|
208
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
209
|
+
}
|
|
210
|
+
return privateMap.get(receiver);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
214
|
+
if (!privateMap.has(receiver)) {
|
|
215
|
+
throw new TypeError("attempted to set private field on non-instance");
|
|
216
|
+
}
|
|
217
|
+
privateMap.set(receiver, value);
|
|
218
|
+
return value;
|
|
91
219
|
}
|
|
92
220
|
|
|
93
|
-
|
|
94
|
-
OnAuthError
|
|
95
|
-
OnAuthLogout
|
|
96
|
-
OnAuthRefreshError
|
|
97
|
-
OnAuthRefreshSuccess
|
|
98
|
-
OnAuthSuccess
|
|
99
|
-
OnReady
|
|
100
|
-
OnTokenExpired
|
|
101
|
-
};
|
|
102
|
-
KeycloakEventType[KeycloakEventType.OnAuthError] = 'OnAuthError';
|
|
103
|
-
KeycloakEventType[KeycloakEventType.OnAuthLogout] = 'OnAuthLogout';
|
|
104
|
-
KeycloakEventType[KeycloakEventType.OnAuthRefreshError] = 'OnAuthRefreshError';
|
|
105
|
-
KeycloakEventType[KeycloakEventType.OnAuthRefreshSuccess] = 'OnAuthRefreshSuccess';
|
|
106
|
-
KeycloakEventType[KeycloakEventType.OnAuthSuccess] = 'OnAuthSuccess';
|
|
107
|
-
KeycloakEventType[KeycloakEventType.OnReady] = 'OnReady';
|
|
108
|
-
KeycloakEventType[KeycloakEventType.OnTokenExpired] = 'OnTokenExpired';
|
|
221
|
+
(function (KeycloakEventType) {
|
|
222
|
+
KeycloakEventType[KeycloakEventType["OnAuthError"] = 0] = "OnAuthError";
|
|
223
|
+
KeycloakEventType[KeycloakEventType["OnAuthLogout"] = 1] = "OnAuthLogout";
|
|
224
|
+
KeycloakEventType[KeycloakEventType["OnAuthRefreshError"] = 2] = "OnAuthRefreshError";
|
|
225
|
+
KeycloakEventType[KeycloakEventType["OnAuthRefreshSuccess"] = 3] = "OnAuthRefreshSuccess";
|
|
226
|
+
KeycloakEventType[KeycloakEventType["OnAuthSuccess"] = 4] = "OnAuthSuccess";
|
|
227
|
+
KeycloakEventType[KeycloakEventType["OnReady"] = 5] = "OnReady";
|
|
228
|
+
KeycloakEventType[KeycloakEventType["OnTokenExpired"] = 6] = "OnTokenExpired";
|
|
229
|
+
})(exports.KeycloakEventType || (exports.KeycloakEventType = {}));
|
|
109
230
|
|
|
110
231
|
var KeycloakAuthGuard = (function () {
|
|
111
232
|
function KeycloakAuthGuard(router, keycloakAngular) {
|
|
@@ -114,7 +235,7 @@
|
|
|
114
235
|
}
|
|
115
236
|
KeycloakAuthGuard.prototype.canActivate = function (route, state) {
|
|
116
237
|
var _this = this;
|
|
117
|
-
return new Promise(
|
|
238
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
118
239
|
var _a, _b, result, error_1;
|
|
119
240
|
return __generator(this, function (_c) {
|
|
120
241
|
switch (_c.label) {
|
|
@@ -140,11 +261,21 @@
|
|
|
140
261
|
case 5: return [2];
|
|
141
262
|
}
|
|
142
263
|
});
|
|
143
|
-
}); })
|
|
264
|
+
}); });
|
|
144
265
|
};
|
|
145
266
|
return KeycloakAuthGuard;
|
|
146
267
|
}());
|
|
147
268
|
|
|
269
|
+
function toPromise(originalPromise) {
|
|
270
|
+
if (originalPromise instanceof Promise) {
|
|
271
|
+
return originalPromise;
|
|
272
|
+
}
|
|
273
|
+
return new Promise(function (resolve, reject) {
|
|
274
|
+
originalPromise.success(resolve);
|
|
275
|
+
originalPromise.error(reject);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
148
279
|
var Keycloak = Keycloak_;
|
|
149
280
|
var KeycloakService = (function () {
|
|
150
281
|
function KeycloakService() {
|
|
@@ -152,39 +283,39 @@
|
|
|
152
283
|
}
|
|
153
284
|
KeycloakService.prototype.bindsKeycloakEvents = function () {
|
|
154
285
|
var _this = this;
|
|
155
|
-
this._instance.onAuthError =
|
|
286
|
+
this._instance.onAuthError = function (errorData) {
|
|
156
287
|
_this._keycloakEvents$.next({
|
|
157
288
|
args: errorData,
|
|
158
|
-
type: KeycloakEventType.OnAuthError
|
|
289
|
+
type: exports.KeycloakEventType.OnAuthError,
|
|
159
290
|
});
|
|
160
|
-
}
|
|
161
|
-
this._instance.onAuthLogout =
|
|
162
|
-
_this._keycloakEvents$.next({ type: KeycloakEventType.OnAuthLogout });
|
|
163
|
-
}
|
|
164
|
-
this._instance.onAuthRefreshSuccess =
|
|
291
|
+
};
|
|
292
|
+
this._instance.onAuthLogout = function () {
|
|
293
|
+
_this._keycloakEvents$.next({ type: exports.KeycloakEventType.OnAuthLogout });
|
|
294
|
+
};
|
|
295
|
+
this._instance.onAuthRefreshSuccess = function () {
|
|
165
296
|
_this._keycloakEvents$.next({
|
|
166
|
-
type: KeycloakEventType.OnAuthRefreshSuccess
|
|
297
|
+
type: exports.KeycloakEventType.OnAuthRefreshSuccess,
|
|
167
298
|
});
|
|
168
|
-
}
|
|
169
|
-
this._instance.onAuthRefreshError =
|
|
299
|
+
};
|
|
300
|
+
this._instance.onAuthRefreshError = function () {
|
|
170
301
|
_this._keycloakEvents$.next({
|
|
171
|
-
type: KeycloakEventType.OnAuthRefreshError
|
|
302
|
+
type: exports.KeycloakEventType.OnAuthRefreshError,
|
|
172
303
|
});
|
|
173
|
-
}
|
|
174
|
-
this._instance.onAuthSuccess =
|
|
175
|
-
_this._keycloakEvents$.next({ type: KeycloakEventType.OnAuthSuccess });
|
|
176
|
-
}
|
|
177
|
-
this._instance.onTokenExpired =
|
|
304
|
+
};
|
|
305
|
+
this._instance.onAuthSuccess = function () {
|
|
306
|
+
_this._keycloakEvents$.next({ type: exports.KeycloakEventType.OnAuthSuccess });
|
|
307
|
+
};
|
|
308
|
+
this._instance.onTokenExpired = function () {
|
|
178
309
|
_this._keycloakEvents$.next({
|
|
179
|
-
type: KeycloakEventType.OnTokenExpired
|
|
310
|
+
type: exports.KeycloakEventType.OnTokenExpired,
|
|
180
311
|
});
|
|
181
|
-
}
|
|
182
|
-
this._instance.onReady =
|
|
312
|
+
};
|
|
313
|
+
this._instance.onReady = function (authenticated) {
|
|
183
314
|
_this._keycloakEvents$.next({
|
|
184
315
|
args: authenticated,
|
|
185
|
-
type: KeycloakEventType.OnReady
|
|
316
|
+
type: exports.KeycloakEventType.OnReady,
|
|
186
317
|
});
|
|
187
|
-
}
|
|
318
|
+
};
|
|
188
319
|
};
|
|
189
320
|
KeycloakService.prototype.loadExcludedUrls = function (bearerExcludedUrls) {
|
|
190
321
|
var e_1, _a;
|
|
@@ -199,7 +330,7 @@
|
|
|
199
330
|
else {
|
|
200
331
|
excludedUrl = {
|
|
201
332
|
urlPattern: new RegExp(item.url, 'i'),
|
|
202
|
-
httpMethods: item.httpMethods
|
|
333
|
+
httpMethods: item.httpMethods,
|
|
203
334
|
};
|
|
204
335
|
}
|
|
205
336
|
excludedUrls.push(excludedUrl);
|
|
@@ -224,90 +355,77 @@
|
|
|
224
355
|
this._silentRefresh = initOptions ? initOptions.flow === 'implicit' : false;
|
|
225
356
|
};
|
|
226
357
|
KeycloakService.prototype.init = function (options) {
|
|
227
|
-
var _this = this;
|
|
228
358
|
if (options === void 0) { options = {}; }
|
|
229
|
-
return
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return [2];
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}); }))
|
|
251
|
-
.error((function (kcError) {
|
|
252
|
-
var msg = 'An error happened during Keycloak initialization.';
|
|
253
|
-
if (kcError) {
|
|
254
|
-
var error = kcError.error, error_description = kcError.error_description;
|
|
255
|
-
msg = msg.concat("\nAdapter error details:\nError: " + error + "\nDescription: " + error_description);
|
|
359
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
360
|
+
var config, initOptions, authenticated;
|
|
361
|
+
return __generator(this, function (_a) {
|
|
362
|
+
switch (_a.label) {
|
|
363
|
+
case 0:
|
|
364
|
+
this.initServiceValues(options);
|
|
365
|
+
config = options.config, initOptions = options.initOptions;
|
|
366
|
+
this._instance = Keycloak(config);
|
|
367
|
+
this.bindsKeycloakEvents();
|
|
368
|
+
return [4, toPromise(this._instance.init(initOptions))];
|
|
369
|
+
case 1:
|
|
370
|
+
authenticated = _a.sent();
|
|
371
|
+
if (!(authenticated && this._loadUserProfileAtStartUp)) return [3, 3];
|
|
372
|
+
return [4, this.loadUserProfile()];
|
|
373
|
+
case 2:
|
|
374
|
+
_a.sent();
|
|
375
|
+
_a.label = 3;
|
|
376
|
+
case 3: return [2, authenticated];
|
|
256
377
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}));
|
|
378
|
+
});
|
|
379
|
+
});
|
|
260
380
|
};
|
|
261
381
|
KeycloakService.prototype.login = function (options) {
|
|
262
|
-
var _this = this;
|
|
263
382
|
if (options === void 0) { options = {}; }
|
|
264
|
-
return
|
|
265
|
-
|
|
266
|
-
.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}); }))
|
|
282
|
-
.error((function () { return reject("An error happened during the login."); }));
|
|
283
|
-
}));
|
|
383
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
384
|
+
return __generator(this, function (_a) {
|
|
385
|
+
switch (_a.label) {
|
|
386
|
+
case 0: return [4, toPromise(this._instance.login(options))];
|
|
387
|
+
case 1:
|
|
388
|
+
_a.sent();
|
|
389
|
+
if (!this._loadUserProfileAtStartUp) return [3, 3];
|
|
390
|
+
return [4, this.loadUserProfile()];
|
|
391
|
+
case 2:
|
|
392
|
+
_a.sent();
|
|
393
|
+
_a.label = 3;
|
|
394
|
+
case 3: return [2];
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
});
|
|
284
398
|
};
|
|
285
399
|
KeycloakService.prototype.logout = function (redirectUri) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
400
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
401
|
+
var options;
|
|
402
|
+
return __generator(this, function (_a) {
|
|
403
|
+
switch (_a.label) {
|
|
404
|
+
case 0:
|
|
405
|
+
options = {
|
|
406
|
+
redirectUri: redirectUri,
|
|
407
|
+
};
|
|
408
|
+
return [4, toPromise(this._instance.logout(options))];
|
|
409
|
+
case 1:
|
|
410
|
+
_a.sent();
|
|
411
|
+
this._userProfile = undefined;
|
|
412
|
+
return [2];
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
});
|
|
299
416
|
};
|
|
300
417
|
KeycloakService.prototype.register = function (options) {
|
|
301
|
-
var _this = this;
|
|
302
418
|
if (options === void 0) { options = { action: 'register' }; }
|
|
303
|
-
return
|
|
304
|
-
|
|
305
|
-
.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
419
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
420
|
+
return __generator(this, function (_a) {
|
|
421
|
+
switch (_a.label) {
|
|
422
|
+
case 0: return [4, toPromise(this._instance.register(options))];
|
|
423
|
+
case 1:
|
|
424
|
+
_a.sent();
|
|
425
|
+
return [2];
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
});
|
|
311
429
|
};
|
|
312
430
|
KeycloakService.prototype.isUserInRole = function (role, resource) {
|
|
313
431
|
var hasRole;
|
|
@@ -362,61 +480,45 @@
|
|
|
362
480
|
return this._instance.isTokenExpired(minValidity);
|
|
363
481
|
};
|
|
364
482
|
KeycloakService.prototype.updateToken = function (minValidity) {
|
|
365
|
-
var _this = this;
|
|
366
483
|
if (minValidity === void 0) { minValidity = 5; }
|
|
367
|
-
return
|
|
484
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
368
485
|
return __generator(this, function (_a) {
|
|
369
486
|
if (this._silentRefresh) {
|
|
370
487
|
if (this.isTokenExpired()) {
|
|
371
|
-
|
|
488
|
+
throw new Error('Failed to refresh the token, or the session is expired');
|
|
372
489
|
}
|
|
373
|
-
|
|
374
|
-
resolve(true);
|
|
375
|
-
}
|
|
376
|
-
return [2];
|
|
490
|
+
return [2, true];
|
|
377
491
|
}
|
|
378
492
|
if (!this._instance) {
|
|
379
|
-
|
|
380
|
-
return [2];
|
|
493
|
+
throw new Error('Keycloak Angular library is not initialized.');
|
|
381
494
|
}
|
|
382
|
-
this._instance
|
|
383
|
-
.updateToken(minValidity)
|
|
384
|
-
.success((function (refreshed) {
|
|
385
|
-
resolve(refreshed);
|
|
386
|
-
}))
|
|
387
|
-
.error((function () { return reject('Failed to refresh the token, or the session is expired'); }));
|
|
388
|
-
return [2];
|
|
495
|
+
return [2, toPromise(this._instance.updateToken(minValidity))];
|
|
389
496
|
});
|
|
390
|
-
});
|
|
497
|
+
});
|
|
391
498
|
};
|
|
392
499
|
KeycloakService.prototype.loadUserProfile = function (forceReload) {
|
|
393
|
-
var _this = this;
|
|
394
500
|
if (forceReload === void 0) { forceReload = false; }
|
|
395
|
-
return
|
|
396
|
-
var
|
|
397
|
-
return __generator(this, function (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
501
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
502
|
+
var _a;
|
|
503
|
+
return __generator(this, function (_b) {
|
|
504
|
+
switch (_b.label) {
|
|
505
|
+
case 0:
|
|
506
|
+
if (this._userProfile && !forceReload) {
|
|
507
|
+
return [2, this._userProfile];
|
|
508
|
+
}
|
|
509
|
+
if (!this._instance.authenticated) {
|
|
510
|
+
throw new Error('The user profile was not loaded as the user is not logged in.');
|
|
511
|
+
}
|
|
512
|
+
_a = this;
|
|
513
|
+
return [4, toPromise(this._instance.loadUserProfile())];
|
|
514
|
+
case 1: return [2, (_a._userProfile = _b.sent())];
|
|
405
515
|
}
|
|
406
|
-
this._instance
|
|
407
|
-
.loadUserProfile()
|
|
408
|
-
.success((function (result) {
|
|
409
|
-
_this._userProfile = ((result));
|
|
410
|
-
resolve(_this._userProfile);
|
|
411
|
-
}))
|
|
412
|
-
.error((function () { return reject('The user profile could not be loaded.'); }));
|
|
413
|
-
return [2];
|
|
414
516
|
});
|
|
415
|
-
});
|
|
517
|
+
});
|
|
416
518
|
};
|
|
417
|
-
KeycloakService.prototype.getToken = function () {
|
|
418
|
-
|
|
419
|
-
return
|
|
519
|
+
KeycloakService.prototype.getToken = function (forceLogin) {
|
|
520
|
+
if (forceLogin === void 0) { forceLogin = true; }
|
|
521
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
420
522
|
var error_2;
|
|
421
523
|
return __generator(this, function (_a) {
|
|
422
524
|
switch (_a.label) {
|
|
@@ -425,22 +527,26 @@
|
|
|
425
527
|
return [4, this.updateToken(10)];
|
|
426
528
|
case 1:
|
|
427
529
|
_a.sent();
|
|
428
|
-
|
|
429
|
-
return [3, 3];
|
|
530
|
+
return [2, this._instance.token];
|
|
430
531
|
case 2:
|
|
431
532
|
error_2 = _a.sent();
|
|
432
|
-
|
|
533
|
+
if (forceLogin) {
|
|
534
|
+
this.login();
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
throw error_2;
|
|
538
|
+
}
|
|
433
539
|
return [3, 3];
|
|
434
540
|
case 3: return [2];
|
|
435
541
|
}
|
|
436
542
|
});
|
|
437
|
-
});
|
|
543
|
+
});
|
|
438
544
|
};
|
|
439
545
|
KeycloakService.prototype.getUsername = function () {
|
|
440
546
|
if (!this._userProfile) {
|
|
441
547
|
throw new Error('User not logged in or user profile was not loaded.');
|
|
442
548
|
}
|
|
443
|
-
return
|
|
549
|
+
return this._userProfile.username;
|
|
444
550
|
};
|
|
445
551
|
KeycloakService.prototype.clearToken = function () {
|
|
446
552
|
this._instance.clearToken();
|
|
@@ -448,27 +554,9 @@
|
|
|
448
554
|
KeycloakService.prototype.addTokenToHeader = function (headers) {
|
|
449
555
|
var _this = this;
|
|
450
556
|
if (headers === void 0) { headers = new http.HttpHeaders(); }
|
|
451
|
-
return rxjs.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
switch (_a.label) {
|
|
455
|
-
case 0:
|
|
456
|
-
_a.trys.push([0, 2, , 3]);
|
|
457
|
-
return [4, this.getToken()];
|
|
458
|
-
case 1:
|
|
459
|
-
token = _a.sent();
|
|
460
|
-
headers = headers.set(this._authorizationHeaderName, this._bearerPrefix + token);
|
|
461
|
-
observer.next(headers);
|
|
462
|
-
observer.complete();
|
|
463
|
-
return [3, 3];
|
|
464
|
-
case 2:
|
|
465
|
-
error_3 = _a.sent();
|
|
466
|
-
observer.error(error_3);
|
|
467
|
-
return [3, 3];
|
|
468
|
-
case 3: return [2];
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
}); }));
|
|
557
|
+
return rxjs.from(this.getToken()).pipe(operators.map(function (token) {
|
|
558
|
+
return headers.set(_this._authorizationHeaderName, _this._bearerPrefix + token);
|
|
559
|
+
}));
|
|
472
560
|
};
|
|
473
561
|
KeycloakService.prototype.getKeycloakInstance = function () {
|
|
474
562
|
return this._instance;
|
|
@@ -494,9 +582,9 @@
|
|
|
494
582
|
enumerable: true,
|
|
495
583
|
configurable: true
|
|
496
584
|
});
|
|
497
|
-
KeycloakService
|
|
498
|
-
|
|
499
|
-
];
|
|
585
|
+
KeycloakService = __decorate([
|
|
586
|
+
core.Injectable()
|
|
587
|
+
], KeycloakService);
|
|
500
588
|
return KeycloakService;
|
|
501
589
|
}());
|
|
502
590
|
|
|
@@ -518,51 +606,57 @@
|
|
|
518
606
|
if (!enableBearerInterceptor) {
|
|
519
607
|
return next.handle(req);
|
|
520
608
|
}
|
|
521
|
-
var shallPass = excludedUrls.findIndex(
|
|
609
|
+
var shallPass = excludedUrls.findIndex(function (item) { return _this.isUrlExcluded(req, item); }) > -1;
|
|
522
610
|
if (shallPass) {
|
|
523
611
|
return next.handle(req);
|
|
524
612
|
}
|
|
525
|
-
return this.keycloak.
|
|
613
|
+
return rxjs.from(this.keycloak.isLoggedIn()).pipe(operators.mergeMap(function (loggedIn) { return loggedIn
|
|
614
|
+
? _this.handleRequestWithTokenHeader(req, next)
|
|
615
|
+
: next.handle(req); }));
|
|
616
|
+
};
|
|
617
|
+
KeycloakBearerInterceptor.prototype.handleRequestWithTokenHeader = function (req, next) {
|
|
618
|
+
return this.keycloak.addTokenToHeader(req.headers).pipe(operators.mergeMap(function (headersWithBearer) {
|
|
526
619
|
var kcReq = req.clone({ headers: headersWithBearer });
|
|
527
620
|
return next.handle(kcReq);
|
|
528
|
-
}))
|
|
621
|
+
}));
|
|
529
622
|
};
|
|
530
|
-
KeycloakBearerInterceptor.decorators = [
|
|
531
|
-
{ type: core.Injectable }
|
|
532
|
-
];
|
|
533
623
|
KeycloakBearerInterceptor.ctorParameters = function () { return [
|
|
534
624
|
{ type: KeycloakService }
|
|
535
625
|
]; };
|
|
626
|
+
KeycloakBearerInterceptor = __decorate([
|
|
627
|
+
core.Injectable(),
|
|
628
|
+
__metadata("design:paramtypes", [KeycloakService])
|
|
629
|
+
], KeycloakBearerInterceptor);
|
|
536
630
|
return KeycloakBearerInterceptor;
|
|
537
631
|
}());
|
|
538
632
|
|
|
539
633
|
var CoreModule = (function () {
|
|
540
634
|
function CoreModule() {
|
|
541
635
|
}
|
|
542
|
-
CoreModule
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
];
|
|
636
|
+
CoreModule = __decorate([
|
|
637
|
+
core.NgModule({
|
|
638
|
+
imports: [common.CommonModule],
|
|
639
|
+
providers: [
|
|
640
|
+
KeycloakService,
|
|
641
|
+
{
|
|
642
|
+
provide: http.HTTP_INTERCEPTORS,
|
|
643
|
+
useClass: KeycloakBearerInterceptor,
|
|
644
|
+
multi: true
|
|
645
|
+
}
|
|
646
|
+
]
|
|
647
|
+
})
|
|
648
|
+
], CoreModule);
|
|
555
649
|
return CoreModule;
|
|
556
650
|
}());
|
|
557
651
|
|
|
558
652
|
var KeycloakAngularModule = (function () {
|
|
559
653
|
function KeycloakAngularModule() {
|
|
560
654
|
}
|
|
561
|
-
KeycloakAngularModule
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
];
|
|
655
|
+
KeycloakAngularModule = __decorate([
|
|
656
|
+
core.NgModule({
|
|
657
|
+
imports: [CoreModule]
|
|
658
|
+
})
|
|
659
|
+
], KeycloakAngularModule);
|
|
566
660
|
return KeycloakAngularModule;
|
|
567
661
|
}());
|
|
568
662
|
|
|
@@ -570,10 +664,9 @@
|
|
|
570
664
|
exports.KeycloakAngularModule = KeycloakAngularModule;
|
|
571
665
|
exports.KeycloakAuthGuard = KeycloakAuthGuard;
|
|
572
666
|
exports.KeycloakBearerInterceptor = KeycloakBearerInterceptor;
|
|
573
|
-
exports.KeycloakEventType = KeycloakEventType;
|
|
574
667
|
exports.KeycloakService = KeycloakService;
|
|
575
668
|
|
|
576
669
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
577
670
|
|
|
578
|
-
}));
|
|
671
|
+
})));
|
|
579
672
|
//# sourceMappingURL=keycloak-angular.umd.js.map
|