dash-button-web 0.0.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/dash-button.cjs.entry.js +2549 -0
  3. package/dist/cjs/dash-button.cjs.entry.js.map +1 -0
  4. package/dist/cjs/index-8282b36b.js +1733 -0
  5. package/dist/cjs/index-8282b36b.js.map +1 -0
  6. package/dist/cjs/index.cjs.js +4 -0
  7. package/dist/cjs/index.cjs.js.map +1 -0
  8. package/dist/cjs/loader.cjs.js +15 -0
  9. package/dist/cjs/loader.cjs.js.map +1 -0
  10. package/dist/cjs/web-compnont.cjs.js +25 -0
  11. package/dist/cjs/web-compnont.cjs.js.map +1 -0
  12. package/dist/collection/collection-manifest.json +12 -0
  13. package/dist/collection/components/my-component/dash-button.css +169 -0
  14. package/dist/collection/components/my-component/dash-button.e2e.js +26 -0
  15. package/dist/collection/components/my-component/dash-button.e2e.js.map +1 -0
  16. package/dist/collection/components/my-component/dash-button.js +195 -0
  17. package/dist/collection/components/my-component/dash-button.js.map +1 -0
  18. package/dist/collection/components/my-component/dash-button.spec.js +35 -0
  19. package/dist/collection/components/my-component/dash-button.spec.js.map +1 -0
  20. package/dist/collection/index.js +2 -0
  21. package/dist/collection/index.js.map +1 -0
  22. package/dist/components/dash-button.d.ts +11 -0
  23. package/dist/components/dash-button.js +2574 -0
  24. package/dist/components/dash-button.js.map +1 -0
  25. package/dist/components/index.d.ts +33 -0
  26. package/dist/components/index.js +3 -0
  27. package/dist/components/index.js.map +1 -0
  28. package/dist/esm/dash-button.entry.js +2545 -0
  29. package/dist/esm/dash-button.entry.js.map +1 -0
  30. package/dist/esm/index-2b6c17bc.js +1706 -0
  31. package/dist/esm/index-2b6c17bc.js.map +1 -0
  32. package/dist/esm/index.js +3 -0
  33. package/dist/esm/index.js.map +1 -0
  34. package/dist/esm/loader.js +11 -0
  35. package/dist/esm/loader.js.map +1 -0
  36. package/dist/esm/polyfills/core-js.js +11 -0
  37. package/dist/esm/polyfills/dom.js +79 -0
  38. package/dist/esm/polyfills/es5-html-element.js +1 -0
  39. package/dist/esm/polyfills/index.js +34 -0
  40. package/dist/esm/polyfills/system.js +6 -0
  41. package/dist/esm/web-compnont.js +20 -0
  42. package/dist/esm/web-compnont.js.map +1 -0
  43. package/dist/index.cjs.js +1 -0
  44. package/dist/index.js +1 -0
  45. package/dist/types/components/my-component/dash-button.d.ts +19 -0
  46. package/dist/types/components.d.ts +49 -0
  47. package/dist/types/index.d.ts +1 -0
  48. package/dist/types/stencil-public-runtime.d.ts +1681 -0
  49. package/dist/web-compnont/index.esm.js +2 -0
  50. package/dist/web-compnont/index.esm.js.map +1 -0
  51. package/dist/web-compnont/p-35259f64.js +3 -0
  52. package/dist/web-compnont/p-35259f64.js.map +1 -0
  53. package/dist/web-compnont/p-97a6df2d.entry.js +10 -0
  54. package/dist/web-compnont/p-97a6df2d.entry.js.map +1 -0
  55. package/dist/web-compnont/web-compnont.esm.js +2 -0
  56. package/dist/web-compnont/web-compnont.esm.js.map +1 -0
  57. package/loader/cdn.js +3 -0
  58. package/loader/index.cjs.js +3 -0
  59. package/loader/index.d.ts +21 -0
  60. package/loader/index.es2017.js +3 -0
  61. package/loader/index.js +4 -0
  62. package/loader/package.json +11 -0
  63. package/package.json +41 -0
  64. package/readme.md +124 -0
