1 | function _inheritsLoose(e, t) {
|
2 | (e.prototype = Object.create(t.prototype)), (e.prototype.constructor = e), _setPrototypeOf(e, t);
|
3 | }
|
4 | function _setPrototypeOf(e, t) {
|
5 | return (
|
6 | (_setPrototypeOf = Object.setPrototypeOf
|
7 | ? Object.setPrototypeOf.bind()
|
8 | : function (e, t) {
|
9 | return (e.__proto__ = t), e;
|
10 | }),
|
11 | _setPrototypeOf(e, t)
|
12 | );
|
13 | }
|
14 | function _assertThisInitialized(e) {
|
15 | if (void 0 === e)
|
16 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
17 | return e;
|
18 | }
|
19 | for (
|
20 | var byteLength_1 = byteLength,
|
21 | toByteArray_1 = toByteArray,
|
22 | fromByteArray_1 = fromByteArray,
|
23 | lookup = [],
|
24 | revLookup = [],
|
25 | Arr = 'undefined' != typeof Uint8Array ? Uint8Array : Array,
|
26 | code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
27 | i = 0,
|
28 | len = code.length;
|
29 | i < len;
|
30 | ++i
|
31 | )
|
32 | (lookup[i] = code[i]), (revLookup[code.charCodeAt(i)] = i);
|
33 | function getLens(e) {
|
34 | var t = e.length;
|
35 | if (t % 4 > 0) throw new Error('Invalid string. Length must be a multiple of 4');
|
36 | var r = e.indexOf('=');
|
37 | return -1 === r && (r = t), [r, r === t ? 0 : 4 - (r % 4)];
|
38 | }
|
39 | function byteLength(e) {
|
40 | var t = getLens(e),
|
41 | r = t[1];
|
42 | return (3 * (t[0] + r)) / 4 - r;
|
43 | }
|
44 | function _byteLength(e, t, r) {
|
45 | return (3 * (t + r)) / 4 - r;
|
46 | }
|
47 | function toByteArray(e) {
|
48 | var t,
|
49 | r,
|
50 | o = getLens(e),
|
51 | n = o[0],
|
52 | i = o[1],
|
53 | s = new Arr(_byteLength(e, n, i)),
|
54 | a = 0,
|
55 | c = i > 0 ? n - 4 : n;
|
56 | for (r = 0; r < c; r += 4)
|
57 | (t =
|
58 | (revLookup[e.charCodeAt(r)] << 18) |
|
59 | (revLookup[e.charCodeAt(r + 1)] << 12) |
|
60 | (revLookup[e.charCodeAt(r + 2)] << 6) |
|
61 | revLookup[e.charCodeAt(r + 3)]),
|
62 | (s[a++] = (t >> 16) & 255),
|
63 | (s[a++] = (t >> 8) & 255),
|
64 | (s[a++] = 255 & t);
|
65 | return (
|
66 | 2 === i &&
|
67 | ((t = (revLookup[e.charCodeAt(r)] << 2) | (revLookup[e.charCodeAt(r + 1)] >> 4)),
|
68 | (s[a++] = 255 & t)),
|
69 | 1 === i &&
|
70 | ((t =
|
71 | (revLookup[e.charCodeAt(r)] << 10) |
|
72 | (revLookup[e.charCodeAt(r + 1)] << 4) |
|
73 | (revLookup[e.charCodeAt(r + 2)] >> 2)),
|
74 | (s[a++] = (t >> 8) & 255),
|
75 | (s[a++] = 255 & t)),
|
76 | s
|
77 | );
|
78 | }
|
79 | function tripletToBase64(e) {
|
80 | return lookup[(e >> 18) & 63] + lookup[(e >> 12) & 63] + lookup[(e >> 6) & 63] + lookup[63 & e];
|
81 | }
|
82 | function encodeChunk(e, t, r) {
|
83 | for (var o = [], n = t; n < r; n += 3)
|
84 | o.push(
|
85 | tripletToBase64(((e[n] << 16) & 16711680) + ((e[n + 1] << 8) & 65280) + (255 & e[n + 2]))
|
86 | );
|
87 | return o.join('');
|
88 | }
|
89 | function fromByteArray(e) {
|
90 | for (var t, r = e.length, o = r % 3, n = [], i = 16383, s = 0, a = r - o; s < a; s += i)
|
91 | n.push(encodeChunk(e, s, s + i > a ? a : s + i));
|
92 | return (
|
93 | 1 === o
|
94 | ? n.push(lookup[(t = e[r - 1]) >> 2] + lookup[(t << 4) & 63] + '==')
|
95 | : 2 === o &&
|
96 | n.push(
|
97 | lookup[(t = (e[r - 2] << 8) + e[r - 1]) >> 10] +
|
98 | lookup[(t >> 4) & 63] +
|
99 | lookup[(t << 2) & 63] +
|
100 | '='
|
101 | ),
|
102 | n.join('')
|
103 | );
|
104 | }
|
105 | (revLookup['-'.charCodeAt(0)] = 62), (revLookup['_'.charCodeAt(0)] = 63);
|
106 | var base64Js = {
|
107 | byteLength: byteLength_1,
|
108 | toByteArray: toByteArray_1,
|
109 | fromByteArray: fromByteArray_1,
|
110 | },
|
111 | commonjsGlobal =
|
112 | 'undefined' != typeof globalThis
|
113 | ? globalThis
|
114 | : 'undefined' != typeof window
|
115 | ? window
|
116 | : 'undefined' != typeof global
|
117 | ? global
|
118 | : 'undefined' != typeof self
|
119 | ? self
|
120 | : {};
|
121 | function createCommonjsModule(e) {
|
122 | var t = { exports: {} };
|
123 | return e(t, t.exports), t.exports;
|
124 | }
|
125 | var sha256 = createCommonjsModule(function (module) {
|
126 | (function () {
|
127 | var ERROR = 'input is invalid type',
|
128 | WINDOW = 'object' == typeof window,
|
129 | root = WINDOW ? window : {};
|
130 | root.JS_SHA256_NO_WINDOW && (WINDOW = !1);
|
131 | var WEB_WORKER = !WINDOW && 'object' == typeof self,
|
132 | NODE_JS =
|
133 | !root.JS_SHA256_NO_NODE_JS &&
|
134 | 'object' == typeof process &&
|
135 | process.versions &&
|
136 | process.versions.node;
|
137 | NODE_JS ? (root = commonjsGlobal) : WEB_WORKER && (root = self);
|
138 | var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && module.exports,
|
139 | ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && 'undefined' != typeof ArrayBuffer,
|
140 | HEX_CHARS = '0123456789abcdef'.split(''),
|
141 | EXTRA = [-2147483648, 8388608, 32768, 128],
|
142 | SHIFT = [24, 16, 8, 0],
|
143 | K = [
|
144 | 1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748,
|
145 | 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206,
|
146 | 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122,
|
147 | 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891,
|
148 | 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700,
|
149 | 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771,
|
150 | 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877,
|
151 | 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452,
|
152 | 2361852424, 2428436474, 2756734187, 3204031479, 3329325298,
|
153 | ],
|
154 | OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'],
|
155 | blocks = [];
|
156 | (!root.JS_SHA256_NO_NODE_JS && Array.isArray) ||
|
157 | (Array.isArray = function (e) {
|
158 | return '[object Array]' === Object.prototype.toString.call(e);
|
159 | }),
|
160 | !ARRAY_BUFFER ||
|
161 | (!root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW && ArrayBuffer.isView) ||
|
162 | (ArrayBuffer.isView = function (e) {
|
163 | return 'object' == typeof e && e.buffer && e.buffer.constructor === ArrayBuffer;
|
164 | });
|
165 | var createOutputMethod = function (e, t) {
|
166 | return function (r) {
|
167 | return new Sha256(t, !0).update(r)[e]();
|
168 | };
|
169 | },
|
170 | createMethod = function (e) {
|
171 | var t = createOutputMethod('hex', e);
|
172 | NODE_JS && (t = nodeWrap(t, e)),
|
173 | (t.create = function () {
|
174 | return new Sha256(e);
|
175 | }),
|
176 | (t.update = function (e) {
|
177 | return t.create().update(e);
|
178 | });
|
179 | for (var r = 0; r < OUTPUT_TYPES.length; ++r) {
|
180 | var o = OUTPUT_TYPES[r];
|
181 | t[o] = createOutputMethod(o, e);
|
182 | }
|
183 | return t;
|
184 | },
|
185 | nodeWrap = function (method, is224) {
|
186 | var crypto = eval("require('crypto')"),
|
187 | Buffer = eval("require('buffer').Buffer"),
|
188 | algorithm = is224 ? 'sha224' : 'sha256',
|
189 | nodeMethod = function (e) {
|
190 | if ('string' == typeof e)
|
191 | return crypto.createHash(algorithm).update(e, 'utf8').digest('hex');
|
192 | if (null == e) throw new Error(ERROR);
|
193 | return (
|
194 | e.constructor === ArrayBuffer && (e = new Uint8Array(e)),
|
195 | Array.isArray(e) || ArrayBuffer.isView(e) || e.constructor === Buffer
|
196 | ? crypto.createHash(algorithm).update(new Buffer(e)).digest('hex')
|
197 | : method(e)
|
198 | );
|
199 | };
|
200 | return nodeMethod;
|
201 | },
|
202 | createHmacOutputMethod = function (e, t) {
|
203 | return function (r, o) {
|
204 | return new HmacSha256(r, t, !0).update(o)[e]();
|
205 | };
|
206 | },
|
207 | createHmacMethod = function (e) {
|
208 | var t = createHmacOutputMethod('hex', e);
|
209 | (t.create = function (t) {
|
210 | return new HmacSha256(t, e);
|
211 | }),
|
212 | (t.update = function (e, r) {
|
213 | return t.create(e).update(r);
|
214 | });
|
215 | for (var r = 0; r < OUTPUT_TYPES.length; ++r) {
|
216 | var o = OUTPUT_TYPES[r];
|
217 | t[o] = createHmacOutputMethod(o, e);
|
218 | }
|
219 | return t;
|
220 | };
|
221 | function Sha256(e, t) {
|
222 | t
|
223 | ? ((blocks[0] =
|
224 | blocks[16] =
|
225 | blocks[1] =
|
226 | blocks[2] =
|
227 | blocks[3] =
|
228 | blocks[4] =
|
229 | blocks[5] =
|
230 | blocks[6] =
|
231 | blocks[7] =
|
232 | blocks[8] =
|
233 | blocks[9] =
|
234 | blocks[10] =
|
235 | blocks[11] =
|
236 | blocks[12] =
|
237 | blocks[13] =
|
238 | blocks[14] =
|
239 | blocks[15] =
|
240 | 0),
|
241 | (this.blocks = blocks))
|
242 | : (this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
243 | e
|
244 | ? ((this.h0 = 3238371032),
|
245 | (this.h1 = 914150663),
|
246 | (this.h2 = 812702999),
|
247 | (this.h3 = 4144912697),
|
248 | (this.h4 = 4290775857),
|
249 | (this.h5 = 1750603025),
|
250 | (this.h6 = 1694076839),
|
251 | (this.h7 = 3204075428))
|
252 | : ((this.h0 = 1779033703),
|
253 | (this.h1 = 3144134277),
|
254 | (this.h2 = 1013904242),
|
255 | (this.h3 = 2773480762),
|
256 | (this.h4 = 1359893119),
|
257 | (this.h5 = 2600822924),
|
258 | (this.h6 = 528734635),
|
259 | (this.h7 = 1541459225)),
|
260 | (this.block = this.start = this.bytes = this.hBytes = 0),
|
261 | (this.finalized = this.hashed = !1),
|
262 | (this.first = !0),
|
263 | (this.is224 = e);
|
264 | }
|
265 | function HmacSha256(e, t, r) {
|
266 | var o,
|
267 | n = typeof e;
|
268 | if ('string' === n) {
|
269 | var i,
|
270 | s = [],
|
271 | a = e.length,
|
272 | c = 0;
|
273 | for (o = 0; o < a; ++o)
|
274 | (i = e.charCodeAt(o)) < 128
|
275 | ? (s[c++] = i)
|
276 | : i < 2048
|
277 | ? ((s[c++] = 192 | (i >> 6)), (s[c++] = 128 | (63 & i)))
|
278 | : i < 55296 || i >= 57344
|
279 | ? ((s[c++] = 224 | (i >> 12)),
|
280 | (s[c++] = 128 | ((i >> 6) & 63)),
|
281 | (s[c++] = 128 | (63 & i)))
|
282 | : ((i = 65536 + (((1023 & i) << 10) | (1023 & e.charCodeAt(++o)))),
|
283 | (s[c++] = 240 | (i >> 18)),
|
284 | (s[c++] = 128 | ((i >> 12) & 63)),
|
285 | (s[c++] = 128 | ((i >> 6) & 63)),
|
286 | (s[c++] = 128 | (63 & i)));
|
287 | e = s;
|
288 | } else {
|
289 | if ('object' !== n) throw new Error(ERROR);
|
290 | if (null === e) throw new Error(ERROR);
|
291 | if (ARRAY_BUFFER && e.constructor === ArrayBuffer) e = new Uint8Array(e);
|
292 | else if (!(Array.isArray(e) || (ARRAY_BUFFER && ArrayBuffer.isView(e))))
|
293 | throw new Error(ERROR);
|
294 | }
|
295 | e.length > 64 && (e = new Sha256(t, !0).update(e).array());
|
296 | var u = [],
|
297 | l = [];
|
298 | for (o = 0; o < 64; ++o) {
|
299 | var d = e[o] || 0;
|
300 | (u[o] = 92 ^ d), (l[o] = 54 ^ d);
|
301 | }
|
302 | Sha256.call(this, t, r),
|
303 | this.update(l),
|
304 | (this.oKeyPad = u),
|
305 | (this.inner = !0),
|
306 | (this.sharedMemory = r);
|
307 | }
|
308 | (Sha256.prototype.update = function (e) {
|
309 | if (!this.finalized) {
|
310 | var t,
|
311 | r = typeof e;
|
312 | if ('string' !== r) {
|
313 | if ('object' !== r) throw new Error(ERROR);
|
314 | if (null === e) throw new Error(ERROR);
|
315 | if (ARRAY_BUFFER && e.constructor === ArrayBuffer) e = new Uint8Array(e);
|
316 | else if (!(Array.isArray(e) || (ARRAY_BUFFER && ArrayBuffer.isView(e))))
|
317 | throw new Error(ERROR);
|
318 | t = !0;
|
319 | }
|
320 | for (var o, n, i = 0, s = e.length, a = this.blocks; i < s; ) {
|
321 | if (
|
322 | (this.hashed &&
|
323 | ((this.hashed = !1),
|
324 | (a[0] = this.block),
|
325 | (a[16] =
|
326 | a[1] =
|
327 | a[2] =
|
328 | a[3] =
|
329 | a[4] =
|
330 | a[5] =
|
331 | a[6] =
|
332 | a[7] =
|
333 | a[8] =
|
334 | a[9] =
|
335 | a[10] =
|
336 | a[11] =
|
337 | a[12] =
|
338 | a[13] =
|
339 | a[14] =
|
340 | a[15] =
|
341 | 0)),
|
342 | t)
|
343 | )
|
344 | for (n = this.start; i < s && n < 64; ++i) a[n >> 2] |= e[i] << SHIFT[3 & n++];
|
345 | else
|
346 | for (n = this.start; i < s && n < 64; ++i)
|
347 | (o = e.charCodeAt(i)) < 128
|
348 | ? (a[n >> 2] |= o << SHIFT[3 & n++])
|
349 | : o < 2048
|
350 | ? ((a[n >> 2] |= (192 | (o >> 6)) << SHIFT[3 & n++]),
|
351 | (a[n >> 2] |= (128 | (63 & o)) << SHIFT[3 & n++]))
|
352 | : o < 55296 || o >= 57344
|
353 | ? ((a[n >> 2] |= (224 | (o >> 12)) << SHIFT[3 & n++]),
|
354 | (a[n >> 2] |= (128 | ((o >> 6) & 63)) << SHIFT[3 & n++]),
|
355 | (a[n >> 2] |= (128 | (63 & o)) << SHIFT[3 & n++]))
|
356 | : ((o = 65536 + (((1023 & o) << 10) | (1023 & e.charCodeAt(++i)))),
|
357 | (a[n >> 2] |= (240 | (o >> 18)) << SHIFT[3 & n++]),
|
358 | (a[n >> 2] |= (128 | ((o >> 12) & 63)) << SHIFT[3 & n++]),
|
359 | (a[n >> 2] |= (128 | ((o >> 6) & 63)) << SHIFT[3 & n++]),
|
360 | (a[n >> 2] |= (128 | (63 & o)) << SHIFT[3 & n++]));
|
361 | (this.lastByteIndex = n),
|
362 | (this.bytes += n - this.start),
|
363 | n >= 64
|
364 | ? ((this.block = a[16]), (this.start = n - 64), this.hash(), (this.hashed = !0))
|
365 | : (this.start = n);
|
366 | }
|
367 | return (
|
368 | this.bytes > 4294967295 &&
|
369 | ((this.hBytes += (this.bytes / 4294967296) << 0),
|
370 | (this.bytes = this.bytes % 4294967296)),
|
371 | this
|
372 | );
|
373 | }
|
374 | }),
|
375 | (Sha256.prototype.finalize = function () {
|
376 | if (!this.finalized) {
|
377 | this.finalized = !0;
|
378 | var e = this.blocks,
|
379 | t = this.lastByteIndex;
|
380 | (e[16] = this.block),
|
381 | (e[t >> 2] |= EXTRA[3 & t]),
|
382 | (this.block = e[16]),
|
383 | t >= 56 &&
|
384 | (this.hashed || this.hash(),
|
385 | (e[0] = this.block),
|
386 | (e[16] =
|
387 | e[1] =
|
388 | e[2] =
|
389 | e[3] =
|
390 | e[4] =
|
391 | e[5] =
|
392 | e[6] =
|
393 | e[7] =
|
394 | e[8] =
|
395 | e[9] =
|
396 | e[10] =
|
397 | e[11] =
|
398 | e[12] =
|
399 | e[13] =
|
400 | e[14] =
|
401 | e[15] =
|
402 | 0)),
|
403 | (e[14] = (this.hBytes << 3) | (this.bytes >>> 29)),
|
404 | (e[15] = this.bytes << 3),
|
405 | this.hash();
|
406 | }
|
407 | }),
|
408 | (Sha256.prototype.hash = function () {
|
409 | var e,
|
410 | t,
|
411 | r,
|
412 | o,
|
413 | n,
|
414 | i,
|
415 | s = this.h0,
|
416 | a = this.h1,
|
417 | c = this.h2,
|
418 | u = this.h3,
|
419 | l = this.h4,
|
420 | d = this.h5,
|
421 | h = this.h6,
|
422 | f = this.h7,
|
423 | p = this.blocks;
|
424 | for (e = 16; e < 64; ++e)
|
425 | p[e] =
|
426 | (p[e - 16] +
|
427 | ((((t = p[e - 15]) >>> 7) | (t << 25)) ^ ((t >>> 18) | (t << 14)) ^ (t >>> 3)) +
|
428 | p[e - 7] +
|
429 | ((((t = p[e - 2]) >>> 17) | (t << 15)) ^ ((t >>> 19) | (t << 13)) ^ (t >>> 10))) <<
|
430 | 0;
|
431 | for (i = a & c, e = 0; e < 64; e += 4)
|
432 | this.first
|
433 | ? (this.is224
|
434 | ? ((r = 300032),
|
435 | (f = ((t = p[0] - 1413257819) - 150054599) << 0),
|
436 | (u = (t + 24177077) << 0))
|
437 | : ((r = 704751109),
|
438 | (f = ((t = p[0] - 210244248) - 1521486534) << 0),
|
439 | (u = (t + 143694565) << 0)),
|
440 | (this.first = !1))
|
441 | : ((f =
|
442 | (u +
|
443 | (t =
|
444 | f +
|
445 | (((l >>> 6) | (l << 26)) ^ ((l >>> 11) | (l << 21)) ^ ((l >>> 25) | (l << 7))) +
|
446 | ((l & d) ^ (~l & h)) +
|
447 | K[e] +
|
448 | p[e])) <<
|
449 | 0),
|
450 | (u =
|
451 | (t +
|
452 | ((((s >>> 2) | (s << 30)) ^ ((s >>> 13) | (s << 19)) ^ ((s >>> 22) | (s << 10))) +
|
453 | ((r = s & a) ^ (s & c) ^ i))) <<
|
454 | 0)),
|
455 | (h =
|
456 | (c +
|
457 | (t =
|
458 | h +
|
459 | (((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7))) +
|
460 | ((f & l) ^ (~f & d)) +
|
461 | K[e + 1] +
|
462 | p[e + 1])) <<
|
463 | 0),
|
464 | (c =
|
465 | (t +
|
466 | ((((u >>> 2) | (u << 30)) ^ ((u >>> 13) | (u << 19)) ^ ((u >>> 22) | (u << 10))) +
|
467 | ((o = u & s) ^ (u & a) ^ r))) <<
|
468 | 0),
|
469 | (d =
|
470 | (a +
|
471 | (t =
|
472 | d +
|
473 | (((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7))) +
|
474 | ((h & f) ^ (~h & l)) +
|
475 | K[e + 2] +
|
476 | p[e + 2])) <<
|
477 | 0),
|
478 | (a =
|
479 | (t +
|
480 | ((((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10))) +
|
481 | ((n = c & u) ^ (c & s) ^ o))) <<
|
482 | 0),
|
483 | (l =
|
484 | (s +
|
485 | (t =
|
486 | l +
|
487 | (((d >>> 6) | (d << 26)) ^ ((d >>> 11) | (d << 21)) ^ ((d >>> 25) | (d << 7))) +
|
488 | ((d & h) ^ (~d & f)) +
|
489 | K[e + 3] +
|
490 | p[e + 3])) <<
|
491 | 0),
|
492 | (s =
|
493 | (t +
|
494 | ((((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10))) +
|
495 | ((i = a & c) ^ (a & u) ^ n))) <<
|
496 | 0);
|
497 | (this.h0 = (this.h0 + s) << 0),
|
498 | (this.h1 = (this.h1 + a) << 0),
|
499 | (this.h2 = (this.h2 + c) << 0),
|
500 | (this.h3 = (this.h3 + u) << 0),
|
501 | (this.h4 = (this.h4 + l) << 0),
|
502 | (this.h5 = (this.h5 + d) << 0),
|
503 | (this.h6 = (this.h6 + h) << 0),
|
504 | (this.h7 = (this.h7 + f) << 0);
|
505 | }),
|
506 | (Sha256.prototype.hex = function () {
|
507 | this.finalize();
|
508 | var e = this.h0,
|
509 | t = this.h1,
|
510 | r = this.h2,
|
511 | o = this.h3,
|
512 | n = this.h4,
|
513 | i = this.h5,
|
514 | s = this.h6,
|
515 | a = this.h7,
|
516 | c =
|
517 | HEX_CHARS[(e >> 28) & 15] +
|
518 | HEX_CHARS[(e >> 24) & 15] +
|
519 | HEX_CHARS[(e >> 20) & 15] +
|
520 | HEX_CHARS[(e >> 16) & 15] +
|
521 | HEX_CHARS[(e >> 12) & 15] +
|
522 | HEX_CHARS[(e >> 8) & 15] +
|
523 | HEX_CHARS[(e >> 4) & 15] +
|
524 | HEX_CHARS[15 & e] +
|
525 | HEX_CHARS[(t >> 28) & 15] +
|
526 | HEX_CHARS[(t >> 24) & 15] +
|
527 | HEX_CHARS[(t >> 20) & 15] +
|
528 | HEX_CHARS[(t >> 16) & 15] +
|
529 | HEX_CHARS[(t >> 12) & 15] +
|
530 | HEX_CHARS[(t >> 8) & 15] +
|
531 | HEX_CHARS[(t >> 4) & 15] +
|
532 | HEX_CHARS[15 & t] +
|
533 | HEX_CHARS[(r >> 28) & 15] +
|
534 | HEX_CHARS[(r >> 24) & 15] +
|
535 | HEX_CHARS[(r >> 20) & 15] +
|
536 | HEX_CHARS[(r >> 16) & 15] +
|
537 | HEX_CHARS[(r >> 12) & 15] +
|
538 | HEX_CHARS[(r >> 8) & 15] +
|
539 | HEX_CHARS[(r >> 4) & 15] +
|
540 | HEX_CHARS[15 & r] +
|
541 | HEX_CHARS[(o >> 28) & 15] +
|
542 | HEX_CHARS[(o >> 24) & 15] +
|
543 | HEX_CHARS[(o >> 20) & 15] +
|
544 | HEX_CHARS[(o >> 16) & 15] +
|
545 | HEX_CHARS[(o >> 12) & 15] +
|
546 | HEX_CHARS[(o >> 8) & 15] +
|
547 | HEX_CHARS[(o >> 4) & 15] +
|
548 | HEX_CHARS[15 & o] +
|
549 | HEX_CHARS[(n >> 28) & 15] +
|
550 | HEX_CHARS[(n >> 24) & 15] +
|
551 | HEX_CHARS[(n >> 20) & 15] +
|
552 | HEX_CHARS[(n >> 16) & 15] +
|
553 | HEX_CHARS[(n >> 12) & 15] +
|
554 | HEX_CHARS[(n >> 8) & 15] +
|
555 | HEX_CHARS[(n >> 4) & 15] +
|
556 | HEX_CHARS[15 & n] +
|
557 | HEX_CHARS[(i >> 28) & 15] +
|
558 | HEX_CHARS[(i >> 24) & 15] +
|
559 | HEX_CHARS[(i >> 20) & 15] +
|
560 | HEX_CHARS[(i >> 16) & 15] +
|
561 | HEX_CHARS[(i >> 12) & 15] +
|
562 | HEX_CHARS[(i >> 8) & 15] +
|
563 | HEX_CHARS[(i >> 4) & 15] +
|
564 | HEX_CHARS[15 & i] +
|
565 | HEX_CHARS[(s >> 28) & 15] +
|
566 | HEX_CHARS[(s >> 24) & 15] +
|
567 | HEX_CHARS[(s >> 20) & 15] +
|
568 | HEX_CHARS[(s >> 16) & 15] +
|
569 | HEX_CHARS[(s >> 12) & 15] +
|
570 | HEX_CHARS[(s >> 8) & 15] +
|
571 | HEX_CHARS[(s >> 4) & 15] +
|
572 | HEX_CHARS[15 & s];
|
573 | return (
|
574 | this.is224 ||
|
575 | (c +=
|
576 | HEX_CHARS[(a >> 28) & 15] +
|
577 | HEX_CHARS[(a >> 24) & 15] +
|
578 | HEX_CHARS[(a >> 20) & 15] +
|
579 | HEX_CHARS[(a >> 16) & 15] +
|
580 | HEX_CHARS[(a >> 12) & 15] +
|
581 | HEX_CHARS[(a >> 8) & 15] +
|
582 | HEX_CHARS[(a >> 4) & 15] +
|
583 | HEX_CHARS[15 & a]),
|
584 | c
|
585 | );
|
586 | }),
|
587 | (Sha256.prototype.toString = Sha256.prototype.hex),
|
588 | (Sha256.prototype.digest = function () {
|
589 | this.finalize();
|
590 | var e = this.h0,
|
591 | t = this.h1,
|
592 | r = this.h2,
|
593 | o = this.h3,
|
594 | n = this.h4,
|
595 | i = this.h5,
|
596 | s = this.h6,
|
597 | a = this.h7,
|
598 | c = [
|
599 | (e >> 24) & 255,
|
600 | (e >> 16) & 255,
|
601 | (e >> 8) & 255,
|
602 | 255 & e,
|
603 | (t >> 24) & 255,
|
604 | (t >> 16) & 255,
|
605 | (t >> 8) & 255,
|
606 | 255 & t,
|
607 | (r >> 24) & 255,
|
608 | (r >> 16) & 255,
|
609 | (r >> 8) & 255,
|
610 | 255 & r,
|
611 | (o >> 24) & 255,
|
612 | (o >> 16) & 255,
|
613 | (o >> 8) & 255,
|
614 | 255 & o,
|
615 | (n >> 24) & 255,
|
616 | (n >> 16) & 255,
|
617 | (n >> 8) & 255,
|
618 | 255 & n,
|
619 | (i >> 24) & 255,
|
620 | (i >> 16) & 255,
|
621 | (i >> 8) & 255,
|
622 | 255 & i,
|
623 | (s >> 24) & 255,
|
624 | (s >> 16) & 255,
|
625 | (s >> 8) & 255,
|
626 | 255 & s,
|
627 | ];
|
628 | return this.is224 || c.push((a >> 24) & 255, (a >> 16) & 255, (a >> 8) & 255, 255 & a), c;
|
629 | }),
|
630 | (Sha256.prototype.array = Sha256.prototype.digest),
|
631 | (Sha256.prototype.arrayBuffer = function () {
|
632 | this.finalize();
|
633 | var e = new ArrayBuffer(this.is224 ? 28 : 32),
|
634 | t = new DataView(e);
|
635 | return (
|
636 | t.setUint32(0, this.h0),
|
637 | t.setUint32(4, this.h1),
|
638 | t.setUint32(8, this.h2),
|
639 | t.setUint32(12, this.h3),
|
640 | t.setUint32(16, this.h4),
|
641 | t.setUint32(20, this.h5),
|
642 | t.setUint32(24, this.h6),
|
643 | this.is224 || t.setUint32(28, this.h7),
|
644 | e
|
645 | );
|
646 | }),
|
647 | (HmacSha256.prototype = new Sha256()),
|
648 | (HmacSha256.prototype.finalize = function () {
|
649 | if ((Sha256.prototype.finalize.call(this), this.inner)) {
|
650 | this.inner = !1;
|
651 | var e = this.array();
|
652 | Sha256.call(this, this.is224, this.sharedMemory),
|
653 | this.update(this.oKeyPad),
|
654 | this.update(e),
|
655 | Sha256.prototype.finalize.call(this);
|
656 | }
|
657 | });
|
658 | var exports = createMethod();
|
659 | (exports.sha256 = exports),
|
660 | (exports.sha224 = createMethod(!0)),
|
661 | (exports.sha256.hmac = createHmacMethod()),
|
662 | (exports.sha224.hmac = createHmacMethod(!0)),
|
663 | COMMON_JS
|
664 | ? (module.exports = exports)
|
665 | : ((root.sha256 = exports.sha256), (root.sha224 = exports.sha224));
|
666 | })();
|
667 | });
|
668 | if ('undefined' == typeof Promise)
|
669 | throw Error(
|
670 | 'Keycloak requires an environment that supports Promises. Make sure that you include the appropriate polyfill.'
|
671 | );
|
672 | function Keycloak(e) {
|
673 | if (!(this instanceof Keycloak))
|
674 | throw new Error("The 'Keycloak' constructor must be invoked with 'new'.");
|
675 | for (
|
676 | var t,
|
677 | r,
|
678 | o = this,
|
679 | n = [],
|
680 | i = { enable: !0, callbackList: [], interval: 5 },
|
681 | s = document.getElementsByTagName('script'),
|
682 | a = 0;
|
683 | a < s.length;
|
684 | a++
|
685 | )
|
686 | (-1 === s[a].src.indexOf('keycloak.js') && -1 === s[a].src.indexOf('keycloak.min.js')) ||
|
687 | -1 === s[a].src.indexOf('version=') ||
|
688 | (o.iframeVersion = s[a].src.substring(s[a].src.indexOf('version=') + 8).split('&')[0]);
|
689 | var c = !0,
|
690 | u = H(console.info),
|
691 | l = H(console.warn);
|
692 | function d(e, t) {
|
693 | for (
|
694 | var r = (function (e) {
|
695 | var t = null,
|
696 | r = window.crypto || window.msCrypto;
|
697 | if (r && r.getRandomValues && window.Uint8Array)
|
698 | return (t = new Uint8Array(e)), r.getRandomValues(t), t;
|
699 | t = new Array(e);
|
700 | for (var o = 0; o < t.length; o++) t[o] = Math.floor(256 * Math.random());
|
701 | return t;
|
702 | })(e),
|
703 | o = new Array(e),
|
704 | n = 0;
|
705 | n < e;
|
706 | n++
|
707 | )
|
708 | o[n] = t.charCodeAt(r[n] % t.length);
|
709 | return String.fromCharCode.apply(null, o);
|
710 | }
|
711 | function h() {
|
712 | return void 0 !== o.authServerUrl
|
713 | ? '/' == o.authServerUrl.charAt(o.authServerUrl.length - 1)
|
714 | ? o.authServerUrl + 'realms/' + encodeURIComponent(o.realm)
|
715 | : o.authServerUrl + '/realms/' + encodeURIComponent(o.realm)
|
716 | : void 0;
|
717 | }
|
718 | function f(e, t) {
|
719 | var r = e.code,
|
720 | n = e.error,
|
721 | i = e.prompt,
|
722 | s = new Date().getTime();
|
723 | if ((e.kc_action_status && o.onActionUpdate && o.onActionUpdate(e.kc_action_status), n))
|
724 | if ('none' != i) {
|
725 | var a = { error: n, error_description: e.error_description };
|
726 | o.onAuthError && o.onAuthError(a), t && t.setError(a);
|
727 | } else t && t.setSuccess();
|
728 | else if (
|
729 | ('standard' != o.flow &&
|
730 | (e.access_token || e.id_token) &&
|
731 | f(e.access_token, null, e.id_token, !0),
|
732 | 'implicit' != o.flow && r)
|
733 | ) {
|
734 | var l = 'code=' + r + '&grant_type=authorization_code',
|
735 | d = o.endpoints.token(),
|
736 | h = new XMLHttpRequest();
|
737 | h.open('POST', d, !0),
|
738 | h.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'),
|
739 | (l += '&client_id=' + encodeURIComponent(o.clientId)),
|
740 | (l += '&redirect_uri=' + e.redirectUri),
|
741 | e.pkceCodeVerifier && (l += '&code_verifier=' + e.pkceCodeVerifier),
|
742 | (h.withCredentials = !0),
|
743 | (h.onreadystatechange = function () {
|
744 | if (4 == h.readyState)
|
745 | if (200 == h.status) {
|
746 | var e = JSON.parse(h.responseText);
|
747 | f(e.access_token, e.refresh_token, e.id_token, 'standard' === o.flow), _();
|
748 | } else o.onAuthError && o.onAuthError(), t && t.setError();
|
749 | }),
|
750 | h.send(l);
|
751 | }
|
752 | function f(r, n, i, a) {
|
753 | g(r, n, i, (s = (s + new Date().getTime()) / 2)),
|
754 | c &&
|
755 | ((o.tokenParsed && o.tokenParsed.nonce != e.storedNonce) ||
|
756 | (o.refreshTokenParsed && o.refreshTokenParsed.nonce != e.storedNonce) ||
|
757 | (o.idTokenParsed && o.idTokenParsed.nonce != e.storedNonce))
|
758 | ? (u('[KEYCLOAK] Invalid nonce, clearing token'), o.clearToken(), t && t.setError())
|
759 | : a && (o.onAuthSuccess && o.onAuthSuccess(), t && t.setSuccess());
|
760 | }
|
761 | }
|
762 | function p(e) {
|
763 | return 0 == e.status && e.responseText && e.responseURL.startsWith('file:');
|
764 | }
|
765 | function g(e, t, r, n) {
|
766 | if (
|
767 | (o.tokenTimeoutHandle && (clearTimeout(o.tokenTimeoutHandle), (o.tokenTimeoutHandle = null)),
|
768 | t
|
769 | ? ((o.refreshToken = t), (o.refreshTokenParsed = k(t)))
|
770 | : (delete o.refreshToken, delete o.refreshTokenParsed),
|
771 | r ? ((o.idToken = r), (o.idTokenParsed = k(r))) : (delete o.idToken, delete o.idTokenParsed),
|
772 | e)
|
773 | ) {
|
774 | if (
|
775 | ((o.token = e),
|
776 | (o.tokenParsed = k(e)),
|
777 | (o.sessionId = o.tokenParsed.session_state),
|
778 | (o.authenticated = !0),
|
779 | (o.subject = o.tokenParsed.sub),
|
780 | (o.realmAccess = o.tokenParsed.realm_access),
|
781 | (o.resourceAccess = o.tokenParsed.resource_access),
|
782 | n && (o.timeSkew = Math.floor(n / 1e3) - o.tokenParsed.iat),
|
783 | null != o.timeSkew &&
|
784 | (u(
|
785 | '[KEYCLOAK] Estimated time difference between browser and server is ' +
|
786 | o.timeSkew +
|
787 | ' seconds'
|
788 | ),
|
789 | o.onTokenExpired))
|
790 | ) {
|
791 | var i = 1e3 * (o.tokenParsed.exp - new Date().getTime() / 1e3 + o.timeSkew);
|
792 | u('[KEYCLOAK] Token expires in ' + Math.round(i / 1e3) + ' s'),
|
793 | i <= 0 ? o.onTokenExpired() : (o.tokenTimeoutHandle = setTimeout(o.onTokenExpired, i));
|
794 | }
|
795 | } else
|
796 | delete o.token,
|
797 | delete o.tokenParsed,
|
798 | delete o.subject,
|
799 | delete o.realmAccess,
|
800 | delete o.resourceAccess,
|
801 | (o.authenticated = !1);
|
802 | }
|
803 | function k(e) {
|
804 | switch ((e = (e = (e = e.split('.')[1]).replace(/-/g, '+')).replace(/_/g, '/')).length % 4) {
|
805 | case 0:
|
806 | break;
|
807 | case 2:
|
808 | e += '==';
|
809 | break;
|
810 | case 3:
|
811 | e += '=';
|
812 | break;
|
813 | default:
|
814 | throw 'Invalid token';
|
815 | }
|
816 | return (e = decodeURIComponent(escape(atob(e)))), JSON.parse(e);
|
817 | }
|
818 | function m() {
|
819 | var e = '0123456789abcdef',
|
820 | t = d(36, e).split('');
|
821 | return (
|
822 | (t[14] = '4'),
|
823 | (t[19] = e.substr((3 & t[19]) | 8, 1)),
|
824 | (t[8] = t[13] = t[18] = t[23] = '-'),
|
825 | t.join('')
|
826 | );
|
827 | }
|
828 | function v(e) {
|
829 | var t = (function (e) {
|
830 | var t;
|
831 | switch (o.flow) {
|
832 | case 'standard':
|
833 | t = ['code', 'state', 'session_state', 'kc_action_status'];
|
834 | break;
|
835 | case 'implicit':
|
836 | t = [
|
837 | 'access_token',
|
838 | 'token_type',
|
839 | 'id_token',
|
840 | 'state',
|
841 | 'session_state',
|
842 | 'expires_in',
|
843 | 'kc_action_status',
|
844 | ];
|
845 | break;
|
846 | case 'hybrid':
|
847 | t = [
|
848 | 'access_token',
|
849 | 'token_type',
|
850 | 'id_token',
|
851 | 'code',
|
852 | 'state',
|
853 | 'session_state',
|
854 | 'expires_in',
|
855 | 'kc_action_status',
|
856 | ];
|
857 | }
|
858 | t.push('error'), t.push('error_description'), t.push('error_uri');
|
859 | var r,
|
860 | n,
|
861 | i = e.indexOf('?'),
|
862 | s = e.indexOf('#');
|
863 | if (
|
864 | ('query' === o.responseMode && -1 !== i
|
865 | ? ((r = e.substring(0, i)),
|
866 | '' !== (n = w(e.substring(i + 1, -1 !== s ? s : e.length), t)).paramsString &&
|
867 | (r += '?' + n.paramsString),
|
868 | -1 !== s && (r += e.substring(s)))
|
869 | : 'fragment' === o.responseMode &&
|
870 | -1 !== s &&
|
871 | ((r = e.substring(0, s)),
|
872 | '' !== (n = w(e.substring(s + 1), t)).paramsString && (r += '#' + n.paramsString)),
|
873 | n && n.oauthParams)
|
874 | )
|
875 | if ('standard' === o.flow || 'hybrid' === o.flow) {
|
876 | if ((n.oauthParams.code || n.oauthParams.error) && n.oauthParams.state)
|
877 | return (n.oauthParams.newUrl = r), n.oauthParams;
|
878 | } else if (
|
879 | 'implicit' === o.flow &&
|
880 | (n.oauthParams.access_token || n.oauthParams.error) &&
|
881 | n.oauthParams.state
|
882 | )
|
883 | return (n.oauthParams.newUrl = r), n.oauthParams;
|
884 | })(e);
|
885 | if (t) {
|
886 | var n = r.get(t.state);
|
887 | return (
|
888 | n &&
|
889 | ((t.valid = !0),
|
890 | (t.redirectUri = n.redirectUri),
|
891 | (t.storedNonce = n.nonce),
|
892 | (t.prompt = n.prompt),
|
893 | (t.pkceCodeVerifier = n.pkceCodeVerifier)),
|
894 | t
|
895 | );
|
896 | }
|
897 | }
|
898 | function w(e, t) {
|
899 | for (
|
900 | var r = e.split('&'), o = { paramsString: '', oauthParams: {} }, n = 0;
|
901 | n < r.length;
|
902 | n++
|
903 | ) {
|
904 | var i = r[n].indexOf('='),
|
905 | s = r[n].slice(0, i);
|
906 | -1 !== t.indexOf(s)
|
907 | ? (o.oauthParams[s] = r[n].slice(i + 1))
|
908 | : ('' !== o.paramsString && (o.paramsString += '&'), (o.paramsString += r[n]));
|
909 | }
|
910 | return o;
|
911 | }
|
912 | function y() {
|
913 | var e = {
|
914 | setSuccess: function (t) {
|
915 | e.resolve(t);
|
916 | },
|
917 | setError: function (t) {
|
918 | e.reject(t);
|
919 | },
|
920 | };
|
921 | return (
|
922 | (e.promise = new Promise(function (t, r) {
|
923 | (e.resolve = t), (e.reject = r);
|
924 | })),
|
925 | e
|
926 | );
|
927 | }
|
928 | function S() {
|
929 | var e = y();
|
930 | if (!i.enable) return e.setSuccess(), e.promise;
|
931 | if (i.iframe) return e.setSuccess(), e.promise;
|
932 | var t = document.createElement('iframe');
|
933 | (i.iframe = t),
|
934 | (t.onload = function () {
|
935 | var t = o.endpoints.authorize();
|
936 | (i.iframeOrigin =
|
937 | '/' === t.charAt(0)
|
938 | ? window.location.origin
|
939 | ? window.location.origin
|
940 | : window.location.protocol +
|
941 | '//' +
|
942 | window.location.hostname +
|
943 | (window.location.port ? ':' + window.location.port : '')
|
944 | : t.substring(0, t.indexOf('/', 8))),
|
945 | e.setSuccess();
|
946 | });
|
947 | var r = o.endpoints.checkSessionIframe();
|
948 | return (
|
949 | t.setAttribute('src', r),
|
950 | t.setAttribute('sandbox', 'allow-scripts allow-same-origin'),
|
951 | t.setAttribute('title', 'keycloak-session-iframe'),
|
952 | (t.style.display = 'none'),
|
953 | document.body.appendChild(t),
|
954 | window.addEventListener(
|
955 | 'message',
|
956 | function (e) {
|
957 | if (
|
958 | e.origin === i.iframeOrigin &&
|
959 | i.iframe.contentWindow === e.source &&
|
960 | ('unchanged' == e.data || 'changed' == e.data || 'error' == e.data)
|
961 | ) {
|
962 | 'unchanged' != e.data && o.clearToken();
|
963 | for (
|
964 | var t = i.callbackList.splice(0, i.callbackList.length), r = t.length - 1;
|
965 | r >= 0;
|
966 | --r
|
967 | ) {
|
968 | var n = t[r];
|
969 | 'error' == e.data ? n.setError() : n.setSuccess('unchanged' == e.data);
|
970 | }
|
971 | }
|
972 | },
|
973 | !1
|
974 | ),
|
975 | e.promise
|
976 | );
|
977 | }
|
978 | function _() {
|
979 | i.enable &&
|
980 | o.token &&
|
981 | setTimeout(function () {
|
982 | A().then(function (e) {
|
983 | e && _();
|
984 | });
|
985 | }, 1e3 * i.interval);
|
986 | }
|
987 | function A() {
|
988 | var e = y();
|
989 | if (i.iframe && i.iframeOrigin) {
|
990 | var t = o.clientId + ' ' + (o.sessionId ? o.sessionId : '');
|
991 | i.callbackList.push(e),
|
992 | 1 == i.callbackList.length && i.iframe.contentWindow.postMessage(t, i.iframeOrigin);
|
993 | } else e.setSuccess();
|
994 | return e.promise;
|
995 | }
|
996 | function b() {
|
997 | var e = y();
|
998 | if (i.enable || o.silentCheckSsoRedirectUri) {
|
999 | var t = document.createElement('iframe');
|
1000 | t.setAttribute('src', o.endpoints.thirdPartyCookiesIframe()),
|
1001 | t.setAttribute('sandbox', 'allow-scripts allow-same-origin'),
|
1002 | t.setAttribute('title', 'keycloak-3p-check-iframe'),
|
1003 | (t.style.display = 'none'),
|
1004 | document.body.appendChild(t);
|
1005 | var r = function (n) {
|
1006 | t.contentWindow === n.source &&
|
1007 | (('supported' !== n.data && 'unsupported' !== n.data) ||
|
1008 | ('unsupported' === n.data &&
|
1009 | ((i.enable = !1),
|
1010 | o.silentCheckSsoFallback && (o.silentCheckSsoRedirectUri = !1),
|
1011 | l(
|
1012 | "[KEYCLOAK] 3rd party cookies aren't supported by this browser. checkLoginIframe and silent check-sso are not available."
|
1013 | )),
|
1014 | document.body.removeChild(t),
|
1015 | window.removeEventListener('message', r),
|
1016 | e.setSuccess()));
|
1017 | };
|
1018 | window.addEventListener('message', r, !1);
|
1019 | } else e.setSuccess();
|
1020 | return (function (e, t, r) {
|
1021 | var o = null,
|
1022 | n = new Promise(function (e, r) {
|
1023 | o = setTimeout(function () {
|
1024 | r({ error: 'Timeout when waiting for 3rd party check iframe message.' });
|
1025 | }, t);
|
1026 | });
|
1027 | return Promise.race([e, n]).finally(function () {
|
1028 | clearTimeout(o);
|
1029 | });
|
1030 | })(e.promise, o.messageReceiveTimeout);
|
1031 | }
|
1032 | function R(e) {
|
1033 | if (!e || 'default' == e)
|
1034 | return {
|
1035 | login: function (e) {
|
1036 | return window.location.assign(o.createLoginUrl(e)), y().promise;
|
1037 | },
|
1038 | logout: function (e) {
|
1039 | return window.location.replace(o.createLogoutUrl(e)), y().promise;
|
1040 | },
|
1041 | register: function (e) {
|
1042 | return window.location.assign(o.createRegisterUrl(e)), y().promise;
|
1043 | },
|
1044 | accountManagement: function () {
|
1045 | var e = o.createAccountUrl();
|
1046 | if (void 0 === e) throw 'Not supported by the OIDC server';
|
1047 | return (window.location.href = e), y().promise;
|
1048 | },
|
1049 | redirectUri: function (e, t) {
|
1050 | return e && e.redirectUri ? e.redirectUri : o.redirectUri ? o.redirectUri : location.href;
|
1051 | },
|
1052 | };
|
1053 | if ('cordova' == e) {
|
1054 | i.enable = !1;
|
1055 | var t = function (e, t, r) {
|
1056 | return window.cordova && window.cordova.InAppBrowser
|
1057 | ? window.cordova.InAppBrowser.open(e, t, r)
|
1058 | : window.open(e, t, r);
|
1059 | },
|
1060 | r = function (e) {
|
1061 | var t = (function (e) {
|
1062 | return e && e.cordovaOptions
|
1063 | ? Object.keys(e.cordovaOptions).reduce(function (t, r) {
|
1064 | return (t[r] = e.cordovaOptions[r]), t;
|
1065 | }, {})
|
1066 | : {};
|
1067 | })(e);
|
1068 | return (
|
1069 | (t.location = 'no'),
|
1070 | e && 'none' == e.prompt && (t.hidden = 'yes'),
|
1071 | (function (e) {
|
1072 | return Object.keys(e)
|
1073 | .reduce(function (t, r) {
|
1074 | return t.push(r + '=' + e[r]), t;
|
1075 | }, [])
|
1076 | .join(',');
|
1077 | })(t)
|
1078 | );
|
1079 | },
|
1080 | n = o.redirectUri || 'http://localhost';
|
1081 | return {
|
1082 | login: function (e) {
|
1083 | var i = y(),
|
1084 | s = r(e),
|
1085 | a = o.createLoginUrl(e),
|
1086 | c = t(a, '_blank', s),
|
1087 | u = !1,
|
1088 | l = !1,
|
1089 | d = function () {
|
1090 | (l = !0), c.close();
|
1091 | };
|
1092 | return (
|
1093 | c.addEventListener('loadstart', function (e) {
|
1094 | 0 == e.url.indexOf(n) && (f(v(e.url), i), d(), (u = !0));
|
1095 | }),
|
1096 | c.addEventListener('loaderror', function (e) {
|
1097 | u || (0 == e.url.indexOf(n) ? (f(v(e.url), i), d(), (u = !0)) : (i.setError(), d()));
|
1098 | }),
|
1099 | c.addEventListener('exit', function (e) {
|
1100 | l || i.setError({ reason: 'closed_by_user' });
|
1101 | }),
|
1102 | i.promise
|
1103 | );
|
1104 | },
|
1105 | logout: function (e) {
|
1106 | var r,
|
1107 | i = y(),
|
1108 | s = o.createLogoutUrl(e),
|
1109 | a = t(s, '_blank', 'location=no,hidden=yes,clearcache=yes');
|
1110 | return (
|
1111 | a.addEventListener('loadstart', function (e) {
|
1112 | 0 == e.url.indexOf(n) && a.close();
|
1113 | }),
|
1114 | a.addEventListener('loaderror', function (e) {
|
1115 | 0 == e.url.indexOf(n) || (r = !0), a.close();
|
1116 | }),
|
1117 | a.addEventListener('exit', function (e) {
|
1118 | r ? i.setError() : (o.clearToken(), i.setSuccess());
|
1119 | }),
|
1120 | i.promise
|
1121 | );
|
1122 | },
|
1123 | register: function (e) {
|
1124 | var i = y(),
|
1125 | s = o.createRegisterUrl(),
|
1126 | a = r(e),
|
1127 | c = t(s, '_blank', a);
|
1128 | return (
|
1129 | c.addEventListener('loadstart', function (e) {
|
1130 | 0 == e.url.indexOf(n) && (c.close(), f(v(e.url), i));
|
1131 | }),
|
1132 | i.promise
|
1133 | );
|
1134 | },
|
1135 | accountManagement: function () {
|
1136 | var e = o.createAccountUrl();
|
1137 | if (void 0 === e) throw 'Not supported by the OIDC server';
|
1138 | var r = t(e, '_blank', 'location=no');
|
1139 | r.addEventListener('loadstart', function (e) {
|
1140 | 0 == e.url.indexOf(n) && r.close();
|
1141 | });
|
1142 | },
|
1143 | redirectUri: function (e) {
|
1144 | return n;
|
1145 | },
|
1146 | };
|
1147 | }
|
1148 | if ('cordova-native' == e)
|
1149 | return (
|
1150 | (i.enable = !1),
|
1151 | {
|
1152 | login: function (e) {
|
1153 | var t = y(),
|
1154 | r = o.createLoginUrl(e);
|
1155 | return (
|
1156 | universalLinks.subscribe('keycloak', function (e) {
|
1157 | universalLinks.unsubscribe('keycloak'),
|
1158 | window.cordova.plugins.browsertab.close(),
|
1159 | f(v(e.url), t);
|
1160 | }),
|
1161 | window.cordova.plugins.browsertab.openUrl(r),
|
1162 | t.promise
|
1163 | );
|
1164 | },
|
1165 | logout: function (e) {
|
1166 | var t = y(),
|
1167 | r = o.createLogoutUrl(e);
|
1168 | return (
|
1169 | universalLinks.subscribe('keycloak', function (e) {
|
1170 | universalLinks.unsubscribe('keycloak'),
|
1171 | window.cordova.plugins.browsertab.close(),
|
1172 | o.clearToken(),
|
1173 | t.setSuccess();
|
1174 | }),
|
1175 | window.cordova.plugins.browsertab.openUrl(r),
|
1176 | t.promise
|
1177 | );
|
1178 | },
|
1179 | register: function (e) {
|
1180 | var t = y(),
|
1181 | r = o.createRegisterUrl(e);
|
1182 | return (
|
1183 | universalLinks.subscribe('keycloak', function (e) {
|
1184 | universalLinks.unsubscribe('keycloak'),
|
1185 | window.cordova.plugins.browsertab.close(),
|
1186 | f(v(e.url), t);
|
1187 | }),
|
1188 | window.cordova.plugins.browsertab.openUrl(r),
|
1189 | t.promise
|
1190 | );
|
1191 | },
|
1192 | accountManagement: function () {
|
1193 | var e = o.createAccountUrl();
|
1194 | if (void 0 === e) throw 'Not supported by the OIDC server';
|
1195 | window.cordova.plugins.browsertab.openUrl(e);
|
1196 | },
|
1197 | redirectUri: function (e) {
|
1198 | return e && e.redirectUri
|
1199 | ? e.redirectUri
|
1200 | : o.redirectUri
|
1201 | ? o.redirectUri
|
1202 | : 'http://localhost';
|
1203 | },
|
1204 | }
|
1205 | );
|
1206 | throw 'invalid adapter type: ' + e;
|
1207 | }
|
1208 | (o.init = function (n) {
|
1209 | if (o.didInitialize) throw new Error("A 'Keycloak' instance can only be initialized once.");
|
1210 | if (
|
1211 | ((o.didInitialize = !0),
|
1212 | (o.authenticated = !1),
|
1213 | (r = (function () {
|
1214 | try {
|
1215 | return new E();
|
1216 | } catch (e) {}
|
1217 | return new C();
|
1218 | })()),
|
1219 | (t =
|
1220 | n && ['default', 'cordova', 'cordova-native'].indexOf(n.adapter) > -1
|
1221 | ? R(n.adapter)
|
1222 | : n && 'object' == typeof n.adapter
|
1223 | ? n.adapter
|
1224 | : window.Cordova || window.cordova
|
1225 | ? R('cordova')
|
1226 | : R()),
|
1227 | n)
|
1228 | ) {
|
1229 | if (
|
1230 | (void 0 !== n.useNonce && (c = n.useNonce),
|
1231 | void 0 !== n.checkLoginIframe && (i.enable = n.checkLoginIframe),
|
1232 | n.checkLoginIframeInterval && (i.interval = n.checkLoginIframeInterval),
|
1233 | 'login-required' === n.onLoad && (o.loginRequired = !0),
|
1234 | n.responseMode)
|
1235 | ) {
|
1236 | if ('query' !== n.responseMode && 'fragment' !== n.responseMode)
|
1237 | throw 'Invalid value for responseMode';
|
1238 | o.responseMode = n.responseMode;
|
1239 | }
|
1240 | if (n.flow) {
|
1241 | switch (n.flow) {
|
1242 | case 'standard':
|
1243 | o.responseType = 'code';
|
1244 | break;
|
1245 | case 'implicit':
|
1246 | o.responseType = 'id_token token';
|
1247 | break;
|
1248 | case 'hybrid':
|
1249 | o.responseType = 'code id_token token';
|
1250 | break;
|
1251 | default:
|
1252 | throw 'Invalid value for flow';
|
1253 | }
|
1254 | o.flow = n.flow;
|
1255 | }
|
1256 | if (
|
1257 | (null != n.timeSkew && (o.timeSkew = n.timeSkew),
|
1258 | n.redirectUri && (o.redirectUri = n.redirectUri),
|
1259 | n.silentCheckSsoRedirectUri && (o.silentCheckSsoRedirectUri = n.silentCheckSsoRedirectUri),
|
1260 | (o.silentCheckSsoFallback =
|
1261 | 'boolean' != typeof n.silentCheckSsoFallback || n.silentCheckSsoFallback),
|
1262 | n.pkceMethod)
|
1263 | ) {
|
1264 | if ('S256' !== n.pkceMethod) throw 'Invalid value for pkceMethod';
|
1265 | o.pkceMethod = n.pkceMethod;
|
1266 | }
|
1267 | (o.enableLogging = 'boolean' == typeof n.enableLogging && n.enableLogging),
|
1268 | 'string' == typeof n.scope && (o.scope = n.scope),
|
1269 | (o.messageReceiveTimeout =
|
1270 | 'number' == typeof n.messageReceiveTimeout && n.messageReceiveTimeout > 0
|
1271 | ? n.messageReceiveTimeout
|
1272 | : 1e4);
|
1273 | }
|
1274 | o.responseMode || (o.responseMode = 'fragment'),
|
1275 | o.responseType || ((o.responseType = 'code'), (o.flow = 'standard'));
|
1276 | var s = y(),
|
1277 | a = y();
|
1278 | a.promise
|
1279 | .then(function () {
|
1280 | o.onReady && o.onReady(o.authenticated), s.setSuccess(o.authenticated);
|
1281 | })
|
1282 | .catch(function (e) {
|
1283 | s.setError(e);
|
1284 | });
|
1285 | var u = (function (t) {
|
1286 | var r,
|
1287 | n = y();
|
1288 | function i(e) {
|
1289 | o.endpoints = e
|
1290 | ? {
|
1291 | authorize: function () {
|
1292 | return e.authorization_endpoint;
|
1293 | },
|
1294 | token: function () {
|
1295 | return e.token_endpoint;
|
1296 | },
|
1297 | logout: function () {
|
1298 | if (!e.end_session_endpoint) throw 'Not supported by the OIDC server';
|
1299 | return e.end_session_endpoint;
|
1300 | },
|
1301 | checkSessionIframe: function () {
|
1302 | if (!e.check_session_iframe) throw 'Not supported by the OIDC server';
|
1303 | return e.check_session_iframe;
|
1304 | },
|
1305 | register: function () {
|
1306 | throw 'Redirection to "Register user" page not supported in standard OIDC mode';
|
1307 | },
|
1308 | userinfo: function () {
|
1309 | if (!e.userinfo_endpoint) throw 'Not supported by the OIDC server';
|
1310 | return e.userinfo_endpoint;
|
1311 | },
|
1312 | }
|
1313 | : {
|
1314 | authorize: function () {
|
1315 | return h() + '/protocol/openid-connect/auth';
|
1316 | },
|
1317 | token: function () {
|
1318 | return h() + '/protocol/openid-connect/token';
|
1319 | },
|
1320 | logout: function () {
|
1321 | return h() + '/protocol/openid-connect/logout';
|
1322 | },
|
1323 | checkSessionIframe: function () {
|
1324 | var e = h() + '/protocol/openid-connect/login-status-iframe.html';
|
1325 | return o.iframeVersion && (e = e + '?version=' + o.iframeVersion), e;
|
1326 | },
|
1327 | thirdPartyCookiesIframe: function () {
|
1328 | var e = h() + '/protocol/openid-connect/3p-cookies/step1.html';
|
1329 | return o.iframeVersion && (e = e + '?version=' + o.iframeVersion), e;
|
1330 | },
|
1331 | register: function () {
|
1332 | return h() + '/protocol/openid-connect/registrations';
|
1333 | },
|
1334 | userinfo: function () {
|
1335 | return h() + '/protocol/openid-connect/userinfo';
|
1336 | },
|
1337 | };
|
1338 | }
|
1339 | if ((e ? 'string' == typeof e && (r = e) : (r = 'keycloak.json'), r))
|
1340 | (c = new XMLHttpRequest()).open('GET', r, !0),
|
1341 | c.setRequestHeader('Accept', 'application/json'),
|
1342 | (c.onreadystatechange = function () {
|
1343 | if (4 == c.readyState)
|
1344 | if (200 == c.status || p(c)) {
|
1345 | var e = JSON.parse(c.responseText);
|
1346 | (o.authServerUrl = e['auth-server-url']),
|
1347 | (o.realm = e.realm),
|
1348 | (o.clientId = e.resource),
|
1349 | i(null),
|
1350 | n.setSuccess();
|
1351 | } else n.setError();
|
1352 | }),
|
1353 | c.send();
|
1354 | else {
|
1355 | if (!e.clientId) throw 'clientId missing';
|
1356 | o.clientId = e.clientId;
|
1357 | var s = e.oidcProvider;
|
1358 | if (s) {
|
1359 | var a, c;
|
1360 | 'string' == typeof s
|
1361 | ? ((a =
|
1362 | '/' == s.charAt(s.length - 1)
|
1363 | ? s + '.well-known/openid-configuration'
|
1364 | : s + '/.well-known/openid-configuration'),
|
1365 | (c = new XMLHttpRequest()).open('GET', a, !0),
|
1366 | c.setRequestHeader('Accept', 'application/json'),
|
1367 | (c.onreadystatechange = function () {
|
1368 | 4 == c.readyState &&
|
1369 | (200 == c.status || p(c)
|
1370 | ? (i(JSON.parse(c.responseText)), n.setSuccess())
|
1371 | : n.setError());
|
1372 | }),
|
1373 | c.send())
|
1374 | : (i(s), n.setSuccess());
|
1375 | } else {
|
1376 | if (!e.url)
|
1377 | for (var u = document.getElementsByTagName('script'), l = 0; l < u.length; l++)
|
1378 | if (u[l].src.match(/.*keycloak\.js/)) {
|
1379 | e.url = u[l].src.substr(0, u[l].src.indexOf('/js/keycloak.js'));
|
1380 | break;
|
1381 | }
|
1382 | if (!e.realm) throw 'realm missing';
|
1383 | (o.authServerUrl = e.url), (o.realm = e.realm), i(null), n.setSuccess();
|
1384 | }
|
1385 | }
|
1386 | return n.promise;
|
1387 | })();
|
1388 | function l() {
|
1389 | var e = function (e) {
|
1390 | e || (r.prompt = 'none'),
|
1391 | n && n.locale && (r.locale = n.locale),
|
1392 | o
|
1393 | .login(r)
|
1394 | .then(function () {
|
1395 | a.setSuccess();
|
1396 | })
|
1397 | .catch(function (e) {
|
1398 | a.setError(e);
|
1399 | });
|
1400 | },
|
1401 | t = function () {
|
1402 | var e = document.createElement('iframe'),
|
1403 | t = o.createLoginUrl({ prompt: 'none', redirectUri: o.silentCheckSsoRedirectUri });
|
1404 | e.setAttribute('src', t),
|
1405 | e.setAttribute('sandbox', 'allow-scripts allow-same-origin'),
|
1406 | e.setAttribute('title', 'keycloak-silent-check-sso'),
|
1407 | (e.style.display = 'none'),
|
1408 | document.body.appendChild(e);
|
1409 | var r = function (t) {
|
1410 | t.origin === window.location.origin &&
|
1411 | e.contentWindow === t.source &&
|
1412 | (f(v(t.data), a),
|
1413 | document.body.removeChild(e),
|
1414 | window.removeEventListener('message', r));
|
1415 | };
|
1416 | window.addEventListener('message', r);
|
1417 | },
|
1418 | r = {};
|
1419 | switch (n.onLoad) {
|
1420 | case 'check-sso':
|
1421 | i.enable
|
1422 | ? S().then(function () {
|
1423 | A()
|
1424 | .then(function (r) {
|
1425 | r ? a.setSuccess() : o.silentCheckSsoRedirectUri ? t() : e(!1);
|
1426 | })
|
1427 | .catch(function (e) {
|
1428 | a.setError(e);
|
1429 | });
|
1430 | })
|
1431 | : o.silentCheckSsoRedirectUri
|
1432 | ? t()
|
1433 | : e(!1);
|
1434 | break;
|
1435 | case 'login-required':
|
1436 | e(!0);
|
1437 | break;
|
1438 | default:
|
1439 | throw 'Invalid value for onLoad';
|
1440 | }
|
1441 | }
|
1442 | function d() {
|
1443 | var e = v(window.location.href);
|
1444 | if ((e && window.history.replaceState(window.history.state, null, e.newUrl), e && e.valid))
|
1445 | return S()
|
1446 | .then(function () {
|
1447 | f(e, a);
|
1448 | })
|
1449 | .catch(function (e) {
|
1450 | a.setError(e);
|
1451 | });
|
1452 | n
|
1453 | ? n.token && n.refreshToken
|
1454 | ? (g(n.token, n.refreshToken, n.idToken),
|
1455 | i.enable
|
1456 | ? S().then(function () {
|
1457 | A()
|
1458 | .then(function (e) {
|
1459 | e
|
1460 | ? (o.onAuthSuccess && o.onAuthSuccess(), a.setSuccess(), _())
|
1461 | : a.setSuccess();
|
1462 | })
|
1463 | .catch(function (e) {
|
1464 | a.setError(e);
|
1465 | });
|
1466 | })
|
1467 | : o
|
1468 | .updateToken(-1)
|
1469 | .then(function () {
|
1470 | o.onAuthSuccess && o.onAuthSuccess(), a.setSuccess();
|
1471 | })
|
1472 | .catch(function (e) {
|
1473 | o.onAuthError && o.onAuthError(), n.onLoad ? l() : a.setError(e);
|
1474 | }))
|
1475 | : n.onLoad
|
1476 | ? l()
|
1477 | : a.setSuccess()
|
1478 | : a.setSuccess();
|
1479 | }
|
1480 | return (
|
1481 | u.then(function () {
|
1482 | (function () {
|
1483 | var e = y(),
|
1484 | t = function () {
|
1485 | ('interactive' !== document.readyState && 'complete' !== document.readyState) ||
|
1486 | (document.removeEventListener('readystatechange', t), e.setSuccess());
|
1487 | };
|
1488 | return document.addEventListener('readystatechange', t), t(), e.promise;
|
1489 | })()
|
1490 | .then(b)
|
1491 | .then(d)
|
1492 | .catch(function (e) {
|
1493 | s.setError(e);
|
1494 | });
|
1495 | }),
|
1496 | u.catch(function (e) {
|
1497 | s.setError(e);
|
1498 | }),
|
1499 | s.promise
|
1500 | );
|
1501 | }),
|
1502 | (o.login = function (e) {
|
1503 | return t.login(e);
|
1504 | }),
|
1505 | (o.createLoginUrl = function (e) {
|
1506 | var n,
|
1507 | i = m(),
|
1508 | s = m(),
|
1509 | a = t.redirectUri(e),
|
1510 | u = { state: i, nonce: s, redirectUri: encodeURIComponent(a) };
|
1511 | e && e.prompt && (u.prompt = e.prompt),
|
1512 | (n = e && 'register' == e.action ? o.endpoints.register() : o.endpoints.authorize());
|
1513 | var l = (e && e.scope) || o.scope;
|
1514 | l ? -1 === l.indexOf('openid') && (l = 'openid ' + l) : (l = 'openid');
|
1515 | var h =
|
1516 | n +
|
1517 | '?client_id=' +
|
1518 | encodeURIComponent(o.clientId) +
|
1519 | '&redirect_uri=' +
|
1520 | encodeURIComponent(a) +
|
1521 | '&state=' +
|
1522 | encodeURIComponent(i) +
|
1523 | '&response_mode=' +
|
1524 | encodeURIComponent(o.responseMode) +
|
1525 | '&response_type=' +
|
1526 | encodeURIComponent(o.responseType) +
|
1527 | '&scope=' +
|
1528 | encodeURIComponent(l);
|
1529 | if (
|
1530 | (c && (h = h + '&nonce=' + encodeURIComponent(s)),
|
1531 | e && e.prompt && (h += '&prompt=' + encodeURIComponent(e.prompt)),
|
1532 | e && e.maxAge && (h += '&max_age=' + encodeURIComponent(e.maxAge)),
|
1533 | e && e.loginHint && (h += '&login_hint=' + encodeURIComponent(e.loginHint)),
|
1534 | e && e.idpHint && (h += '&kc_idp_hint=' + encodeURIComponent(e.idpHint)),
|
1535 | e &&
|
1536 | e.action &&
|
1537 | 'register' != e.action &&
|
1538 | (h += '&kc_action=' + encodeURIComponent(e.action)),
|
1539 | e && e.locale && (h += '&ui_locales=' + encodeURIComponent(e.locale)),
|
1540 | e && e.acr)
|
1541 | ) {
|
1542 | var f = JSON.stringify({ id_token: { acr: e.acr } });
|
1543 | h += '&claims=' + encodeURIComponent(f);
|
1544 | }
|
1545 | if (o.pkceMethod) {
|
1546 | var p = d(96, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
|
1547 | u.pkceCodeVerifier = p;
|
1548 | var g = (function (e, t) {
|
1549 | if ('S256' === e) {
|
1550 | var r = new Uint8Array(sha256.arrayBuffer(t));
|
1551 | return base64Js
|
1552 | .fromByteArray(r)
|
1553 | .replace(/\+/g, '-')
|
1554 | .replace(/\//g, '_')
|
1555 | .replace(/\=/g, '');
|
1556 | }
|
1557 | throw 'Invalid value for pkceMethod';
|
1558 | })(o.pkceMethod, p);
|
1559 | (h += '&code_challenge=' + g), (h += '&code_challenge_method=' + o.pkceMethod);
|
1560 | }
|
1561 | return r.add(u), h;
|
1562 | }),
|
1563 | (o.logout = function (e) {
|
1564 | return t.logout(e);
|
1565 | }),
|
1566 | (o.createLogoutUrl = function (e) {
|
1567 | var r =
|
1568 | o.endpoints.logout() +
|
1569 | '?client_id=' +
|
1570 | encodeURIComponent(o.clientId) +
|
1571 | '&post_logout_redirect_uri=' +
|
1572 | encodeURIComponent(t.redirectUri(e, !1));
|
1573 | return o.idToken && (r += '&id_token_hint=' + encodeURIComponent(o.idToken)), r;
|
1574 | }),
|
1575 | (o.register = function (e) {
|
1576 | return t.register(e);
|
1577 | }),
|
1578 | (o.createRegisterUrl = function (e) {
|
1579 | return e || (e = {}), (e.action = 'register'), o.createLoginUrl(e);
|
1580 | }),
|
1581 | (o.createAccountUrl = function (e) {
|
1582 | var r = h(),
|
1583 | n = void 0;
|
1584 | return (
|
1585 | void 0 !== r &&
|
1586 | (n =
|
1587 | r +
|
1588 | '/account?referrer=' +
|
1589 | encodeURIComponent(o.clientId) +
|
1590 | '&referrer_uri=' +
|
1591 | encodeURIComponent(t.redirectUri(e))),
|
1592 | n
|
1593 | );
|
1594 | }),
|
1595 | (o.accountManagement = function () {
|
1596 | return t.accountManagement();
|
1597 | }),
|
1598 | (o.hasRealmRole = function (e) {
|
1599 | var t = o.realmAccess;
|
1600 | return !!t && t.roles.indexOf(e) >= 0;
|
1601 | }),
|
1602 | (o.hasResourceRole = function (e, t) {
|
1603 | if (!o.resourceAccess) return !1;
|
1604 | var r = o.resourceAccess[t || o.clientId];
|
1605 | return !!r && r.roles.indexOf(e) >= 0;
|
1606 | }),
|
1607 | (o.loadUserProfile = function () {
|
1608 | var e = h() + '/account',
|
1609 | t = new XMLHttpRequest();
|
1610 | t.open('GET', e, !0),
|
1611 | t.setRequestHeader('Accept', 'application/json'),
|
1612 | t.setRequestHeader('Authorization', 'bearer ' + o.token);
|
1613 | var r = y();
|
1614 | return (
|
1615 | (t.onreadystatechange = function () {
|
1616 | 4 == t.readyState &&
|
1617 | (200 == t.status
|
1618 | ? ((o.profile = JSON.parse(t.responseText)), r.setSuccess(o.profile))
|
1619 | : r.setError());
|
1620 | }),
|
1621 | t.send(),
|
1622 | r.promise
|
1623 | );
|
1624 | }),
|
1625 | (o.loadUserInfo = function () {
|
1626 | var e = o.endpoints.userinfo(),
|
1627 | t = new XMLHttpRequest();
|
1628 | t.open('GET', e, !0),
|
1629 | t.setRequestHeader('Accept', 'application/json'),
|
1630 | t.setRequestHeader('Authorization', 'bearer ' + o.token);
|
1631 | var r = y();
|
1632 | return (
|
1633 | (t.onreadystatechange = function () {
|
1634 | 4 == t.readyState &&
|
1635 | (200 == t.status
|
1636 | ? ((o.userInfo = JSON.parse(t.responseText)), r.setSuccess(o.userInfo))
|
1637 | : r.setError());
|
1638 | }),
|
1639 | t.send(),
|
1640 | r.promise
|
1641 | );
|
1642 | }),
|
1643 | (o.isTokenExpired = function (e) {
|
1644 | if (!o.tokenParsed || (!o.refreshToken && 'implicit' != o.flow)) throw 'Not authenticated';
|
1645 | if (null == o.timeSkew)
|
1646 | return u('[KEYCLOAK] Unable to determine if token is expired as timeskew is not set'), !0;
|
1647 | var t = o.tokenParsed.exp - Math.ceil(new Date().getTime() / 1e3) + o.timeSkew;
|
1648 | if (e) {
|
1649 | if (isNaN(e)) throw 'Invalid minValidity';
|
1650 | t -= e;
|
1651 | }
|
1652 | return t < 0;
|
1653 | }),
|
1654 | (o.updateToken = function (e) {
|
1655 | var t = y();
|
1656 | if (!o.refreshToken) return t.setError(), t.promise;
|
1657 | e = e || 5;
|
1658 | var r = function () {
|
1659 | var r = !1;
|
1660 | if (
|
1661 | (-1 == e
|
1662 | ? ((r = !0), u('[KEYCLOAK] Refreshing token: forced refresh'))
|
1663 | : (o.tokenParsed && !o.isTokenExpired(e)) ||
|
1664 | ((r = !0), u('[KEYCLOAK] Refreshing token: token expired')),
|
1665 | r)
|
1666 | ) {
|
1667 | var i = 'grant_type=refresh_token&refresh_token=' + o.refreshToken,
|
1668 | s = o.endpoints.token();
|
1669 | if ((n.push(t), 1 == n.length)) {
|
1670 | var a = new XMLHttpRequest();
|
1671 | a.open('POST', s, !0),
|
1672 | a.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'),
|
1673 | (a.withCredentials = !0),
|
1674 | (i += '&client_id=' + encodeURIComponent(o.clientId));
|
1675 | var c = new Date().getTime();
|
1676 | (a.onreadystatechange = function () {
|
1677 | if (4 == a.readyState)
|
1678 | if (200 == a.status) {
|
1679 | u('[KEYCLOAK] Token refreshed'), (c = (c + new Date().getTime()) / 2);
|
1680 | var e = JSON.parse(a.responseText);
|
1681 | g(e.access_token, e.refresh_token, e.id_token, c),
|
1682 | o.onAuthRefreshSuccess && o.onAuthRefreshSuccess();
|
1683 | for (var t = n.pop(); null != t; t = n.pop()) t.setSuccess(!0);
|
1684 | } else
|
1685 | for (
|
1686 | l('[KEYCLOAK] Failed to refresh token'),
|
1687 | 400 == a.status && o.clearToken(),
|
1688 | o.onAuthRefreshError && o.onAuthRefreshError(),
|
1689 | t = n.pop();
|
1690 | null != t;
|
1691 | t = n.pop()
|
1692 | )
|
1693 | t.setError(!0);
|
1694 | }),
|
1695 | a.send(i);
|
1696 | }
|
1697 | } else t.setSuccess(!1);
|
1698 | };
|
1699 | return (
|
1700 | i.enable
|
1701 | ? A()
|
1702 | .then(function () {
|
1703 | r();
|
1704 | })
|
1705 | .catch(function (e) {
|
1706 | t.setError(e);
|
1707 | })
|
1708 | : r(),
|
1709 | t.promise
|
1710 | );
|
1711 | }),
|
1712 | (o.clearToken = function () {
|
1713 | o.token &&
|
1714 | (g(null, null, null), o.onAuthLogout && o.onAuthLogout(), o.loginRequired && o.login());
|
1715 | });
|
1716 | var E = function () {
|
1717 | if (!(this instanceof E)) return new E();
|
1718 | function e() {
|
1719 | for (var e = new Date().getTime(), t = 0; t < localStorage.length; t++) {
|
1720 | var r = localStorage.key(t);
|
1721 | if (r && 0 == r.indexOf('kc-callback-')) {
|
1722 | var o = localStorage.getItem(r);
|
1723 | if (o)
|
1724 | try {
|
1725 | var n = JSON.parse(o).expires;
|
1726 | (!n || n < e) && localStorage.removeItem(r);
|
1727 | } catch (e) {
|
1728 | localStorage.removeItem(r);
|
1729 | }
|
1730 | }
|
1731 | }
|
1732 | }
|
1733 | localStorage.setItem('kc-test', 'test'),
|
1734 | localStorage.removeItem('kc-test'),
|
1735 | (this.get = function (t) {
|
1736 | if (t) {
|
1737 | var r = 'kc-callback-' + t,
|
1738 | o = localStorage.getItem(r);
|
1739 | return o && (localStorage.removeItem(r), (o = JSON.parse(o))), e(), o;
|
1740 | }
|
1741 | }),
|
1742 | (this.add = function (t) {
|
1743 | e();
|
1744 | var r = 'kc-callback-' + t.state;
|
1745 | (t.expires = new Date().getTime() + 36e5), localStorage.setItem(r, JSON.stringify(t));
|
1746 | });
|
1747 | },
|
1748 | C = function () {
|
1749 | if (!(this instanceof C)) return new C();
|
1750 | var e = this;
|
1751 | (e.get = function (e) {
|
1752 | if (e) {
|
1753 | var n = r('kc-callback-' + e);
|
1754 | return o('kc-callback-' + e, '', t(-100)), n ? JSON.parse(n) : void 0;
|
1755 | }
|
1756 | }),
|
1757 | (e.add = function (e) {
|
1758 | o('kc-callback-' + e.state, JSON.stringify(e), t(60));
|
1759 | }),
|
1760 | (e.removeItem = function (e) {
|
1761 | o(e, '', t(-100));
|
1762 | });
|
1763 | var t = function (e) {
|
1764 | var t = new Date();
|
1765 | return t.setTime(t.getTime() + 60 * e * 1e3), t;
|
1766 | },
|
1767 | r = function (e) {
|
1768 | for (var t = e + '=', r = document.cookie.split(';'), o = 0; o < r.length; o++) {
|
1769 | for (var n = r[o]; ' ' == n.charAt(0); ) n = n.substring(1);
|
1770 | if (0 == n.indexOf(t)) return n.substring(t.length, n.length);
|
1771 | }
|
1772 | return '';
|
1773 | },
|
1774 | o = function (e, t, r) {
|
1775 | var o = e + '=' + t + '; expires=' + r.toUTCString() + '; ';
|
1776 | document.cookie = o;
|
1777 | };
|
1778 | };
|
1779 | function H(e) {
|
1780 | return function () {
|
1781 | o.enableLogging && e.apply(console, Array.prototype.slice.call(arguments));
|
1782 | };
|
1783 | }
|
1784 | }
|
1785 | var appendParentOriginIntoUrl = function (e, t) {
|
1786 | if (window !== window.parent)
|
1787 | try {
|
1788 | var r,
|
1789 | o,
|
1790 | n = document.referrer,
|
1791 | i = n.split('/')[2];
|
1792 | t && (console.info('DOCUMENT REFERRER: ', n), console.info('DOCUMENT REFERRER HOST: ', i));
|
1793 | var s = null == (r = window.location.ancestorOrigins) ? void 0 : r[0],
|
1794 | a = null == s || null == (o = s.split('/')) ? void 0 : o[2];
|
1795 | t && (console.info('ANCESTOR ORIGIN: ', s), console.info('ANCESTOR ORIGIN HOST: ', a));
|
1796 | var c =
|
1797 | window.location !== window.parent.location
|
1798 | ? null != i
|
1799 | ? i
|
1800 | : a
|
1801 | : window.location.hostname;
|
1802 | t && console.info('WINK PARENT ORIGIN HOST: ', c),
|
1803 | (e = e + '&wink-parent-origin=' + encodeURIComponent(c));
|
1804 | } catch (e) {
|
1805 | console.error('Unable to add wink parent origin query param due to error: ', e);
|
1806 | }
|
1807 | return e;
|
1808 | },
|
1809 | defaultKeycloakInitConfig = {
|
1810 | onLoad: 'check-sso',
|
1811 | pkceMethod: 'S256',
|
1812 | silentCheckSsoRedirectUri: window.location.origin + '/silent-check-sso.html',
|
1813 | checkLoginIframe: !0,
|
1814 | silentCheckSsoFallback: !0,
|
1815 | enableLogging: !0,
|
1816 | },
|
1817 | getUrl = function (e) {
|
1818 | var t = e.authServerUrl,
|
1819 | r = e.realm;
|
1820 | return t
|
1821 | ? '/' === t.charAt(t.length - 1)
|
1822 | ? t + 'realms/' + encodeURIComponent(r)
|
1823 | : t + '/realms/' + encodeURIComponent(r)
|
1824 | : null;
|
1825 | },
|
1826 | getRedirectUri = function (e, t) {
|
1827 | return null != t && t.redirectUri
|
1828 | ? t.redirectUri
|
1829 | : e.redirectUri
|
1830 | ? e.redirectUri
|
1831 | : location.href;
|
1832 | },
|
1833 | getLogoutUrl = function (e, t) {
|
1834 | var r = e.idToken,
|
1835 | o = e.clientId;
|
1836 | return (
|
1837 | getUrl(e) +
|
1838 | '/winklogout?post_logout_redirect_uri=' +
|
1839 | encodeURIComponent(getRedirectUri(e, t)) +
|
1840 | '&id_token_hint=' +
|
1841 | encodeURIComponent(r) +
|
1842 | '&client_id=' +
|
1843 | encodeURIComponent(o)
|
1844 | );
|
1845 | },
|
1846 | changeUrlWithoutReloading = function (e) {
|
1847 | history.pushState({ page: e }, '', e);
|
1848 | },
|
1849 | getUrlParamValue = function (e) {
|
1850 | var t = window.location.search;
|
1851 | return new URLSearchParams(t).get(e);
|
1852 | },
|
1853 | removeUrlParam = function (e) {
|
1854 | var t = window.location,
|
1855 | r = removeParameterFromUrl(t.href, e);
|
1856 | changeUrlWithoutReloading(r);
|
1857 | },
|
1858 | removeParameterFromUrl = function (e, t) {
|
1859 | var r = new URL(e),
|
1860 | o = r.searchParams;
|
1861 | return o.delete(t), (r.search = o.toString()), r.toString();
|
1862 | },
|
1863 | winkSetCookie = function (e, t, r) {
|
1864 | void 0 === r && (r = 1);
|
1865 | var o = new Date();
|
1866 | o.setTime(o.getTime() + 24 * r * 60 * 60 * 1e3);
|
1867 | var n = 'expires=' + o.toUTCString();
|
1868 | document.cookie = e + '=' + t + ';' + n + ';path=/';
|
1869 | },
|
1870 | winkGetCookie = function (e) {
|
1871 | for (
|
1872 | var t = e + '=', r = decodeURIComponent(document.cookie).split(';'), o = 0;
|
1873 | o < r.length;
|
1874 | o++
|
1875 | ) {
|
1876 | for (var n = r[o]; ' ' == n.charAt(0); ) n = n.substring(1);
|
1877 | if (0 == n.indexOf(t)) return n.substring(t.length, n.length);
|
1878 | }
|
1879 | return '';
|
1880 | },
|
1881 | winkEraseCookie = function (e) {
|
1882 | document.cookie = e + '=; Max-Age=-99999999;';
|
1883 | };
|
1884 | function _catch(e, t) {
|
1885 | try {
|
1886 | var r = e();
|
1887 | } catch (e) {
|
1888 | return t(e);
|
1889 | }
|
1890 | return r && r.then ? r.then(void 0, t) : r;
|
1891 | }
|
1892 | var CustomKeycloak = (function (e) {
|
1893 | function t(t) {
|
1894 | var r, o;
|
1895 | return (
|
1896 | ((o = e.call(this, t) || this).onAuthErrorFailure = void 0),
|
1897 | (o.loggingEnabled = !0),
|
1898 | (o.createLogoutUrl = function (e) {
|
1899 | try {
|
1900 | return getLogoutUrl(_assertThisInitialized(o), e);
|
1901 | } catch (e) {
|
1902 | throw (
|
1903 | (o.loggingEnabled && console.error('Error while constructing the logout url: ', e), e)
|
1904 | );
|
1905 | }
|
1906 | }),
|
1907 | (o.winkInit = function (e) {
|
1908 | try {
|
1909 | var t = null != e ? e : {},
|
1910 | r = t.onFailure,
|
1911 | n = t.onSuccess,
|
1912 | i = _catch(
|
1913 | function () {
|
1914 | return (
|
1915 | o.loggingEnabled && console.debug('Calling Keycloak init.'),
|
1916 | Promise.resolve(o.init(defaultKeycloakInitConfig)).then(function (e) {
|
1917 | e
|
1918 | ? (null == n || n(), winkSetCookie('wink_id_token', o.idToken))
|
1919 | : '1' === getUrlParamValue('login_session_state') && o.winkLogin();
|
1920 | })
|
1921 | );
|
1922 | },
|
1923 | function (e) {
|
1924 | o.loggingEnabled && console.error('Error while wink client initialization: ', e),
|
1925 | null == r || r(e);
|
1926 | }
|
1927 | );
|
1928 | return Promise.resolve(i && i.then ? i.then(function () {}) : void 0);
|
1929 | } catch (e) {
|
1930 | return Promise.reject(e);
|
1931 | }
|
1932 | }),
|
1933 | (o.winkLogin = function (e) {
|
1934 | try {
|
1935 | var t = (null != e ? e : {}).onFailure,
|
1936 | r = _catch(
|
1937 | function () {
|
1938 | return (
|
1939 | o.loggingEnabled && console.debug('Calling Keycloak login.'),
|
1940 | Promise.resolve(o.login(e)).then(function () {})
|
1941 | );
|
1942 | },
|
1943 | function (e) {
|
1944 | o.loggingEnabled && console.error('Error while wink client login: ', e),
|
1945 | null == t || t(e);
|
1946 | }
|
1947 | );
|
1948 | return Promise.resolve(r && r.then ? r.then(function () {}) : void 0);
|
1949 | } catch (e) {
|
1950 | return Promise.reject(e);
|
1951 | }
|
1952 | }),
|
1953 | (o.winkLogout = function (e) {
|
1954 | try {
|
1955 | var t = (null != e ? e : {}).onFailure,
|
1956 | r = _catch(
|
1957 | function () {
|
1958 | var t;
|
1959 | return (
|
1960 | o.loggingEnabled && console.debug('Calling Keycloak logout.'),
|
1961 | (o.idToken = null != (t = o.idToken) ? t : winkGetCookie('wink_id_token')),
|
1962 | winkEraseCookie('wink_id_token'),
|
1963 | removeUrlParam('login_session_state'),
|
1964 | Promise.resolve(o.logout(e)).then(function () {})
|
1965 | );
|
1966 | },
|
1967 | function (e) {
|
1968 | o.loggingEnabled && console.error('Error while wink client logout: ', e),
|
1969 | null == t || t(e);
|
1970 | }
|
1971 | );
|
1972 | return Promise.resolve(r && r.then ? r.then(function () {}) : void 0);
|
1973 | } catch (e) {
|
1974 | return Promise.reject(e);
|
1975 | }
|
1976 | }),
|
1977 | (o.onAuthErrorFailure = t.onAuthErrorFailure),
|
1978 | (o.loggingEnabled = null == (r = t.loggingEnabled) || r),
|
1979 | o
|
1980 | );
|
1981 | }
|
1982 | _inheritsLoose(t, e);
|
1983 | var r = t.prototype;
|
1984 | return (
|
1985 | (r.onReady = function (e) {
|
1986 | this.loggingEnabled &&
|
1987 | (console.debug('Keycloak client ready.'),
|
1988 | console.debug('Keycloak client authenticated: ', e));
|
1989 | }),
|
1990 | (r.onAuthError = function (e) {
|
1991 | var t;
|
1992 | null == (t = this.onAuthErrorFailure) || t.call(this, e),
|
1993 | this.loggingEnabled && console.error('Keycloak client authentication error: ', e);
|
1994 | }),
|
1995 | t
|
1996 | );
|
1997 | })(Keycloak),
|
1998 | getWinkLoginClient = function (e) {
|
1999 | var t = new CustomKeycloak(e),
|
2000 | r = t.createLoginUrl;
|
2001 | return (
|
2002 | (t.createLoginUrl = function (t) {
|
2003 | var o,
|
2004 | n = r.call(this, t);
|
2005 | return appendParentOriginIntoUrl(n, null == (o = e.loggingEnabled) || o);
|
2006 | }),
|
2007 | t
|
2008 | );
|
2009 | };
|
2010 | console.info('winklogin.module.js - version 2.1.1'),
|
2011 | (window.getWinkLoginClient = getWinkLoginClient);
|
2012 |
|