@@ -0,0 +1,2549 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-8282b36b.js');
6
+
7
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
+
9
+ function getAugmentedNamespace(n) {
10
+ if (n.__esModule) return n;
11
+ var a = Object.defineProperty({}, '__esModule', {value: true});
12
+ Object.keys(n).forEach(function (k) {
13
+ var d = Object.getOwnPropertyDescriptor(n, k);
14
+ Object.defineProperty(a, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () {
17
+ return n[k];
18
+ }
19
+ });
20
+ });
21
+ return a;
22
+ }
23
+
24
+ var base64Js = {};
25
+
26
+ base64Js.byteLength = byteLength;
27
+ base64Js.toByteArray = toByteArray;
28
+ base64Js.fromByteArray = fromByteArray;
29
+
30
+ var lookup = [];
31
+ var revLookup = [];
32
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
33
+
34
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
35
+ for (var i = 0, len = code.length; i < len; ++i) {
36
+ lookup[i] = code[i];
37
+ revLookup[code.charCodeAt(i)] = i;
38
+ }
39
+
40
+ // Support decoding URL-safe base64 strings, as Node.js does.
41
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
42
+ revLookup['-'.charCodeAt(0)] = 62;
43
+ revLookup['_'.charCodeAt(0)] = 63;
44
+
45
+ function getLens (b64) {
46
+ var len = b64.length;
47
+
48
+ if (len % 4 > 0) {
49
+ throw new Error('Invalid string. Length must be a multiple of 4')
50
+ }
51
+
52
+ // Trim off extra bytes after placeholder bytes are found
53
+ // See: https://github.com/beatgammit/base64-js/issues/42
54
+ var validLen = b64.indexOf('=');
55
+ if (validLen === -1) validLen = len;
56
+
57
+ var placeHoldersLen = validLen === len
58
+ ? 0
59
+ : 4 - (validLen % 4);
60
+
61
+ return [validLen, placeHoldersLen]
62
+ }
63
+
64
+ // base64 is 4/3 + up to two characters of the original data
65
+ function byteLength (b64) {
66
+ var lens = getLens(b64);
67
+ var validLen = lens[0];
68
+ var placeHoldersLen = lens[1];
69
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
70
+ }
71
+
72
+ function _byteLength (b64, validLen, placeHoldersLen) {
73
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
74
+ }
75
+
76
+ function toByteArray (b64) {
77
+ var tmp;
78
+ var lens = getLens(b64);
79
+ var validLen = lens[0];
80
+ var placeHoldersLen = lens[1];
81
+
82
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
83
+
84
+ var curByte = 0;
85
+
86
+ // if there are placeholders, only get up to the last complete 4 chars
87
+ var len = placeHoldersLen > 0
88
+ ? validLen - 4
89
+ : validLen;
90
+
91
+ var i;
92
+ for (i = 0; i < len; i += 4) {
93
+ tmp =
94
+ (revLookup[b64.charCodeAt(i)] << 18) |
95
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
96
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
97
+ revLookup[b64.charCodeAt(i + 3)];
98
+ arr[curByte++] = (tmp >> 16) & 0xFF;
99
+ arr[curByte++] = (tmp >> 8) & 0xFF;
100
+ arr[curByte++] = tmp & 0xFF;
101
+ }
102
+
103
+ if (placeHoldersLen === 2) {
104
+ tmp =
105
+ (revLookup[b64.charCodeAt(i)] << 2) |
106
+ (revLookup[b64.charCodeAt(i + 1)] >> 4);
107
+ arr[curByte++] = tmp & 0xFF;
108
+ }
109
+
110
+ if (placeHoldersLen === 1) {
111
+ tmp =
112
+ (revLookup[b64.charCodeAt(i)] << 10) |
113
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
114
+ (revLookup[b64.charCodeAt(i + 2)] >> 2);
115
+ arr[curByte++] = (tmp >> 8) & 0xFF;
116
+ arr[curByte++] = tmp & 0xFF;
117
+ }
118
+
119
+ return arr
120
+ }
121
+
122
+ function tripletToBase64 (num) {
123
+ return lookup[num >> 18 & 0x3F] +
124
+ lookup[num >> 12 & 0x3F] +
125
+ lookup[num >> 6 & 0x3F] +
126
+ lookup[num & 0x3F]
127
+ }
128
+
129
+ function encodeChunk (uint8, start, end) {
130
+ var tmp;
131
+ var output = [];
132
+ for (var i = start; i < end; i += 3) {
133
+ tmp =
134
+ ((uint8[i] << 16) & 0xFF0000) +
135
+ ((uint8[i + 1] << 8) & 0xFF00) +
136
+ (uint8[i + 2] & 0xFF);
137
+ output.push(tripletToBase64(tmp));
138
+ }
139
+ return output.join('')
140
+ }
141
+
142
+ function fromByteArray (uint8) {
143
+ var tmp;
144
+ var len = uint8.length;
145
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
146
+ var parts = [];
147
+ var maxChunkLength = 16383; // must be multiple of 3
148
+
149
+ // go through the array every three bytes, we'll deal with trailing stuff later
150
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
151
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
152
+ }
153
+
154
+ // pad the end with zeros, but make sure to not forget the extra bytes
155
+ if (extraBytes === 1) {
156
+ tmp = uint8[len - 1];
157
+ parts.push(
158
+ lookup[tmp >> 2] +
159
+ lookup[(tmp << 4) & 0x3F] +
160
+ '=='
161
+ );
162
+ } else if (extraBytes === 2) {
163
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
164
+ parts.push(
165
+ lookup[tmp >> 10] +
166
+ lookup[(tmp >> 4) & 0x3F] +
167
+ lookup[(tmp << 2) & 0x3F] +
168
+ '='
169
+ );
170
+ }
171
+
172
+ return parts.join('')
173
+ }
174
+
175
+ var sha256$1 = {exports: {}};
176
+
177
+ const _nodeResolve_empty = {};
178
+
179
+ const _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
180
+ __proto__: null,
181
+ 'default': _nodeResolve_empty
182
+ });
183
+
184
+ const require$$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
185
+
186
+ /**
187
+ * [js-sha256]{@link https://github.com/emn178/js-sha256}
188
+ *
189
+ * @version 0.10.1
190
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
191
+ * @copyright Chen, Yi-Cyuan 2014-2023
192
+ * @license MIT
193
+ */
194
+
195
+ (function (module) {
196
+ /*jslint bitwise: true */
197
+ (function () {
198
+
199
+ var ERROR = 'input is invalid type';
200
+ var WINDOW = typeof window === 'object';
201
+ var root = WINDOW ? window : {};
202
+ if (root.JS_SHA256_NO_WINDOW) {
203
+ WINDOW = false;
204
+ }
205
+ var WEB_WORKER = !WINDOW && typeof self === 'object';
206
+ var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
207
+ if (NODE_JS) {
208
+ root = commonjsGlobal;
209
+ } else if (WEB_WORKER) {
210
+ root = self;
211
+ }
212
+ var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && 'object' === 'object' && module.exports;
213
+ var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
214
+ var HEX_CHARS = '0123456789abcdef'.split('');
215
+ var EXTRA = [-2147483648, 8388608, 32768, 128];
216
+ var SHIFT = [24, 16, 8, 0];
217
+ var K = [
218
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
219
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
220
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
221
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
222
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
223
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
224
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
225
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
226
+ ];
227
+ var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
228
+
229
+ var blocks = [];
230
+
231
+ if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
232
+ Array.isArray = function (obj) {
233
+ return Object.prototype.toString.call(obj) === '[object Array]';
234
+ };
235
+ }
236
+
237
+ if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
238
+ ArrayBuffer.isView = function (obj) {
239
+ return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
240
+ };
241
+ }
242
+
243
+ var createOutputMethod = function (outputType, is224) {
244
+ return function (message) {
245
+ return new Sha256(is224, true).update(message)[outputType]();
246
+ };
247
+ };
248
+
249
+ var createMethod = function (is224) {
250
+ var method = createOutputMethod('hex', is224);
251
+ if (NODE_JS) {
252
+ method = nodeWrap(method, is224);
253
+ }
254
+ method.create = function () {
255
+ return new Sha256(is224);
256
+ };
257
+ method.update = function (message) {
258
+ return method.create().update(message);
259
+ };
260
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
261
+ var type = OUTPUT_TYPES[i];
262
+ method[type] = createOutputMethod(type, is224);
263
+ }
264
+ return method;
265
+ };
266
+
267
+ var nodeWrap = function (method, is224) {
268
+ var crypto = require$$1;
269
+ var Buffer = require$$1.Buffer;
270
+ var algorithm = is224 ? 'sha224' : 'sha256';
271
+ var bufferFrom;
272
+ if (Buffer.from && !root.JS_SHA256_NO_BUFFER_FROM) {
273
+ bufferFrom = Buffer.from;
274
+ } else {
275
+ bufferFrom = function (message) {
276
+ return new Buffer(message);
277
+ };
278
+ }
279
+ var nodeMethod = function (message) {
280
+ if (typeof message === 'string') {
281
+ return crypto.createHash(algorithm).update(message, 'utf8').digest('hex');
282
+ } else {
283
+ if (message === null || message === undefined) {
284
+ throw new Error(ERROR);
285
+ } else if (message.constructor === ArrayBuffer) {
286
+ message = new Uint8Array(message);
287
+ }
288
+ }
289
+ if (Array.isArray(message) || ArrayBuffer.isView(message) ||
290
+ message.constructor === Buffer) {
291
+ return crypto.createHash(algorithm).update(bufferFrom(message)).digest('hex');
292
+ } else {
293
+ return method(message);
294
+ }
295
+ };
296
+ return nodeMethod;
297
+ };
298
+
299
+ var createHmacOutputMethod = function (outputType, is224) {
300
+ return function (key, message) {
301
+ return new HmacSha256(key, is224, true).update(message)[outputType]();
302
+ };
303
+ };
304
+
305
+ var createHmacMethod = function (is224) {
306
+ var method = createHmacOutputMethod('hex', is224);
307
+ method.create = function (key) {
308
+ return new HmacSha256(key, is224);
309
+ };
310
+ method.update = function (key, message) {
311
+ return method.create(key).update(message);
312
+ };
313
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
314
+ var type = OUTPUT_TYPES[i];
315
+ method[type] = createHmacOutputMethod(type, is224);
316
+ }
317
+ return method;
318
+ };
319
+
320
+ function Sha256(is224, sharedMemory) {
321
+ if (sharedMemory) {
322
+ blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
323
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
324
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
325
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
326
+ this.blocks = blocks;
327
+ } else {
328
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
329
+ }
330
+
331
+ if (is224) {
332
+ this.h0 = 0xc1059ed8;
333
+ this.h1 = 0x367cd507;
334
+ this.h2 = 0x3070dd17;
335
+ this.h3 = 0xf70e5939;
336
+ this.h4 = 0xffc00b31;
337
+ this.h5 = 0x68581511;
338
+ this.h6 = 0x64f98fa7;
339
+ this.h7 = 0xbefa4fa4;
340
+ } else { // 256
341
+ this.h0 = 0x6a09e667;
342
+ this.h1 = 0xbb67ae85;
343
+ this.h2 = 0x3c6ef372;
344
+ this.h3 = 0xa54ff53a;
345
+ this.h4 = 0x510e527f;
346
+ this.h5 = 0x9b05688c;
347
+ this.h6 = 0x1f83d9ab;
348
+ this.h7 = 0x5be0cd19;
349
+ }
350
+
351
+ this.block = this.start = this.bytes = this.hBytes = 0;
352
+ this.finalized = this.hashed = false;
353
+ this.first = true;
354
+ this.is224 = is224;
355
+ }
356
+
357
+ Sha256.prototype.update = function (message) {
358
+ if (this.finalized) {
359
+ return;
360
+ }
361
+ var notString, type = typeof message;
362
+ if (type !== 'string') {
363
+ if (type === 'object') {
364
+ if (message === null) {
365
+ throw new Error(ERROR);
366
+ } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
367
+ message = new Uint8Array(message);
368
+ } else if (!Array.isArray(message)) {
369
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
370
+ throw new Error(ERROR);
371
+ }
372
+ }
373
+ } else {
374
+ throw new Error(ERROR);
375
+ }
376
+ notString = true;
377
+ }
378
+ var code, index = 0, i, length = message.length, blocks = this.blocks;
379
+
380
+ while (index < length) {
381
+ if (this.hashed) {
382
+ this.hashed = false;
383
+ blocks[0] = this.block;
384
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
385
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
386
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
387
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
388
+ }
389
+
390
+ if (notString) {
391
+ for (i = this.start; index < length && i < 64; ++index) {
392
+ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
393
+ }
394
+ } else {
395
+ for (i = this.start; index < length && i < 64; ++index) {
396
+ code = message.charCodeAt(index);
397
+ if (code < 0x80) {
398
+ blocks[i >> 2] |= code << SHIFT[i++ & 3];
399
+ } else if (code < 0x800) {
400
+ blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
401
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
402
+ } else if (code < 0xd800 || code >= 0xe000) {
403
+ blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
404
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
405
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
406
+ } else {
407
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
408
+ blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
409
+ blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
410
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
411
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
412
+ }
413
+ }
414
+ }
415
+
416
+ this.lastByteIndex = i;
417
+ this.bytes += i - this.start;
418
+ if (i >= 64) {
419
+ this.block = blocks[16];
420
+ this.start = i - 64;
421
+ this.hash();
422
+ this.hashed = true;
423
+ } else {
424
+ this.start = i;
425
+ }
426
+ }
427
+ if (this.bytes > 4294967295) {
428
+ this.hBytes += this.bytes / 4294967296 << 0;
429
+ this.bytes = this.bytes % 4294967296;
430
+ }
431
+ return this;
432
+ };
433
+
434
+ Sha256.prototype.finalize = function () {
435
+ if (this.finalized) {
436
+ return;
437
+ }
438
+ this.finalized = true;
439
+ var blocks = this.blocks, i = this.lastByteIndex;
440
+ blocks[16] = this.block;
441
+ blocks[i >> 2] |= EXTRA[i & 3];
442
+ this.block = blocks[16];
443
+ if (i >= 56) {
444
+ if (!this.hashed) {
445
+ this.hash();
446
+ }
447
+ blocks[0] = this.block;
448
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
449
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
450
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
451
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
452
+ }
453
+ blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
454
+ blocks[15] = this.bytes << 3;
455
+ this.hash();
456
+ };
457
+
458
+ Sha256.prototype.hash = function () {
459
+ var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6,
460
+ h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
461
+
462
+ for (j = 16; j < 64; ++j) {
463
+ // rightrotate
464
+ t1 = blocks[j - 15];
465
+ s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
466
+ t1 = blocks[j - 2];
467
+ s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
468
+ blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
469
+ }
470
+
471
+ bc = b & c;
472
+ for (j = 0; j < 64; j += 4) {
473
+ if (this.first) {
474
+ if (this.is224) {
475
+ ab = 300032;
476
+ t1 = blocks[0] - 1413257819;
477
+ h = t1 - 150054599 << 0;
478
+ d = t1 + 24177077 << 0;
479
+ } else {
480
+ ab = 704751109;
481
+ t1 = blocks[0] - 210244248;
482
+ h = t1 - 1521486534 << 0;
483
+ d = t1 + 143694565 << 0;
484
+ }
485
+ this.first = false;
486
+ } else {
487
+ s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
488
+ s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
489
+ ab = a & b;
490
+ maj = ab ^ (a & c) ^ bc;
491
+ ch = (e & f) ^ (~e & g);
492
+ t1 = h + s1 + ch + K[j] + blocks[j];
493
+ t2 = s0 + maj;
494
+ h = d + t1 << 0;
495
+ d = t1 + t2 << 0;
496
+ }
497
+ s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10));
498
+ s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7));
499
+ da = d & a;
500
+ maj = da ^ (d & b) ^ ab;
501
+ ch = (h & e) ^ (~h & f);
502
+ t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
503
+ t2 = s0 + maj;
504
+ g = c + t1 << 0;
505
+ c = t1 + t2 << 0;
506
+ s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10));
507
+ s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7));
508
+ cd = c & d;
509
+ maj = cd ^ (c & a) ^ da;
510
+ ch = (g & h) ^ (~g & e);
511
+ t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
512
+ t2 = s0 + maj;
513
+ f = b + t1 << 0;
514
+ b = t1 + t2 << 0;
515
+ s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10));
516
+ s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7));
517
+ bc = b & c;
518
+ maj = bc ^ (b & d) ^ cd;
519
+ ch = (f & g) ^ (~f & h);
520
+ t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
521
+ t2 = s0 + maj;
522
+ e = a + t1 << 0;
523
+ a = t1 + t2 << 0;
524
+ this.chromeBugWorkAround = true;
525
+ }
526
+
527
+ this.h0 = this.h0 + a << 0;
528
+ this.h1 = this.h1 + b << 0;
529
+ this.h2 = this.h2 + c << 0;
530
+ this.h3 = this.h3 + d << 0;
531
+ this.h4 = this.h4 + e << 0;
532
+ this.h5 = this.h5 + f << 0;
533
+ this.h6 = this.h6 + g << 0;
534
+ this.h7 = this.h7 + h << 0;
535
+ };
536
+
537
+ Sha256.prototype.hex = function () {
538
+ this.finalize();
539
+
540
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
541
+ h6 = this.h6, h7 = this.h7;
542
+
543
+ var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
544
+ HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
545
+ HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
546
+ HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
547
+ HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
548
+ HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
549
+ HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
550
+ HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
551
+ HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
552
+ HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
553
+ HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
554
+ HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
555
+ HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] +
556
+ HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
557
+ HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
558
+ HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
559
+ HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] +
560
+ HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] +
561
+ HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] +
562
+ HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] +
563
+ HEX_CHARS[(h5 >> 28) & 0x0F] + HEX_CHARS[(h5 >> 24) & 0x0F] +
564
+ HEX_CHARS[(h5 >> 20) & 0x0F] + HEX_CHARS[(h5 >> 16) & 0x0F] +
565
+ HEX_CHARS[(h5 >> 12) & 0x0F] + HEX_CHARS[(h5 >> 8) & 0x0F] +
566
+ HEX_CHARS[(h5 >> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] +
567
+ HEX_CHARS[(h6 >> 28) & 0x0F] + HEX_CHARS[(h6 >> 24) & 0x0F] +
568
+ HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] +
569
+ HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] +
570
+ HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
571
+ if (!this.is224) {
572
+ hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] +
573
+ HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] +
574
+ HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] +
575
+ HEX_CHARS[(h7 >> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F];
576
+ }
577
+ return hex;
578
+ };
579
+
580
+ Sha256.prototype.toString = Sha256.prototype.hex;
581
+
582
+ Sha256.prototype.digest = function () {
583
+ this.finalize();
584
+
585
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
586
+ h6 = this.h6, h7 = this.h7;
587
+
588
+ var arr = [
589
+ (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF,
590
+ (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF,
591
+ (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF,
592
+ (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF,
593
+ (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF,
594
+ (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, h5 & 0xFF,
595
+ (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, h6 & 0xFF
596
+ ];
597
+ if (!this.is224) {
598
+ arr.push((h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, h7 & 0xFF);
599
+ }
600
+ return arr;
601
+ };
602
+
603
+ Sha256.prototype.array = Sha256.prototype.digest;
604
+
605
+ Sha256.prototype.arrayBuffer = function () {
606
+ this.finalize();
607
+
608
+ var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
609
+ var dataView = new DataView(buffer);
610
+ dataView.setUint32(0, this.h0);
611
+ dataView.setUint32(4, this.h1);
612
+ dataView.setUint32(8, this.h2);
613
+ dataView.setUint32(12, this.h3);
614
+ dataView.setUint32(16, this.h4);
615
+ dataView.setUint32(20, this.h5);
616
+ dataView.setUint32(24, this.h6);
617
+ if (!this.is224) {
618
+ dataView.setUint32(28, this.h7);
619
+ }
620
+ return buffer;
621
+ };
622
+
623
+ function HmacSha256(key, is224, sharedMemory) {
624
+ var i, type = typeof key;
625
+ if (type === 'string') {
626
+ var bytes = [], length = key.length, index = 0, code;
627
+ for (i = 0; i < length; ++i) {
628
+ code = key.charCodeAt(i);
629
+ if (code < 0x80) {
630
+ bytes[index++] = code;
631
+ } else if (code < 0x800) {
632
+ bytes[index++] = (0xc0 | (code >> 6));
633
+ bytes[index++] = (0x80 | (code & 0x3f));
634
+ } else if (code < 0xd800 || code >= 0xe000) {
635
+ bytes[index++] = (0xe0 | (code >> 12));
636
+ bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
637
+ bytes[index++] = (0x80 | (code & 0x3f));
638
+ } else {
639
+ code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
640
+ bytes[index++] = (0xf0 | (code >> 18));
641
+ bytes[index++] = (0x80 | ((code >> 12) & 0x3f));
642
+ bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
643
+ bytes[index++] = (0x80 | (code & 0x3f));
644
+ }
645
+ }
646
+ key = bytes;
647
+ } else {
648
+ if (type === 'object') {
649
+ if (key === null) {
650
+ throw new Error(ERROR);
651
+ } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
652
+ key = new Uint8Array(key);
653
+ } else if (!Array.isArray(key)) {
654
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
655
+ throw new Error(ERROR);
656
+ }
657
+ }
658
+ } else {
659
+ throw new Error(ERROR);
660
+ }
661
+ }
662
+
663
+ if (key.length > 64) {
664
+ key = (new Sha256(is224, true)).update(key).array();
665
+ }
666
+
667
+ var oKeyPad = [], iKeyPad = [];
668
+ for (i = 0; i < 64; ++i) {
669
+ var b = key[i] || 0;
670
+ oKeyPad[i] = 0x5c ^ b;
671
+ iKeyPad[i] = 0x36 ^ b;
672
+ }
673
+
674
+ Sha256.call(this, is224, sharedMemory);
675
+
676
+ this.update(iKeyPad);
677
+ this.oKeyPad = oKeyPad;
678
+ this.inner = true;
679
+ this.sharedMemory = sharedMemory;
680
+ }
681
+ HmacSha256.prototype = new Sha256();
682
+
683
+ HmacSha256.prototype.finalize = function () {
684
+ Sha256.prototype.finalize.call(this);
685
+ if (this.inner) {
686
+ this.inner = false;
687
+ var innerHash = this.array();
688
+ Sha256.call(this, this.is224, this.sharedMemory);
689
+ this.update(this.oKeyPad);
690
+ this.update(innerHash);
691
+ Sha256.prototype.finalize.call(this);
692
+ }
693
+ };
694
+
695
+ var exports = createMethod();
696
+ exports.sha256 = exports;
697
+ exports.sha224 = createMethod(true);
698
+ exports.sha256.hmac = createHmacMethod();
699
+ exports.sha224.hmac = createHmacMethod(true);
700
+
701
+ if (COMMON_JS) {
702
+ module.exports = exports;
703
+ } else {
704
+ root.sha256 = exports.sha256;
705
+ root.sha224 = exports.sha224;
706
+ }
707
+ })();
708
+ }(sha256$1));
709
+
710
+ const sha256 = sha256$1.exports;
711
+
712
+ class InvalidTokenError extends Error {
713
+ }
714
+ InvalidTokenError.prototype.name = "InvalidTokenError";
715
+ function b64DecodeUnicode(str) {
716
+ return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
717
+ let code = p.charCodeAt(0).toString(16).toUpperCase();
718
+ if (code.length < 2) {
719
+ code = "0" + code;
720
+ }
721
+ return "%" + code;
722
+ }));
723
+ }
724
+ function base64UrlDecode(str) {
725
+ let output = str.replace(/-/g, "+").replace(/_/g, "/");
726
+ switch (output.length % 4) {
727
+ case 0:
728
+ break;
729
+ case 2:
730
+ output += "==";
731
+ break;
732
+ case 3:
733
+ output += "=";
734
+ break;
735
+ default:
736
+ throw new Error("base64 string is not of the correct length");
737
+ }
738
+ try {
739
+ return b64DecodeUnicode(output);
740
+ }
741
+ catch (err) {
742
+ return atob(output);
743
+ }
744
+ }
745
+ function jwtDecode(token, options) {
746
+ if (typeof token !== "string") {
747
+ throw new InvalidTokenError("Invalid token specified: must be a string");
748
+ }
749
+ options || (options = {});
750
+ const pos = options.header === true ? 0 : 1;
751
+ const part = token.split(".")[pos];
752
+ if (typeof part !== "string") {
753
+ throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
754
+ }
755
+ let decoded;
756
+ try {
757
+ decoded = base64UrlDecode(part);
758
+ }
759
+ catch (e) {
760
+ throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
761
+ }
762
+ try {
763
+ return JSON.parse(decoded);
764
+ }
765
+ catch (e) {
766
+ throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
767
+ }
768
+ }
769
+
770
+ /*
771
+ * Copyright 2016 Red Hat, Inc. and/or its affiliates
772
+ * and other contributors as indicated by the @author tags.
773
+ *
774
+ * Licensed under the Apache License, Version 2.0 (the "License");
775
+ * you may not use this file except in compliance with the License.
776
+ * You may obtain a copy of the License at
777
+ *
778
+ * http://www.apache.org/licenses/LICENSE-2.0
779
+ *
780
+ * Unless required by applicable law or agreed to in writing, software
781
+ * distributed under the License is distributed on an "AS IS" BASIS,
782
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
783
+ * See the License for the specific language governing permissions and
784
+ * limitations under the License.
785
+ */
786
+
787
+ if (typeof Promise === 'undefined') {
788
+ throw Error('Keycloak requires an environment that supports Promises. Make sure that you include the appropriate polyfill.');
789
+ }
790
+
791
+ function Keycloak (config) {
792
+ if (!(this instanceof Keycloak)) {
793
+ throw new Error("The 'Keycloak' constructor must be invoked with 'new'.")
794
+ }
795
+
796
+ var kc = this;
797
+ var adapter;
798
+ var refreshQueue = [];
799
+ var callbackStorage;
800
+
801
+ var loginIframe = {
802
+ enable: true,
803
+ callbackList: [],
804
+ interval: 5
805
+ };
806
+
807
+ var scripts = document.getElementsByTagName('script');
808
+ for (var i = 0; i < scripts.length; i++) {
809
+ if ((scripts[i].src.indexOf('keycloak.js') !== -1 || scripts[i].src.indexOf('keycloak.min.js') !== -1) && scripts[i].src.indexOf('version=') !== -1) {
810
+ kc.iframeVersion = scripts[i].src.substring(scripts[i].src.indexOf('version=') + 8).split('&')[0];
811
+ }
812
+ }
813
+
814
+ var useNonce = true;
815
+ var logInfo = createLogger(console.info);
816
+ var logWarn = createLogger(console.warn);
817
+
818
+ kc.init = function (initOptions) {
819
+ if (kc.didInitialize) {
820
+ throw new Error("A 'Keycloak' instance can only be initialized once.");
821
+ }
822
+
823
+ kc.didInitialize = true;
824
+
825
+ kc.authenticated = false;
826
+
827
+ callbackStorage = createCallbackStorage();
828
+ var adapters = ['default', 'cordova', 'cordova-native'];
829
+
830
+ if (initOptions && adapters.indexOf(initOptions.adapter) > -1) {
831
+ adapter = loadAdapter(initOptions.adapter);
832
+ } else if (initOptions && typeof initOptions.adapter === "object") {
833
+ adapter = initOptions.adapter;
834
+ } else {
835
+ if (window.Cordova || window.cordova) {
836
+ adapter = loadAdapter('cordova');
837
+ } else {
838
+ adapter = loadAdapter();
839
+ }
840
+ }
841
+
842
+ if (initOptions) {
843
+ if (typeof initOptions.useNonce !== 'undefined') {
844
+ useNonce = initOptions.useNonce;
845
+ }
846
+
847
+ if (typeof initOptions.checkLoginIframe !== 'undefined') {
848
+ loginIframe.enable = initOptions.checkLoginIframe;
849
+ }
850
+
851
+ if (initOptions.checkLoginIframeInterval) {
852
+ loginIframe.interval = initOptions.checkLoginIframeInterval;
853
+ }
854
+
855
+ if (initOptions.onLoad === 'login-required') {
856
+ kc.loginRequired = true;
857
+ }
858
+
859
+ if (initOptions.responseMode) {
860
+ if (initOptions.responseMode === 'query' || initOptions.responseMode === 'fragment') {
861
+ kc.responseMode = initOptions.responseMode;
862
+ } else {
863
+ throw 'Invalid value for responseMode';
864
+ }
865
+ }
866
+
867
+ if (initOptions.flow) {
868
+ switch (initOptions.flow) {
869
+ case 'standard':
870
+ kc.responseType = 'code';
871
+ break;
872
+ case 'implicit':
873
+ kc.responseType = 'id_token token';
874
+ break;
875
+ case 'hybrid':
876
+ kc.responseType = 'code id_token token';
877
+ break;
878
+ default:
879
+ throw 'Invalid value for flow';
880
+ }
881
+ kc.flow = initOptions.flow;
882
+ }
883
+
884
+ if (initOptions.timeSkew != null) {
885
+ kc.timeSkew = initOptions.timeSkew;
886
+ }
887
+
888
+ if(initOptions.redirectUri) {
889
+ kc.redirectUri = initOptions.redirectUri;
890
+ }
891
+
892
+ if (initOptions.silentCheckSsoRedirectUri) {
893
+ kc.silentCheckSsoRedirectUri = initOptions.silentCheckSsoRedirectUri;
894
+ }
895
+
896
+ if (typeof initOptions.silentCheckSsoFallback === 'boolean') {
897
+ kc.silentCheckSsoFallback = initOptions.silentCheckSsoFallback;
898
+ } else {
899
+ kc.silentCheckSsoFallback = true;
900
+ }
901
+
902
+ if (initOptions.pkceMethod) {
903
+ if (initOptions.pkceMethod !== "S256") {
904
+ throw 'Invalid value for pkceMethod';
905
+ }
906
+ kc.pkceMethod = initOptions.pkceMethod;
907
+ }
908
+
909
+ if (typeof initOptions.enableLogging === 'boolean') {
910
+ kc.enableLogging = initOptions.enableLogging;
911
+ } else {
912
+ kc.enableLogging = false;
913
+ }
914
+
915
+ if (typeof initOptions.scope === 'string') {
916
+ kc.scope = initOptions.scope;
917
+ }
918
+
919
+ if (typeof initOptions.acrValues === 'string') {
920
+ kc.acrValues = initOptions.acrValues;
921
+ }
922
+
923
+ if (typeof initOptions.messageReceiveTimeout === 'number' && initOptions.messageReceiveTimeout > 0) {
924
+ kc.messageReceiveTimeout = initOptions.messageReceiveTimeout;
925
+ } else {
926
+ kc.messageReceiveTimeout = 10000;
927
+ }
928
+ }
929
+
930
+ if (!kc.responseMode) {
931
+ kc.responseMode = 'fragment';
932
+ }
933
+ if (!kc.responseType) {
934
+ kc.responseType = 'code';
935
+ kc.flow = 'standard';
936
+ }
937
+
938
+ var promise = createPromise();
939
+
940
+ var initPromise = createPromise();
941
+ initPromise.promise.then(function() {
942
+ kc.onReady && kc.onReady(kc.authenticated);
943
+ promise.setSuccess(kc.authenticated);
944
+ }).catch(function(error) {
945
+ promise.setError(error);
946
+ });
947
+
948
+ var configPromise = loadConfig();
949
+
950
+ function onLoad() {
951
+ var doLogin = function(prompt) {
952
+ if (!prompt) {
953
+ options.prompt = 'none';
954
+ }
955
+
956
+ if (initOptions && initOptions.locale) {
957
+ options.locale = initOptions.locale;
958
+ }
959
+ kc.login(options).then(function () {
960
+ initPromise.setSuccess();
961
+ }).catch(function (error) {
962
+ initPromise.setError(error);
963
+ });
964
+ };
965
+
966
+ var checkSsoSilently = function() {
967
+ var ifrm = document.createElement("iframe");
968
+ var src = kc.createLoginUrl({prompt: 'none', redirectUri: kc.silentCheckSsoRedirectUri});
969
+ ifrm.setAttribute("src", src);
970
+ ifrm.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin");
971
+ ifrm.setAttribute("title", "keycloak-silent-check-sso");
972
+ ifrm.style.display = "none";
973
+ document.body.appendChild(ifrm);
974
+
975
+ var messageCallback = function(event) {
976
+ if (event.origin !== window.location.origin || ifrm.contentWindow !== event.source) {
977
+ return;
978
+ }
979
+
980
+ var oauth = parseCallback(event.data);
981
+ processCallback(oauth, initPromise);
982
+
983
+ document.body.removeChild(ifrm);
984
+ window.removeEventListener("message", messageCallback);
985
+ };
986
+
987
+ window.addEventListener("message", messageCallback);
988
+ };
989
+
990
+ var options = {};
991
+ switch (initOptions.onLoad) {
992
+ case 'check-sso':
993
+ if (loginIframe.enable) {
994
+ setupCheckLoginIframe().then(function() {
995
+ checkLoginIframe().then(function (unchanged) {
996
+ if (!unchanged) {
997
+ kc.silentCheckSsoRedirectUri ? checkSsoSilently() : doLogin(false);
998
+ } else {
999
+ initPromise.setSuccess();
1000
+ }
1001
+ }).catch(function (error) {
1002
+ initPromise.setError(error);
1003
+ });
1004
+ });
1005
+ } else {
1006
+ kc.silentCheckSsoRedirectUri ? checkSsoSilently() : doLogin(false);
1007
+ }
1008
+ break;
1009
+ case 'login-required':
1010
+ doLogin(true);
1011
+ break;
1012
+ default:
1013
+ throw 'Invalid value for onLoad';
1014
+ }
1015
+ }
1016
+
1017
+ function processInit() {
1018
+ var callback = parseCallback(window.location.href);
1019
+
1020
+ if (callback) {
1021
+ window.history.replaceState(window.history.state, null, callback.newUrl);
1022
+ }
1023
+
1024
+ if (callback && callback.valid) {
1025
+ return setupCheckLoginIframe().then(function() {
1026
+ processCallback(callback, initPromise);
1027
+ }).catch(function (error) {
1028
+ initPromise.setError(error);
1029
+ });
1030
+ } else if (initOptions) {
1031
+ if (initOptions.token && initOptions.refreshToken) {
1032
+ setToken(initOptions.token, initOptions.refreshToken, initOptions.idToken);
1033
+
1034
+ if (loginIframe.enable) {
1035
+ setupCheckLoginIframe().then(function() {
1036
+ checkLoginIframe().then(function (unchanged) {
1037
+ if (unchanged) {
1038
+ kc.onAuthSuccess && kc.onAuthSuccess();
1039
+ initPromise.setSuccess();
1040
+ scheduleCheckIframe();
1041
+ } else {
1042
+ initPromise.setSuccess();
1043
+ }
1044
+ }).catch(function (error) {
1045
+ initPromise.setError(error);
1046
+ });
1047
+ });
1048
+ } else {
1049
+ kc.updateToken(-1).then(function() {
1050
+ kc.onAuthSuccess && kc.onAuthSuccess();
1051
+ initPromise.setSuccess();
1052
+ }).catch(function(error) {
1053
+ kc.onAuthError && kc.onAuthError();
1054
+ if (initOptions.onLoad) {
1055
+ onLoad();
1056
+ } else {
1057
+ initPromise.setError(error);
1058
+ }
1059
+ });
1060
+ }
1061
+ } else if (initOptions.onLoad) {
1062
+ onLoad();
1063
+ } else {
1064
+ initPromise.setSuccess();
1065
+ }
1066
+ } else {
1067
+ initPromise.setSuccess();
1068
+ }
1069
+ }
1070
+
1071
+ function domReady() {
1072
+ var promise = createPromise();
1073
+
1074
+ var checkReadyState = function () {
1075
+ if (document.readyState === 'interactive' || document.readyState === 'complete') {
1076
+ document.removeEventListener('readystatechange', checkReadyState);
1077
+ promise.setSuccess();
1078
+ }
1079
+ };
1080
+ document.addEventListener('readystatechange', checkReadyState);
1081
+
1082
+ checkReadyState(); // just in case the event was already fired and we missed it (in case the init is done later than at the load time, i.e. it's done from code)
1083
+
1084
+ return promise.promise;
1085
+ }
1086
+
1087
+ configPromise.then(function () {
1088
+ domReady()
1089
+ .then(check3pCookiesSupported)
1090
+ .then(processInit)
1091
+ .catch(function (error) {
1092
+ promise.setError(error);
1093
+ });
1094
+ });
1095
+ configPromise.catch(function (error) {
1096
+ promise.setError(error);
1097
+ });
1098
+
1099
+ return promise.promise;
1100
+ };
1101
+
1102
+ kc.login = function (options) {
1103
+ return adapter.login(options);
1104
+ };
1105
+
1106
+ function generateRandomData(len) {
1107
+ // use web crypto APIs if possible
1108
+ var array = null;
1109
+ var crypto = window.crypto || window.msCrypto;
1110
+ if (crypto && crypto.getRandomValues && window.Uint8Array) {
1111
+ array = new Uint8Array(len);
1112
+ crypto.getRandomValues(array);
1113
+ return array;
1114
+ }
1115
+
1116
+ // fallback to Math random
1117
+ array = new Array(len);
1118
+ for (var j = 0; j < array.length; j++) {
1119
+ array[j] = Math.floor(256 * Math.random());
1120
+ }
1121
+ return array;
1122
+ }
1123
+
1124
+ function generateCodeVerifier(len) {
1125
+ return generateRandomString(len, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
1126
+ }
1127
+
1128
+ function generateRandomString(len, alphabet){
1129
+ var randomData = generateRandomData(len);
1130
+ var chars = new Array(len);
1131
+ for (var i = 0; i < len; i++) {
1132
+ chars[i] = alphabet.charCodeAt(randomData[i] % alphabet.length);
1133
+ }
1134
+ return String.fromCharCode.apply(null, chars);
1135
+ }
1136
+
1137
+ function generatePkceChallenge(pkceMethod, codeVerifier) {
1138
+ switch (pkceMethod) {
1139
+ // The use of the "plain" method is considered insecure and therefore not supported.
1140
+ case "S256":
1141
+ // hash codeVerifier, then encode as url-safe base64 without padding
1142
+ var hashBytes = new Uint8Array(sha256.arrayBuffer(codeVerifier));
1143
+ var encodedHash = base64Js.fromByteArray(hashBytes)
1144
+ .replace(/\+/g, '-')
1145
+ .replace(/\//g, '_')
1146
+ .replace(/\=/g, '');
1147
+ return encodedHash;
1148
+ default:
1149
+ throw 'Invalid value for pkceMethod';
1150
+ }
1151
+ }
1152
+
1153
+ function buildClaimsParameter(requestedAcr){
1154
+ var claims = {
1155
+ id_token: {
1156
+ acr: requestedAcr
1157
+ }
1158
+ };
1159
+ return JSON.stringify(claims);
1160
+ }
1161
+
1162
+ kc.createLoginUrl = function(options) {
1163
+ var state = createUUID();
1164
+ var nonce = createUUID();
1165
+
1166
+ var redirectUri = adapter.redirectUri(options);
1167
+
1168
+ var callbackState = {
1169
+ state: state,
1170
+ nonce: nonce,
1171
+ redirectUri: encodeURIComponent(redirectUri)
1172
+ };
1173
+
1174
+ if (options && options.prompt) {
1175
+ callbackState.prompt = options.prompt;
1176
+ }
1177
+
1178
+ var baseUrl;
1179
+ if (options && options.action == 'register') {
1180
+ baseUrl = kc.endpoints.register();
1181
+ } else {
1182
+ baseUrl = kc.endpoints.authorize();
1183
+ }
1184
+
1185
+ var scope = options && options.scope || kc.scope;
1186
+ if (!scope) {
1187
+ // if scope is not set, default to "openid"
1188
+ scope = "openid";
1189
+ } else if (scope.indexOf("openid") === -1) {
1190
+ // if openid scope is missing, prefix the given scopes with it
1191
+ scope = "openid " + scope;
1192
+ }
1193
+
1194
+ var url = baseUrl
1195
+ + '?client_id=' + encodeURIComponent(kc.clientId)
1196
+ + '&redirect_uri=' + encodeURIComponent(redirectUri)
1197
+ + '&state=' + encodeURIComponent(state)
1198
+ + '&response_mode=' + encodeURIComponent(kc.responseMode)
1199
+ + '&response_type=' + encodeURIComponent(kc.responseType)
1200
+ + '&scope=' + encodeURIComponent(scope);
1201
+ if (useNonce) {
1202
+ url = url + '&nonce=' + encodeURIComponent(nonce);
1203
+ }
1204
+
1205
+ if (options && options.prompt) {
1206
+ url += '&prompt=' + encodeURIComponent(options.prompt);
1207
+ }
1208
+
1209
+ if (options && options.maxAge) {
1210
+ url += '&max_age=' + encodeURIComponent(options.maxAge);
1211
+ }
1212
+
1213
+ if (options && options.loginHint) {
1214
+ url += '&login_hint=' + encodeURIComponent(options.loginHint);
1215
+ }
1216
+
1217
+ if (options && options.idpHint) {
1218
+ url += '&kc_idp_hint=' + encodeURIComponent(options.idpHint);
1219
+ }
1220
+
1221
+ if (options && options.action && options.action != 'register') {
1222
+ url += '&kc_action=' + encodeURIComponent(options.action);
1223
+ }
1224
+
1225
+ if (options && options.locale) {
1226
+ url += '&ui_locales=' + encodeURIComponent(options.locale);
1227
+ }
1228
+
1229
+ if (options && options.acr) {
1230
+ var claimsParameter = buildClaimsParameter(options.acr);
1231
+ url += '&claims=' + encodeURIComponent(claimsParameter);
1232
+ }
1233
+
1234
+ if ((options && options.acrValues) || kc.acrValues) {
1235
+ url += '&acr_values=' + encodeURIComponent(options.acrValues || kc.acrValues);
1236
+ }
1237
+
1238
+ if (kc.pkceMethod) {
1239
+ var codeVerifier = generateCodeVerifier(96);
1240
+ callbackState.pkceCodeVerifier = codeVerifier;
1241
+ var pkceChallenge = generatePkceChallenge(kc.pkceMethod, codeVerifier);
1242
+ url += '&code_challenge=' + pkceChallenge;
1243
+ url += '&code_challenge_method=' + kc.pkceMethod;
1244
+ }
1245
+
1246
+ callbackStorage.add(callbackState);
1247
+
1248
+ return url;
1249
+ };
1250
+
1251
+ kc.logout = function(options) {
1252
+ return adapter.logout(options);
1253
+ };
1254
+
1255
+ kc.createLogoutUrl = function(options) {
1256
+ var url = kc.endpoints.logout()
1257
+ + '?client_id=' + encodeURIComponent(kc.clientId)
1258
+ + '&post_logout_redirect_uri=' + encodeURIComponent(adapter.redirectUri(options, false));
1259
+
1260
+ if (kc.idToken) {
1261
+ url += '&id_token_hint=' + encodeURIComponent(kc.idToken);
1262
+ }
1263
+
1264
+ return url;
1265
+ };
1266
+
1267
+ kc.register = function (options) {
1268
+ return adapter.register(options);
1269
+ };
1270
+
1271
+ kc.createRegisterUrl = function(options) {
1272
+ if (!options) {
1273
+ options = {};
1274
+ }
1275
+ options.action = 'register';
1276
+ return kc.createLoginUrl(options);
1277
+ };
1278
+
1279
+ kc.createAccountUrl = function(options) {
1280
+ var realm = getRealmUrl();
1281
+ var url = undefined;
1282
+ if (typeof realm !== 'undefined') {
1283
+ url = realm
1284
+ + '/account'
1285
+ + '?referrer=' + encodeURIComponent(kc.clientId)
1286
+ + '&referrer_uri=' + encodeURIComponent(adapter.redirectUri(options));
1287
+ }
1288
+ return url;
1289
+ };
1290
+
1291
+ kc.accountManagement = function() {
1292
+ return adapter.accountManagement();
1293
+ };
1294
+
1295
+ kc.hasRealmRole = function (role) {
1296
+ var access = kc.realmAccess;
1297
+ return !!access && access.roles.indexOf(role) >= 0;
1298
+ };
1299
+
1300
+ kc.hasResourceRole = function(role, resource) {
1301
+ if (!kc.resourceAccess) {
1302
+ return false;
1303
+ }
1304
+
1305
+ var access = kc.resourceAccess[resource || kc.clientId];
1306
+ return !!access && access.roles.indexOf(role) >= 0;
1307
+ };
1308
+
1309
+ kc.loadUserProfile = function() {
1310
+ var url = getRealmUrl() + '/account';
1311
+ var req = new XMLHttpRequest();
1312
+ req.open('GET', url, true);
1313
+ req.setRequestHeader('Accept', 'application/json');
1314
+ req.setRequestHeader('Authorization', 'bearer ' + kc.token);
1315
+
1316
+ var promise = createPromise();
1317
+
1318
+ req.onreadystatechange = function () {
1319
+ if (req.readyState == 4) {
1320
+ if (req.status == 200) {
1321
+ kc.profile = JSON.parse(req.responseText);
1322
+ promise.setSuccess(kc.profile);
1323
+ } else {
1324
+ promise.setError();
1325
+ }
1326
+ }
1327
+ };
1328
+
1329
+ req.send();
1330
+
1331
+ return promise.promise;
1332
+ };
1333
+
1334
+ kc.loadUserInfo = function() {
1335
+ var url = kc.endpoints.userinfo();
1336
+ var req = new XMLHttpRequest();
1337
+ req.open('GET', url, true);
1338
+ req.setRequestHeader('Accept', 'application/json');
1339
+ req.setRequestHeader('Authorization', 'bearer ' + kc.token);
1340
+
1341
+ var promise = createPromise();
1342
+
1343
+ req.onreadystatechange = function () {
1344
+ if (req.readyState == 4) {
1345
+ if (req.status == 200) {
1346
+ kc.userInfo = JSON.parse(req.responseText);
1347
+ promise.setSuccess(kc.userInfo);
1348
+ } else {
1349
+ promise.setError();
1350
+ }
1351
+ }
1352
+ };
1353
+
1354
+ req.send();
1355
+
1356
+ return promise.promise;
1357
+ };
1358
+
1359
+ kc.isTokenExpired = function(minValidity) {
1360
+ if (!kc.tokenParsed || (!kc.refreshToken && kc.flow != 'implicit' )) {
1361
+ throw 'Not authenticated';
1362
+ }
1363
+
1364
+ if (kc.timeSkew == null) {
1365
+ logInfo('[KEYCLOAK] Unable to determine if token is expired as timeskew is not set');
1366
+ return true;
1367
+ }
1368
+
1369
+ var expiresIn = kc.tokenParsed['exp'] - Math.ceil(new Date().getTime() / 1000) + kc.timeSkew;
1370
+ if (minValidity) {
1371
+ if (isNaN(minValidity)) {
1372
+ throw 'Invalid minValidity';
1373
+ }
1374
+ expiresIn -= minValidity;
1375
+ }
1376
+ return expiresIn < 0;
1377
+ };
1378
+
1379
+ kc.updateToken = function(minValidity) {
1380
+ var promise = createPromise();
1381
+
1382
+ if (!kc.refreshToken) {
1383
+ promise.setError();
1384
+ return promise.promise;
1385
+ }
1386
+
1387
+ minValidity = minValidity || 5;
1388
+
1389
+ var exec = function() {
1390
+ var refreshToken = false;
1391
+ if (minValidity == -1) {
1392
+ refreshToken = true;
1393
+ logInfo('[KEYCLOAK] Refreshing token: forced refresh');
1394
+ } else if (!kc.tokenParsed || kc.isTokenExpired(minValidity)) {
1395
+ refreshToken = true;
1396
+ logInfo('[KEYCLOAK] Refreshing token: token expired');
1397
+ }
1398
+
1399
+ if (!refreshToken) {
1400
+ promise.setSuccess(false);
1401
+ } else {
1402
+ var params = 'grant_type=refresh_token&' + 'refresh_token=' + kc.refreshToken;
1403
+ var url = kc.endpoints.token();
1404
+
1405
+ refreshQueue.push(promise);
1406
+
1407
+ if (refreshQueue.length == 1) {
1408
+ var req = new XMLHttpRequest();
1409
+ req.open('POST', url, true);
1410
+ req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
1411
+ req.withCredentials = true;
1412
+
1413
+ params += '&client_id=' + encodeURIComponent(kc.clientId);
1414
+
1415
+ var timeLocal = new Date().getTime();
1416
+
1417
+ req.onreadystatechange = function () {
1418
+ if (req.readyState == 4) {
1419
+ if (req.status == 200) {
1420
+ logInfo('[KEYCLOAK] Token refreshed');
1421
+
1422
+ timeLocal = (timeLocal + new Date().getTime()) / 2;
1423
+
1424
+ var tokenResponse = JSON.parse(req.responseText);
1425
+
1426
+ setToken(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], timeLocal);
1427
+
1428
+ kc.onAuthRefreshSuccess && kc.onAuthRefreshSuccess();
1429
+ for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
1430
+ p.setSuccess(true);
1431
+ }
1432
+ } else {
1433
+ logWarn('[KEYCLOAK] Failed to refresh token');
1434
+
1435
+ if (req.status == 400) {
1436
+ kc.clearToken();
1437
+ }
1438
+
1439
+ kc.onAuthRefreshError && kc.onAuthRefreshError();
1440
+ for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
1441
+ p.setError(true);
1442
+ }
1443
+ }
1444
+ }
1445
+ };
1446
+
1447
+ req.send(params);
1448
+ }
1449
+ }
1450
+ };
1451
+
1452
+ if (loginIframe.enable) {
1453
+ var iframePromise = checkLoginIframe();
1454
+ iframePromise.then(function() {
1455
+ exec();
1456
+ }).catch(function(error) {
1457
+ promise.setError(error);
1458
+ });
1459
+ } else {
1460
+ exec();
1461
+ }
1462
+
1463
+ return promise.promise;
1464
+ };
1465
+
1466
+ kc.clearToken = function() {
1467
+ if (kc.token) {
1468
+ setToken(null, null, null);
1469
+ kc.onAuthLogout && kc.onAuthLogout();
1470
+ if (kc.loginRequired) {
1471
+ kc.login();
1472
+ }
1473
+ }
1474
+ };
1475
+
1476
+ function getRealmUrl() {
1477
+ if (typeof kc.authServerUrl !== 'undefined') {
1478
+ if (kc.authServerUrl.charAt(kc.authServerUrl.length - 1) == '/') {
1479
+ return kc.authServerUrl + 'realms/' + encodeURIComponent(kc.realm);
1480
+ } else {
1481
+ return kc.authServerUrl + '/realms/' + encodeURIComponent(kc.realm);
1482
+ }
1483
+ } else {
1484
+ return undefined;
1485
+ }
1486
+ }
1487
+
1488
+ function getOrigin() {
1489
+ if (!window.location.origin) {
1490
+ return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
1491
+ } else {
1492
+ return window.location.origin;
1493
+ }
1494
+ }
1495
+
1496
+ function processCallback(oauth, promise) {
1497
+ var code = oauth.code;
1498
+ var error = oauth.error;
1499
+ var prompt = oauth.prompt;
1500
+
1501
+ var timeLocal = new Date().getTime();
1502
+
1503
+ if (oauth['kc_action_status']) {
1504
+ kc.onActionUpdate && kc.onActionUpdate(oauth['kc_action_status']);
1505
+ }
1506
+
1507
+ if (error) {
1508
+ if (prompt != 'none') {
1509
+ var errorData = { error: error, error_description: oauth.error_description };
1510
+ kc.onAuthError && kc.onAuthError(errorData);
1511
+ promise && promise.setError(errorData);
1512
+ } else {
1513
+ promise && promise.setSuccess();
1514
+ }
1515
+ return;
1516
+ } else if ((kc.flow != 'standard') && (oauth.access_token || oauth.id_token)) {
1517
+ authSuccess(oauth.access_token, null, oauth.id_token, true);
1518
+ }
1519
+
1520
+ if ((kc.flow != 'implicit') && code) {
1521
+ var params = 'code=' + code + '&grant_type=authorization_code';
1522
+ var url = kc.endpoints.token();
1523
+
1524
+ var req = new XMLHttpRequest();
1525
+ req.open('POST', url, true);
1526
+ req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
1527
+
1528
+ params += '&client_id=' + encodeURIComponent(kc.clientId);
1529
+ params += '&redirect_uri=' + oauth.redirectUri;
1530
+
1531
+ if (oauth.pkceCodeVerifier) {
1532
+ params += '&code_verifier=' + oauth.pkceCodeVerifier;
1533
+ }
1534
+
1535
+ req.withCredentials = true;
1536
+
1537
+ req.onreadystatechange = function() {
1538
+ if (req.readyState == 4) {
1539
+ if (req.status == 200) {
1540
+
1541
+ var tokenResponse = JSON.parse(req.responseText);
1542
+ authSuccess(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], kc.flow === 'standard');
1543
+ scheduleCheckIframe();
1544
+ } else {
1545
+ kc.onAuthError && kc.onAuthError();
1546
+ promise && promise.setError();
1547
+ }
1548
+ }
1549
+ };
1550
+
1551
+ req.send(params);
1552
+ }
1553
+
1554
+ function authSuccess(accessToken, refreshToken, idToken, fulfillPromise) {
1555
+ timeLocal = (timeLocal + new Date().getTime()) / 2;
1556
+
1557
+ setToken(accessToken, refreshToken, idToken, timeLocal);
1558
+
1559
+ if (useNonce && ((kc.tokenParsed && kc.tokenParsed.nonce != oauth.storedNonce) ||
1560
+ (kc.refreshTokenParsed && kc.refreshTokenParsed.nonce != oauth.storedNonce) ||
1561
+ (kc.idTokenParsed && kc.idTokenParsed.nonce != oauth.storedNonce))) {
1562
+
1563
+ logInfo('[KEYCLOAK] Invalid nonce, clearing token');
1564
+ kc.clearToken();
1565
+ promise && promise.setError();
1566
+ } else {
1567
+ if (fulfillPromise) {
1568
+ kc.onAuthSuccess && kc.onAuthSuccess();
1569
+ promise && promise.setSuccess();
1570
+ }
1571
+ }
1572
+ }
1573
+
1574
+ }
1575
+
1576
+ function loadConfig(url) {
1577
+ var promise = createPromise();
1578
+ var configUrl;
1579
+
1580
+ if (!config) {
1581
+ configUrl = 'keycloak.json';
1582
+ } else if (typeof config === 'string') {
1583
+ configUrl = config;
1584
+ }
1585
+
1586
+ function setupOidcEndoints(oidcConfiguration) {
1587
+ if (! oidcConfiguration) {
1588
+ kc.endpoints = {
1589
+ authorize: function() {
1590
+ return getRealmUrl() + '/protocol/openid-connect/auth';
1591
+ },
1592
+ token: function() {
1593
+ return getRealmUrl() + '/protocol/openid-connect/token';
1594
+ },
1595
+ logout: function() {
1596
+ return getRealmUrl() + '/protocol/openid-connect/logout';
1597
+ },
1598
+ checkSessionIframe: function() {
1599
+ var src = getRealmUrl() + '/protocol/openid-connect/login-status-iframe.html';
1600
+ if (kc.iframeVersion) {
1601
+ src = src + '?version=' + kc.iframeVersion;
1602
+ }
1603
+ return src;
1604
+ },
1605
+ thirdPartyCookiesIframe: function() {
1606
+ var src = getRealmUrl() + '/protocol/openid-connect/3p-cookies/step1.html';
1607
+ if (kc.iframeVersion) {
1608
+ src = src + '?version=' + kc.iframeVersion;
1609
+ }
1610
+ return src;
1611
+ },
1612
+ register: function() {
1613
+ return getRealmUrl() + '/protocol/openid-connect/registrations';
1614
+ },
1615
+ userinfo: function() {
1616
+ return getRealmUrl() + '/protocol/openid-connect/userinfo';
1617
+ }
1618
+ };
1619
+ } else {
1620
+ kc.endpoints = {
1621
+ authorize: function() {
1622
+ return oidcConfiguration.authorization_endpoint;
1623
+ },
1624
+ token: function() {
1625
+ return oidcConfiguration.token_endpoint;
1626
+ },
1627
+ logout: function() {
1628
+ if (!oidcConfiguration.end_session_endpoint) {
1629
+ throw "Not supported by the OIDC server";
1630
+ }
1631
+ return oidcConfiguration.end_session_endpoint;
1632
+ },
1633
+ checkSessionIframe: function() {
1634
+ if (!oidcConfiguration.check_session_iframe) {
1635
+ throw "Not supported by the OIDC server";
1636
+ }
1637
+ return oidcConfiguration.check_session_iframe;
1638
+ },
1639
+ register: function() {
1640
+ throw 'Redirection to "Register user" page not supported in standard OIDC mode';
1641
+ },
1642
+ userinfo: function() {
1643
+ if (!oidcConfiguration.userinfo_endpoint) {
1644
+ throw "Not supported by the OIDC server";
1645
+ }
1646
+ return oidcConfiguration.userinfo_endpoint;
1647
+ }
1648
+ };
1649
+ }
1650
+ }
1651
+
1652
+ if (configUrl) {
1653
+ var req = new XMLHttpRequest();
1654
+ req.open('GET', configUrl, true);
1655
+ req.setRequestHeader('Accept', 'application/json');
1656
+
1657
+ req.onreadystatechange = function () {
1658
+ if (req.readyState == 4) {
1659
+ if (req.status == 200 || fileLoaded(req)) {
1660
+ var config = JSON.parse(req.responseText);
1661
+
1662
+ kc.authServerUrl = config['auth-server-url'];
1663
+ kc.realm = config['realm'];
1664
+ kc.clientId = config['resource'];
1665
+ setupOidcEndoints(null);
1666
+ promise.setSuccess();
1667
+ } else {
1668
+ promise.setError();
1669
+ }
1670
+ }
1671
+ };
1672
+
1673
+ req.send();
1674
+ } else {
1675
+ if (!config.clientId) {
1676
+ throw 'clientId missing';
1677
+ }
1678
+
1679
+ kc.clientId = config.clientId;
1680
+
1681
+ var oidcProvider = config['oidcProvider'];
1682
+ if (!oidcProvider) {
1683
+ if (!config['url']) {
1684
+ var scripts = document.getElementsByTagName('script');
1685
+ for (var i = 0; i < scripts.length; i++) {
1686
+ if (scripts[i].src.match(/.*keycloak\.js/)) {
1687
+ config.url = scripts[i].src.substr(0, scripts[i].src.indexOf('/js/keycloak.js'));
1688
+ break;
1689
+ }
1690
+ }
1691
+ }
1692
+ if (!config.realm) {
1693
+ throw 'realm missing';
1694
+ }
1695
+
1696
+ kc.authServerUrl = config.url;
1697
+ kc.realm = config.realm;
1698
+ setupOidcEndoints(null);
1699
+ promise.setSuccess();
1700
+ } else {
1701
+ if (typeof oidcProvider === 'string') {
1702
+ var oidcProviderConfigUrl;
1703
+ if (oidcProvider.charAt(oidcProvider.length - 1) == '/') {
1704
+ oidcProviderConfigUrl = oidcProvider + '.well-known/openid-configuration';
1705
+ } else {
1706
+ oidcProviderConfigUrl = oidcProvider + '/.well-known/openid-configuration';
1707
+ }
1708
+ var req = new XMLHttpRequest();
1709
+ req.open('GET', oidcProviderConfigUrl, true);
1710
+ req.setRequestHeader('Accept', 'application/json');
1711
+
1712
+ req.onreadystatechange = function () {
1713
+ if (req.readyState == 4) {
1714
+ if (req.status == 200 || fileLoaded(req)) {
1715
+ var oidcProviderConfig = JSON.parse(req.responseText);
1716
+ setupOidcEndoints(oidcProviderConfig);
1717
+ promise.setSuccess();
1718
+ } else {
1719
+ promise.setError();
1720
+ }
1721
+ }
1722
+ };
1723
+
1724
+ req.send();
1725
+ } else {
1726
+ setupOidcEndoints(oidcProvider);
1727
+ promise.setSuccess();
1728
+ }
1729
+ }
1730
+ }
1731
+
1732
+ return promise.promise;
1733
+ }
1734
+
1735
+ function fileLoaded(xhr) {
1736
+ return xhr.status == 0 && xhr.responseText && xhr.responseURL.startsWith('file:');
1737
+ }
1738
+
1739
+ function setToken(token, refreshToken, idToken, timeLocal) {
1740
+ if (kc.tokenTimeoutHandle) {
1741
+ clearTimeout(kc.tokenTimeoutHandle);
1742
+ kc.tokenTimeoutHandle = null;
1743
+ }
1744
+
1745
+ if (refreshToken) {
1746
+ kc.refreshToken = refreshToken;
1747
+ kc.refreshTokenParsed = jwtDecode(refreshToken);
1748
+ } else {
1749
+ delete kc.refreshToken;
1750
+ delete kc.refreshTokenParsed;
1751
+ }
1752
+
1753
+ if (idToken) {
1754
+ kc.idToken = idToken;
1755
+ kc.idTokenParsed = jwtDecode(idToken);
1756
+ } else {
1757
+ delete kc.idToken;
1758
+ delete kc.idTokenParsed;
1759
+ }
1760
+
1761
+ if (token) {
1762
+ kc.token = token;
1763
+ kc.tokenParsed = jwtDecode(token);
1764
+ kc.sessionId = kc.tokenParsed.session_state;
1765
+ kc.authenticated = true;
1766
+ kc.subject = kc.tokenParsed.sub;
1767
+ kc.realmAccess = kc.tokenParsed.realm_access;
1768
+ kc.resourceAccess = kc.tokenParsed.resource_access;
1769
+
1770
+ if (timeLocal) {
1771
+ kc.timeSkew = Math.floor(timeLocal / 1000) - kc.tokenParsed.iat;
1772
+ }
1773
+
1774
+ if (kc.timeSkew != null) {
1775
+ logInfo('[KEYCLOAK] Estimated time difference between browser and server is ' + kc.timeSkew + ' seconds');
1776
+
1777
+ if (kc.onTokenExpired) {
1778
+ var expiresIn = (kc.tokenParsed['exp'] - (new Date().getTime() / 1000) + kc.timeSkew) * 1000;
1779
+ logInfo('[KEYCLOAK] Token expires in ' + Math.round(expiresIn / 1000) + ' s');
1780
+ if (expiresIn <= 0) {
1781
+ kc.onTokenExpired();
1782
+ } else {
1783
+ kc.tokenTimeoutHandle = setTimeout(kc.onTokenExpired, expiresIn);
1784
+ }
1785
+ }
1786
+ }
1787
+ } else {
1788
+ delete kc.token;
1789
+ delete kc.tokenParsed;
1790
+ delete kc.subject;
1791
+ delete kc.realmAccess;
1792
+ delete kc.resourceAccess;
1793
+
1794
+ kc.authenticated = false;
1795
+ }
1796
+ }
1797
+
1798
+ function createUUID() {
1799
+ var hexDigits = '0123456789abcdef';
1800
+ var s = generateRandomString(36, hexDigits).split("");
1801
+ s[14] = '4';
1802
+ s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
1803
+ s[8] = s[13] = s[18] = s[23] = '-';
1804
+ var uuid = s.join('');
1805
+ return uuid;
1806
+ }
1807
+
1808
+ function parseCallback(url) {
1809
+ var oauth = parseCallbackUrl(url);
1810
+ if (!oauth) {
1811
+ return;
1812
+ }
1813
+
1814
+ var oauthState = callbackStorage.get(oauth.state);
1815
+
1816
+ if (oauthState) {
1817
+ oauth.valid = true;
1818
+ oauth.redirectUri = oauthState.redirectUri;
1819
+ oauth.storedNonce = oauthState.nonce;
1820
+ oauth.prompt = oauthState.prompt;
1821
+ oauth.pkceCodeVerifier = oauthState.pkceCodeVerifier;
1822
+ }
1823
+
1824
+ return oauth;
1825
+ }
1826
+
1827
+ function parseCallbackUrl(url) {
1828
+ var supportedParams;
1829
+ switch (kc.flow) {
1830
+ case 'standard':
1831
+ supportedParams = ['code', 'state', 'session_state', 'kc_action_status', 'iss'];
1832
+ break;
1833
+ case 'implicit':
1834
+ supportedParams = ['access_token', 'token_type', 'id_token', 'state', 'session_state', 'expires_in', 'kc_action_status', 'iss'];
1835
+ break;
1836
+ case 'hybrid':
1837
+ supportedParams = ['access_token', 'token_type', 'id_token', 'code', 'state', 'session_state', 'expires_in', 'kc_action_status', 'iss'];
1838
+ break;
1839
+ }
1840
+
1841
+ supportedParams.push('error');
1842
+ supportedParams.push('error_description');
1843
+ supportedParams.push('error_uri');
1844
+
1845
+ var queryIndex = url.indexOf('?');
1846
+ var fragmentIndex = url.indexOf('#');
1847
+
1848
+ var newUrl;
1849
+ var parsed;
1850
+
1851
+ if (kc.responseMode === 'query' && queryIndex !== -1) {
1852
+ newUrl = url.substring(0, queryIndex);
1853
+ parsed = parseCallbackParams(url.substring(queryIndex + 1, fragmentIndex !== -1 ? fragmentIndex : url.length), supportedParams);
1854
+ if (parsed.paramsString !== '') {
1855
+ newUrl += '?' + parsed.paramsString;
1856
+ }
1857
+ if (fragmentIndex !== -1) {
1858
+ newUrl += url.substring(fragmentIndex);
1859
+ }
1860
+ } else if (kc.responseMode === 'fragment' && fragmentIndex !== -1) {
1861
+ newUrl = url.substring(0, fragmentIndex);
1862
+ parsed = parseCallbackParams(url.substring(fragmentIndex + 1), supportedParams);
1863
+ if (parsed.paramsString !== '') {
1864
+ newUrl += '#' + parsed.paramsString;
1865
+ }
1866
+ }
1867
+
1868
+ if (parsed && parsed.oauthParams) {
1869
+ if (kc.flow === 'standard' || kc.flow === 'hybrid') {
1870
+ if ((parsed.oauthParams.code || parsed.oauthParams.error) && parsed.oauthParams.state) {
1871
+ parsed.oauthParams.newUrl = newUrl;
1872
+ return parsed.oauthParams;
1873
+ }
1874
+ } else if (kc.flow === 'implicit') {
1875
+ if ((parsed.oauthParams.access_token || parsed.oauthParams.error) && parsed.oauthParams.state) {
1876
+ parsed.oauthParams.newUrl = newUrl;
1877
+ return parsed.oauthParams;
1878
+ }
1879
+ }
1880
+ }
1881
+ }
1882
+
1883
+ function parseCallbackParams(paramsString, supportedParams) {
1884
+ var p = paramsString.split('&');
1885
+ var result = {
1886
+ paramsString: '',
1887
+ oauthParams: {}
1888
+ };
1889
+ for (var i = 0; i < p.length; i++) {
1890
+ var split = p[i].indexOf("=");
1891
+ var key = p[i].slice(0, split);
1892
+ if (supportedParams.indexOf(key) !== -1) {
1893
+ result.oauthParams[key] = p[i].slice(split + 1);
1894
+ } else {
1895
+ if (result.paramsString !== '') {
1896
+ result.paramsString += '&';
1897
+ }
1898
+ result.paramsString += p[i];
1899
+ }
1900
+ }
1901
+ return result;
1902
+ }
1903
+
1904
+ function createPromise() {
1905
+ // Need to create a native Promise which also preserves the
1906
+ // interface of the custom promise type previously used by the API
1907
+ var p = {
1908
+ setSuccess: function(result) {
1909
+ p.resolve(result);
1910
+ },
1911
+
1912
+ setError: function(result) {
1913
+ p.reject(result);
1914
+ }
1915
+ };
1916
+ p.promise = new Promise(function(resolve, reject) {
1917
+ p.resolve = resolve;
1918
+ p.reject = reject;
1919
+ });
1920
+
1921
+ return p;
1922
+ }
1923
+
1924
+ // Function to extend existing native Promise with timeout
1925
+ function applyTimeoutToPromise(promise, timeout, errorMessage) {
1926
+ var timeoutHandle = null;
1927
+ var timeoutPromise = new Promise(function (resolve, reject) {
1928
+ timeoutHandle = setTimeout(function () {
1929
+ reject({ "error": errorMessage || "Promise is not settled within timeout of " + timeout + "ms" });
1930
+ }, timeout);
1931
+ });
1932
+
1933
+ return Promise.race([promise, timeoutPromise]).finally(function () {
1934
+ clearTimeout(timeoutHandle);
1935
+ });
1936
+ }
1937
+
1938
+ function setupCheckLoginIframe() {
1939
+ var promise = createPromise();
1940
+
1941
+ if (!loginIframe.enable) {
1942
+ promise.setSuccess();
1943
+ return promise.promise;
1944
+ }
1945
+
1946
+ if (loginIframe.iframe) {
1947
+ promise.setSuccess();
1948
+ return promise.promise;
1949
+ }
1950
+
1951
+ var iframe = document.createElement('iframe');
1952
+ loginIframe.iframe = iframe;
1953
+
1954
+ iframe.onload = function() {
1955
+ var authUrl = kc.endpoints.authorize();
1956
+ if (authUrl.charAt(0) === '/') {
1957
+ loginIframe.iframeOrigin = getOrigin();
1958
+ } else {
1959
+ loginIframe.iframeOrigin = authUrl.substring(0, authUrl.indexOf('/', 8));
1960
+ }
1961
+ promise.setSuccess();
1962
+ };
1963
+
1964
+ var src = kc.endpoints.checkSessionIframe();
1965
+ iframe.setAttribute('src', src );
1966
+ iframe.setAttribute('sandbox', 'allow-storage-access-by-user-activation allow-scripts allow-same-origin');
1967
+ iframe.setAttribute('title', 'keycloak-session-iframe' );
1968
+ iframe.style.display = 'none';
1969
+ document.body.appendChild(iframe);
1970
+
1971
+ var messageCallback = function(event) {
1972
+ if ((event.origin !== loginIframe.iframeOrigin) || (loginIframe.iframe.contentWindow !== event.source)) {
1973
+ return;
1974
+ }
1975
+
1976
+ if (!(event.data == 'unchanged' || event.data == 'changed' || event.data == 'error')) {
1977
+ return;
1978
+ }
1979
+
1980
+
1981
+ if (event.data != 'unchanged') {
1982
+ kc.clearToken();
1983
+ }
1984
+
1985
+ var callbacks = loginIframe.callbackList.splice(0, loginIframe.callbackList.length);
1986
+
1987
+ for (var i = callbacks.length - 1; i >= 0; --i) {
1988
+ var promise = callbacks[i];
1989
+ if (event.data == 'error') {
1990
+ promise.setError();
1991
+ } else {
1992
+ promise.setSuccess(event.data == 'unchanged');
1993
+ }
1994
+ }
1995
+ };
1996
+
1997
+ window.addEventListener('message', messageCallback, false);
1998
+
1999
+ return promise.promise;
2000
+ }
2001
+
2002
+ function scheduleCheckIframe() {
2003
+ if (loginIframe.enable) {
2004
+ if (kc.token) {
2005
+ setTimeout(function() {
2006
+ checkLoginIframe().then(function(unchanged) {
2007
+ if (unchanged) {
2008
+ scheduleCheckIframe();
2009
+ }
2010
+ });
2011
+ }, loginIframe.interval * 1000);
2012
+ }
2013
+ }
2014
+ }
2015
+
2016
+ function checkLoginIframe() {
2017
+ var promise = createPromise();
2018
+
2019
+ if (loginIframe.iframe && loginIframe.iframeOrigin ) {
2020
+ var msg = kc.clientId + ' ' + (kc.sessionId ? kc.sessionId : '');
2021
+ loginIframe.callbackList.push(promise);
2022
+ var origin = loginIframe.iframeOrigin;
2023
+ if (loginIframe.callbackList.length == 1) {
2024
+ loginIframe.iframe.contentWindow.postMessage(msg, origin);
2025
+ }
2026
+ } else {
2027
+ promise.setSuccess();
2028
+ }
2029
+
2030
+ return promise.promise;
2031
+ }
2032
+
2033
+ function check3pCookiesSupported() {
2034
+ var promise = createPromise();
2035
+
2036
+ if (loginIframe.enable || kc.silentCheckSsoRedirectUri) {
2037
+ var iframe = document.createElement('iframe');
2038
+ iframe.setAttribute('src', kc.endpoints.thirdPartyCookiesIframe());
2039
+ iframe.setAttribute('sandbox', 'allow-storage-access-by-user-activation allow-scripts allow-same-origin');
2040
+ iframe.setAttribute('title', 'keycloak-3p-check-iframe' );
2041
+ iframe.style.display = 'none';
2042
+ document.body.appendChild(iframe);
2043
+
2044
+ var messageCallback = function(event) {
2045
+ if (iframe.contentWindow !== event.source) {
2046
+ return;
2047
+ }
2048
+
2049
+ if (event.data !== "supported" && event.data !== "unsupported") {
2050
+ return;
2051
+ } else if (event.data === "unsupported") {
2052
+ logWarn(
2053
+ "[KEYCLOAK] Your browser is blocking access to 3rd-party cookies, this means:\n\n" +
2054
+ " - It is not possible to retrieve tokens without redirecting to the Keycloak server (a.k.a. no support for silent authentication).\n" +
2055
+ " - It is not possible to automatically detect changes to the session status (such as the user logging out in another tab).\n\n" +
2056
+ "For more information see: https://www.keycloak.org/docs/latest/securing_apps/#_modern_browsers"
2057
+ );
2058
+
2059
+ loginIframe.enable = false;
2060
+ if (kc.silentCheckSsoFallback) {
2061
+ kc.silentCheckSsoRedirectUri = false;
2062
+ }
2063
+ }
2064
+
2065
+ document.body.removeChild(iframe);
2066
+ window.removeEventListener("message", messageCallback);
2067
+ promise.setSuccess();
2068
+ };
2069
+
2070
+ window.addEventListener('message', messageCallback, false);
2071
+ } else {
2072
+ promise.setSuccess();
2073
+ }
2074
+
2075
+ return applyTimeoutToPromise(promise.promise, kc.messageReceiveTimeout, "Timeout when waiting for 3rd party check iframe message.");
2076
+ }
2077
+
2078
+ function loadAdapter(type) {
2079
+ if (!type || type == 'default') {
2080
+ return {
2081
+ login: function(options) {
2082
+ window.location.assign(kc.createLoginUrl(options));
2083
+ return createPromise().promise;
2084
+ },
2085
+
2086
+ logout: function(options) {
2087
+ window.location.replace(kc.createLogoutUrl(options));
2088
+ return createPromise().promise;
2089
+ },
2090
+
2091
+ register: function(options) {
2092
+ window.location.assign(kc.createRegisterUrl(options));
2093
+ return createPromise().promise;
2094
+ },
2095
+
2096
+ accountManagement : function() {
2097
+ var accountUrl = kc.createAccountUrl();
2098
+ if (typeof accountUrl !== 'undefined') {
2099
+ window.location.href = accountUrl;
2100
+ } else {
2101
+ throw "Not supported by the OIDC server";
2102
+ }
2103
+ return createPromise().promise;
2104
+ },
2105
+
2106
+ redirectUri: function(options, encodeHash) {
2107
+
2108
+ if (options && options.redirectUri) {
2109
+ return options.redirectUri;
2110
+ } else if (kc.redirectUri) {
2111
+ return kc.redirectUri;
2112
+ } else {
2113
+ return location.href;
2114
+ }
2115
+ }
2116
+ };
2117
+ }
2118
+
2119
+ if (type == 'cordova') {
2120
+ loginIframe.enable = false;
2121
+ var cordovaOpenWindowWrapper = function(loginUrl, target, options) {
2122
+ if (window.cordova && window.cordova.InAppBrowser) {
2123
+ // Use inappbrowser for IOS and Android if available
2124
+ return window.cordova.InAppBrowser.open(loginUrl, target, options);
2125
+ } else {
2126
+ return window.open(loginUrl, target, options);
2127
+ }
2128
+ };
2129
+
2130
+ var shallowCloneCordovaOptions = function (userOptions) {
2131
+ if (userOptions && userOptions.cordovaOptions) {
2132
+ return Object.keys(userOptions.cordovaOptions).reduce(function (options, optionName) {
2133
+ options[optionName] = userOptions.cordovaOptions[optionName];
2134
+ return options;
2135
+ }, {});
2136
+ } else {
2137
+ return {};
2138
+ }
2139
+ };
2140
+
2141
+ var formatCordovaOptions = function (cordovaOptions) {
2142
+ return Object.keys(cordovaOptions).reduce(function (options, optionName) {
2143
+ options.push(optionName+"="+cordovaOptions[optionName]);
2144
+ return options;
2145
+ }, []).join(",");
2146
+ };
2147
+
2148
+ var createCordovaOptions = function (userOptions) {
2149
+ var cordovaOptions = shallowCloneCordovaOptions(userOptions);
2150
+ cordovaOptions.location = 'no';
2151
+ if (userOptions && userOptions.prompt == 'none') {
2152
+ cordovaOptions.hidden = 'yes';
2153
+ }
2154
+ return formatCordovaOptions(cordovaOptions);
2155
+ };
2156
+
2157
+ var getCordovaRedirectUri = function() {
2158
+ return kc.redirectUri || 'http://localhost';
2159
+ };
2160
+
2161
+ return {
2162
+ login: function(options) {
2163
+ var promise = createPromise();
2164
+
2165
+ var cordovaOptions = createCordovaOptions(options);
2166
+ var loginUrl = kc.createLoginUrl(options);
2167
+ var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions);
2168
+ var completed = false;
2169
+
2170
+ var closed = false;
2171
+ var closeBrowser = function() {
2172
+ closed = true;
2173
+ ref.close();
2174
+ };
2175
+
2176
+ ref.addEventListener('loadstart', function(event) {
2177
+ if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
2178
+ var callback = parseCallback(event.url);
2179
+ processCallback(callback, promise);
2180
+ closeBrowser();
2181
+ completed = true;
2182
+ }
2183
+ });
2184
+
2185
+ ref.addEventListener('loaderror', function(event) {
2186
+ if (!completed) {
2187
+ if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
2188
+ var callback = parseCallback(event.url);
2189
+ processCallback(callback, promise);
2190
+ closeBrowser();
2191
+ completed = true;
2192
+ } else {
2193
+ promise.setError();
2194
+ closeBrowser();
2195
+ }
2196
+ }
2197
+ });
2198
+
2199
+ ref.addEventListener('exit', function(event) {
2200
+ if (!closed) {
2201
+ promise.setError({
2202
+ reason: "closed_by_user"
2203
+ });
2204
+ }
2205
+ });
2206
+
2207
+ return promise.promise;
2208
+ },
2209
+
2210
+ logout: function(options) {
2211
+ var promise = createPromise();
2212
+
2213
+ var logoutUrl = kc.createLogoutUrl(options);
2214
+ var ref = cordovaOpenWindowWrapper(logoutUrl, '_blank', 'location=no,hidden=yes,clearcache=yes');
2215
+
2216
+ var error;
2217
+
2218
+ ref.addEventListener('loadstart', function(event) {
2219
+ if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
2220
+ ref.close();
2221
+ }
2222
+ });
2223
+
2224
+ ref.addEventListener('loaderror', function(event) {
2225
+ if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
2226
+ ref.close();
2227
+ } else {
2228
+ error = true;
2229
+ ref.close();
2230
+ }
2231
+ });
2232
+
2233
+ ref.addEventListener('exit', function(event) {
2234
+ if (error) {
2235
+ promise.setError();
2236
+ } else {
2237
+ kc.clearToken();
2238
+ promise.setSuccess();
2239
+ }
2240
+ });
2241
+
2242
+ return promise.promise;
2243
+ },
2244
+
2245
+ register : function(options) {
2246
+ var promise = createPromise();
2247
+ var registerUrl = kc.createRegisterUrl();
2248
+ var cordovaOptions = createCordovaOptions(options);
2249
+ var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', cordovaOptions);
2250
+ ref.addEventListener('loadstart', function(event) {
2251
+ if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
2252
+ ref.close();
2253
+ var oauth = parseCallback(event.url);
2254
+ processCallback(oauth, promise);
2255
+ }
2256
+ });
2257
+ return promise.promise;
2258
+ },
2259
+
2260
+ accountManagement : function() {
2261
+ var accountUrl = kc.createAccountUrl();
2262
+ if (typeof accountUrl !== 'undefined') {
2263
+ var ref = cordovaOpenWindowWrapper(accountUrl, '_blank', 'location=no');
2264
+ ref.addEventListener('loadstart', function(event) {
2265
+ if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
2266
+ ref.close();
2267
+ }
2268
+ });
2269
+ } else {
2270
+ throw "Not supported by the OIDC server";
2271
+ }
2272
+ },
2273
+
2274
+ redirectUri: function(options) {
2275
+ return getCordovaRedirectUri();
2276
+ }
2277
+ }
2278
+ }
2279
+
2280
+ if (type == 'cordova-native') {
2281
+ loginIframe.enable = false;
2282
+
2283
+ return {
2284
+ login: function(options) {
2285
+ var promise = createPromise();
2286
+ var loginUrl = kc.createLoginUrl(options);
2287
+
2288
+ universalLinks.subscribe('keycloak', function(event) {
2289
+ universalLinks.unsubscribe('keycloak');
2290
+ window.cordova.plugins.browsertab.close();
2291
+ var oauth = parseCallback(event.url);
2292
+ processCallback(oauth, promise);
2293
+ });
2294
+
2295
+ window.cordova.plugins.browsertab.openUrl(loginUrl);
2296
+ return promise.promise;
2297
+ },
2298
+
2299
+ logout: function(options) {
2300
+ var promise = createPromise();
2301
+ var logoutUrl = kc.createLogoutUrl(options);
2302
+
2303
+ universalLinks.subscribe('keycloak', function(event) {
2304
+ universalLinks.unsubscribe('keycloak');
2305
+ window.cordova.plugins.browsertab.close();
2306
+ kc.clearToken();
2307
+ promise.setSuccess();
2308
+ });
2309
+
2310
+ window.cordova.plugins.browsertab.openUrl(logoutUrl);
2311
+ return promise.promise;
2312
+ },
2313
+
2314
+ register : function(options) {
2315
+ var promise = createPromise();
2316
+ var registerUrl = kc.createRegisterUrl(options);
2317
+ universalLinks.subscribe('keycloak' , function(event) {
2318
+ universalLinks.unsubscribe('keycloak');
2319
+ window.cordova.plugins.browsertab.close();
2320
+ var oauth = parseCallback(event.url);
2321
+ processCallback(oauth, promise);
2322
+ });
2323
+ window.cordova.plugins.browsertab.openUrl(registerUrl);
2324
+ return promise.promise;
2325
+
2326
+ },
2327
+
2328
+ accountManagement : function() {
2329
+ var accountUrl = kc.createAccountUrl();
2330
+ if (typeof accountUrl !== 'undefined') {
2331
+ window.cordova.plugins.browsertab.openUrl(accountUrl);
2332
+ } else {
2333
+ throw "Not supported by the OIDC server";
2334
+ }
2335
+ },
2336
+
2337
+ redirectUri: function(options) {
2338
+ if (options && options.redirectUri) {
2339
+ return options.redirectUri;
2340
+ } else if (kc.redirectUri) {
2341
+ return kc.redirectUri;
2342
+ } else {
2343
+ return "http://localhost";
2344
+ }
2345
+ }
2346
+ }
2347
+ }
2348
+
2349
+ throw 'invalid adapter type: ' + type;
2350
+ }
2351
+
2352
+ var LocalStorage = function() {
2353
+ if (!(this instanceof LocalStorage)) {
2354
+ return new LocalStorage();
2355
+ }
2356
+
2357
+ localStorage.setItem('kc-test', 'test');
2358
+ localStorage.removeItem('kc-test');
2359
+
2360
+ var cs = this;
2361
+
2362
+ function clearExpired() {
2363
+ var time = new Date().getTime();
2364
+ for (var i = 0; i < localStorage.length; i++) {
2365
+ var key = localStorage.key(i);
2366
+ if (key && key.indexOf('kc-callback-') == 0) {
2367
+ var value = localStorage.getItem(key);
2368
+ if (value) {
2369
+ try {
2370
+ var expires = JSON.parse(value).expires;
2371
+ if (!expires || expires < time) {
2372
+ localStorage.removeItem(key);
2373
+ }
2374
+ } catch (err) {
2375
+ localStorage.removeItem(key);
2376
+ }
2377
+ }
2378
+ }
2379
+ }
2380
+ }
2381
+
2382
+ cs.get = function(state) {
2383
+ if (!state) {
2384
+ return;
2385
+ }
2386
+
2387
+ var key = 'kc-callback-' + state;
2388
+ var value = localStorage.getItem(key);
2389
+ if (value) {
2390
+ localStorage.removeItem(key);
2391
+ value = JSON.parse(value);
2392
+ }
2393
+
2394
+ clearExpired();
2395
+ return value;
2396
+ };
2397
+
2398
+ cs.add = function(state) {
2399
+ clearExpired();
2400
+
2401
+ var key = 'kc-callback-' + state.state;
2402
+ state.expires = new Date().getTime() + (60 * 60 * 1000);
2403
+ localStorage.setItem(key, JSON.stringify(state));
2404
+ };
2405
+ };
2406
+
2407
+ var CookieStorage = function() {
2408
+ if (!(this instanceof CookieStorage)) {
2409
+ return new CookieStorage();
2410
+ }
2411
+
2412
+ var cs = this;
2413
+
2414
+ cs.get = function(state) {
2415
+ if (!state) {
2416
+ return;
2417
+ }
2418
+
2419
+ var value = getCookie('kc-callback-' + state);
2420
+ setCookie('kc-callback-' + state, '', cookieExpiration(-100));
2421
+ if (value) {
2422
+ return JSON.parse(value);
2423
+ }
2424
+ };
2425
+
2426
+ cs.add = function(state) {
2427
+ setCookie('kc-callback-' + state.state, JSON.stringify(state), cookieExpiration(60));
2428
+ };
2429
+
2430
+ cs.removeItem = function(key) {
2431
+ setCookie(key, '', cookieExpiration(-100));
2432
+ };
2433
+
2434
+ var cookieExpiration = function (minutes) {
2435
+ var exp = new Date();
2436
+ exp.setTime(exp.getTime() + (minutes*60*1000));
2437
+ return exp;
2438
+ };
2439
+
2440
+ var getCookie = function (key) {
2441
+ var name = key + '=';
2442
+ var ca = document.cookie.split(';');
2443
+ for (var i = 0; i < ca.length; i++) {
2444
+ var c = ca[i];
2445
+ while (c.charAt(0) == ' ') {
2446
+ c = c.substring(1);
2447
+ }
2448
+ if (c.indexOf(name) == 0) {
2449
+ return c.substring(name.length, c.length);
2450
+ }
2451
+ }
2452
+ return '';
2453
+ };
2454
+
2455
+ var setCookie = function (key, value, expirationDate) {
2456
+ var cookie = key + '=' + value + '; '
2457
+ + 'expires=' + expirationDate.toUTCString() + '; ';
2458
+ document.cookie = cookie;
2459
+ };
2460
+ };
2461
+
2462
+ function createCallbackStorage() {
2463
+ try {
2464
+ return new LocalStorage();
2465
+ } catch (err) {
2466
+ }
2467
+
2468
+ return new CookieStorage();
2469
+ }
2470
+
2471
+ function createLogger(fn) {
2472
+ return function() {
2473
+ if (kc.enableLogging) {
2474
+ fn.apply(console, Array.prototype.slice.call(arguments));
2475
+ }
2476
+ };
2477
+ }
2478
+ }
2479
+
2480
+ const dashButtonCss = ".button{display:flex;height:50px;padding:0;background:#3e7671;border:none;outline:none;border-radius:5px;overflow:hidden;font-size:16px;font-weight:500;cursor:pointer;min-width:220px;max-width:220px}.button:hover{background:#008168}.button:active{background:#3e7671}.button-text{display:block;margin:auto;padding:0 24px;color:#fff;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;width:80px}.button-icon{margin:auto;padding:10px}.button-profile{display:inline-flex;align-items:center;color:#fff}.button-profile img{height:50px}.button-text-full-width{width:auto!important}.button-link{text-decoration:none!important}.gg-menu-grid-r{color:#fff;box-sizing:border-box;position:relative;display:block;transform:scale(var(--ggs,1));width:16px;height:16px}.gg-menu-grid-r::before{content:\"\";display:block;box-sizing:border-box;position:absolute;width:4px;height:4px;background:currentColor;box-shadow:0 6px 0,\n 6px 6px 0,\n 12px 6px 0,\n 6px 12px 0,\n 12px 12px 0,\n 6px 0 0,\n 12px 0 0,\n 0 12px 0}.dropdown{position:relative;display:inline-block}.dropdown-content{display:none;position:absolute;right:0;background-color:#f9f9f9;min-width:180px;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);z-index:1;border-radius:5px}.dropdown-content a{color:#71797E;padding:16px 20px;text-decoration:none;display:block;cursor:pointer}.dropdown-content a:hover{background-color:#f1f1f1;color:#000;opacity:0.7}.dropdown:hover .dropdown-content{display:block}.modal{display:none;position:fixed;z-index:1;padding-top:100px;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgb(0,0,0);background-color:rgba(0,0,0,0.4);text-align:center}.modal-content{background-color:#fefefe;margin:auto;padding:20px;border:1px solid #888;width:40%}.close{color:#aaaaaa;float:right;font-size:28px;font-weight:bold}.close:hover,.close:focus{color:#000;text-decoration:none;cursor:pointer}.modal-app{background-color:#c3e9bc;padding:15px;margin:10px;border-radius:5px}";
2481
+ const DashButtonStyle0 = dashButtonCss;
2482
+
2483
+ const DashButtonComponent = class {
2484
+ constructor(hostRef) {
2485
+ index.registerInstance(this, hostRef);
2486
+ this.showPostLoginText = false;
2487
+ this.silentCheckSso = false;
2488
+ this.redirectUri = undefined;
2489
+ this.keycloakUri = "http://localhost:8080";
2490
+ this.realm = "";
2491
+ this.clientId = "";
2492
+ this.keycloak = new Keycloak({
2493
+ url: this.keycloakUri,
2494
+ realm: this.realm,
2495
+ clientId: this.clientId,
2496
+ });
2497
+ this.isAuth = false;
2498
+ this.givenName = "";
2499
+ this.silentCheckSsoRedirectUri = window.location.origin + '/assets/verificar-sso.html';
2500
+ }
2501
+ ;
2502
+ connectedCallback() {
2503
+ this.keycloak.init({
2504
+ onLoad: 'check-sso',
2505
+ checkLoginIframe: false,
2506
+ silentCheckSsoRedirectUri: this.silentCheckSso ? this.silentCheckSsoRedirectUri : '',
2507
+ }).then(res => {
2508
+ if (res) {
2509
+ this.isAuth = true;
2510
+ localStorage.setItem("keycloak", JSON.stringify(this.keycloak));
2511
+ this.givenName = JSON.parse(localStorage.getItem('keycloak')).idTokenParsed.given_name;
2512
+ }
2513
+ });
2514
+ }
2515
+ login() {
2516
+ this.keycloak.login();
2517
+ }
2518
+ logout() {
2519
+ localStorage.removeItem("keycloak");
2520
+ this.keycloak.logout();
2521
+ }
2522
+ showModal() {
2523
+ const appModal = this.el.shadowRoot.querySelector('#appListModal');
2524
+ appModal.style.display = "block";
2525
+ }
2526
+ closeModal() {
2527
+ const appModal = this.el.shadowRoot.querySelector('#appListModal');
2528
+ appModal.style.display = "none";
2529
+ }
2530
+ render() {
2531
+ return index.h("div", { key: '29a7944051bce29ea8ff3f1db8f2b44b5a157e84' }, index.h("div", { key: 'a44011e412f06a00bca1a6de134391cc1eb248c2' }, (() => {
2532
+ if (this.isAuth && this.showPostLoginText) {
2533
+ return (index.h("a", { href: this.redirectUri, id: "login-btn", class: "button button-link" }, index.h("span", { class: "button-text button-text-full-width" }, "Go to Dashboard")));
2534
+ }
2535
+ else if (this.isAuth) {
2536
+ return (index.h("div", { id: "profile-btn", class: "dropdown" }, index.h("button", { type: "button", class: "button" }, index.h("span", { class: "button-profile" }, index.h("img", { src: "https://i.pravatar.cc/100?img=32", alt: "" })), index.h("span", { id: "given-name", class: "button-text" }, this.givenName), index.h("div", { class: "button-icon" }, index.h("span", { class: "gg-menu-grid-r" }))), index.h("div", { class: "dropdown-content" }, index.h("a", { onClick: this.showModal.bind(this), id: "applications-btn" }, "Applications"), index.h("a", { onClick: this.logout.bind(this), id: "logout-btn" }, "Logout"))));
2537
+ }
2538
+ else {
2539
+ return (index.h("button", { onClick: this.login.bind(this), id: "login-btn", type: "button", class: "button" }, index.h("span", { class: "button-text" }, "Login")));
2540
+ }
2541
+ })()), index.h("div", { key: '475cbe51090c78848032e9044c9f11e460969121', id: "appListModal", class: "modal" }, index.h("div", { key: 'e0a2a1ffa3de0d45001f40fb46d258ade64dc933', class: "modal-content" }, index.h("span", { key: '5fa70d2fcac6816d9a9ee41c329bd9c787014cbb', onClick: this.closeModal.bind(this), class: "close" }, "\u00D7"), index.h("h3", { key: 'de74b78ba75d815758e0d7c68474d7cdb7673ae7' }, "Applications"), index.h("div", { key: '1ed88b256cb82aef902f08179e24cbd0be810bd9', class: "modal-app" }, "App 1"), index.h("div", { key: 'e3e32a260fa06452fb38e64e4593cae1d8530c7b', class: "modal-app" }, "App 2"))));
2542
+ }
2543
+ get el() { return index.getElement(this); }
2544
+ };
2545
+ DashButtonComponent.style = DashButtonStyle0;
2546
+
2547
+ exports.dash_button = DashButtonComponent;
2548
+
2549
+ //# sourceMappingURL=dash-button.cjs.entry.js.map