@grafit/era-dependencies 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -0
- package/vendor/fonts/FontAwesome.otf +0 -0
- package/vendor/fonts/fontawesome-webfont.eot +0 -0
- package/vendor/fonts/fontawesome-webfont.svg +685 -0
- package/vendor/fonts/fontawesome-webfont.ttf +0 -0
- package/vendor/fonts/fontawesome-webfont.woff +0 -0
- package/vendor/fonts/fontawesome-webfont.woff2 +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.eot +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.svg +288 -0
- package/vendor/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.woff +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/vendor/scripts/angular/angular-cookies.js +322 -0
- package/vendor/scripts/angular/angular-file-upload.js +2087 -0
- package/vendor/scripts/angular/angular-filter.js +2287 -0
- package/vendor/scripts/angular/angular-locale_ru-ru.js +143 -0
- package/vendor/scripts/angular/angular-route.js +1069 -0
- package/vendor/scripts/angular/angular-sanitize.js +738 -0
- package/vendor/scripts/angular/angular-ui-router-0.2.18.js +4539 -0
- package/vendor/scripts/angular/angular.js +31768 -0
- package/vendor/scripts/angular/datetimepicker.js +578 -0
- package/vendor/scripts/angular/datetimepicker.templates.js +30 -0
- package/vendor/scripts/angular/mask.min.js +7 -0
- package/vendor/scripts/angular/ng-table.js +1518 -0
- package/vendor/scripts/angular/select.js +2356 -0
- package/vendor/scripts/angular/ui-bootstrap-tpls-2.1.3.js +7536 -0
- package/vendor/scripts/angular/uploader.js +3 -0
- package/vendor/scripts/bootbox.js +985 -0
- package/vendor/scripts/bootstrap.js +2377 -0
- package/vendor/scripts/es6-shim.js +3837 -0
- package/vendor/scripts/highchart/highcharts-more.src.js +3165 -0
- package/vendor/scripts/highchart/highstock.src.js +32008 -0
- package/vendor/scripts/highchart/modules/boost.src.js +2721 -0
- package/vendor/scripts/highchart/modules/exporting.src.js +951 -0
- package/vendor/scripts/jquery/jquery.js +11008 -0
- package/vendor/scripts/jquery.datetimepicker.full.js +2911 -0
- package/vendor/scripts/keycloak.js +2382 -0
- package/vendor/scripts/lodash.js +16733 -0
- package/vendor/scripts/moment-with-locales.js +12251 -0
- package/vendor/scripts/moment.js +4234 -0
- package/vendor/scripts/old/datepicker-ru.js +38 -0
- package/vendor/scripts/old/jquery-ui-1.11.1.js +16375 -0
- package/vendor/scripts/old/jquery.form.js +1278 -0
- package/vendor/scripts/perfect-scrollbar.js +1549 -0
- package/vendor/scripts/pickmeup/pickmeup-locales.js +11 -0
- package/vendor/scripts/pickmeup/pickmeup.js +1383 -0
- package/vendor/scripts/quill.js +9676 -0
- package/vendor/scripts/socket.io.min.js +3 -0
- package/vendor/scripts/textAngular/angular-spectrum-colorpicker.min.js +2 -0
- package/vendor/scripts/textAngular/spectrum.min.js +1 -0
- package/vendor/scripts/textAngular/textAngular-dropdownToggle.js +38 -0
- package/vendor/scripts/textAngular/textAngular-rangy.min.js +478 -0
- package/vendor/scripts/textAngular/textAngular-sanitize.min.js +322 -0
- package/vendor/scripts/textAngular/textAngular.min.js +1481 -0
- package/vendor/scripts/textAngular/textAngularSetup.js +1013 -0
- package/vendor/styles/bootstrap-theme.css +587 -0
- package/vendor/styles/bootstrap-theme.css.map +1 -0
- package/vendor/styles/bootstrap-theme.min.css +6 -0
- package/vendor/styles/bootstrap-theme.min.css.map +1 -0
- package/vendor/styles/bootstrap.css +6757 -0
- package/vendor/styles/bootstrap.css.map +1 -0
- package/vendor/styles/bootstrap.min.css +6 -0
- package/vendor/styles/bootstrap.min.css.map +1 -0
- package/vendor/styles/datetimepicker.css +115 -0
- package/vendor/styles/font-awesome.css +2199 -0
- package/vendor/styles/jquery.datetimepicker.min.css +1 -0
- package/vendor/styles/ng-table.css +136 -0
- package/vendor/styles/normalize.css +424 -0
- package/vendor/styles/perfect-scrollbar.css +165 -0
- package/vendor/styles/pickmeup.css +137 -0
- package/vendor/styles/spectrum.min.css +1 -0
- package/vendor/styles/textAngular.css +193 -0
|
@@ -0,0 +1,2382 @@
|
|
|
1
|
+
// Transpiled to ES5 keycloak-js 25.0.6
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
6
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
8
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
9
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
12
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
13
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
14
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
15
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
19
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
20
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
21
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
22
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
23
|
+
function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
|
|
24
|
+
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
|
|
25
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
26
|
+
function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
|
|
27
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
28
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
29
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
30
|
+
(function (global, factory) {
|
|
31
|
+
(typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('crypto'), require('buffer')) : typeof define === 'function' && define.amd ? define('keycloak', ['crypto', 'buffer'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Keycloak = factory(global.require$$0, global.require$$1));
|
|
32
|
+
})(void 0, function (require$$0, require$$1) {
|
|
33
|
+
'use strict';
|
|
34
|
+
|
|
35
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
36
|
+
function getDefaultExportFromCjs(x) {
|
|
37
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
38
|
+
}
|
|
39
|
+
function commonjsRequire(path) {
|
|
40
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
41
|
+
}
|
|
42
|
+
var es6Promise_min = {
|
|
43
|
+
exports: {}
|
|
44
|
+
};
|
|
45
|
+
(function (module, exports) {
|
|
46
|
+
!function (t, e) {
|
|
47
|
+
module.exports = e();
|
|
48
|
+
}(commonjsGlobal, function () {
|
|
49
|
+
function t(t) {
|
|
50
|
+
var e = _typeof(t);
|
|
51
|
+
return null !== t && ("object" === e || "function" === e);
|
|
52
|
+
}
|
|
53
|
+
function e(t) {
|
|
54
|
+
return "function" == typeof t;
|
|
55
|
+
}
|
|
56
|
+
function n(t) {
|
|
57
|
+
W = t;
|
|
58
|
+
}
|
|
59
|
+
function r(t) {
|
|
60
|
+
z = t;
|
|
61
|
+
}
|
|
62
|
+
function o() {
|
|
63
|
+
return function () {
|
|
64
|
+
return process.nextTick(a);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function i() {
|
|
68
|
+
return "undefined" != typeof U ? function () {
|
|
69
|
+
U(a);
|
|
70
|
+
} : c();
|
|
71
|
+
}
|
|
72
|
+
function s() {
|
|
73
|
+
var t = 0,
|
|
74
|
+
e = new H(a),
|
|
75
|
+
n = document.createTextNode("");
|
|
76
|
+
return e.observe(n, {
|
|
77
|
+
characterData: !0
|
|
78
|
+
}), function () {
|
|
79
|
+
n.data = t = ++t % 2;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function u() {
|
|
83
|
+
var t = new MessageChannel();
|
|
84
|
+
return t.port1.onmessage = a, function () {
|
|
85
|
+
return t.port2.postMessage(0);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function c() {
|
|
89
|
+
var t = setTimeout;
|
|
90
|
+
return function () {
|
|
91
|
+
return t(a, 1);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function a() {
|
|
95
|
+
for (var t = 0; t < N; t += 2) {
|
|
96
|
+
var e = Q[t],
|
|
97
|
+
n = Q[t + 1];
|
|
98
|
+
e(n), Q[t] = void 0, Q[t + 1] = void 0;
|
|
99
|
+
}
|
|
100
|
+
N = 0;
|
|
101
|
+
}
|
|
102
|
+
function f() {
|
|
103
|
+
try {
|
|
104
|
+
var t = Function("return this")().require("vertx");
|
|
105
|
+
return U = t.runOnLoop || t.runOnContext, i();
|
|
106
|
+
} catch (e) {
|
|
107
|
+
return c();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function l(t, e) {
|
|
111
|
+
var n = this,
|
|
112
|
+
r = new this.constructor(v);
|
|
113
|
+
void 0 === r[V] && x(r);
|
|
114
|
+
var o = n._state;
|
|
115
|
+
if (o) {
|
|
116
|
+
var i = arguments[o - 1];
|
|
117
|
+
z(function () {
|
|
118
|
+
return T(o, r, i, n._result);
|
|
119
|
+
});
|
|
120
|
+
} else j(n, r, t, e);
|
|
121
|
+
return r;
|
|
122
|
+
}
|
|
123
|
+
function h(t) {
|
|
124
|
+
var e = this;
|
|
125
|
+
if (t && "object" == _typeof(t) && t.constructor === e) return t;
|
|
126
|
+
var n = new e(v);
|
|
127
|
+
return w(n, t), n;
|
|
128
|
+
}
|
|
129
|
+
function v() {}
|
|
130
|
+
function p() {
|
|
131
|
+
return new TypeError("You cannot resolve a promise with itself");
|
|
132
|
+
}
|
|
133
|
+
function d() {
|
|
134
|
+
return new TypeError("A promises callback cannot return that same promise.");
|
|
135
|
+
}
|
|
136
|
+
function _(t, e, n, r) {
|
|
137
|
+
try {
|
|
138
|
+
t.call(e, n, r);
|
|
139
|
+
} catch (o) {
|
|
140
|
+
return o;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function y(t, e, n) {
|
|
144
|
+
z(function (t) {
|
|
145
|
+
var r = !1,
|
|
146
|
+
o = _(n, e, function (n) {
|
|
147
|
+
r || (r = !0, e !== n ? w(t, n) : A(t, n));
|
|
148
|
+
}, function (e) {
|
|
149
|
+
r || (r = !0, S(t, e));
|
|
150
|
+
}, "Settle: " + (t._label || " unknown promise"));
|
|
151
|
+
!r && o && (r = !0, S(t, o));
|
|
152
|
+
}, t);
|
|
153
|
+
}
|
|
154
|
+
function m(t, e) {
|
|
155
|
+
e._state === Z ? A(t, e._result) : e._state === $ ? S(t, e._result) : j(e, void 0, function (e) {
|
|
156
|
+
return w(t, e);
|
|
157
|
+
}, function (e) {
|
|
158
|
+
return S(t, e);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function b(t, n, r) {
|
|
162
|
+
n.constructor === t.constructor && r === l && n.constructor.resolve === h ? m(t, n) : void 0 === r ? A(t, n) : e(r) ? y(t, n, r) : A(t, n);
|
|
163
|
+
}
|
|
164
|
+
function w(e, n) {
|
|
165
|
+
if (e === n) S(e, p());else if (t(n)) {
|
|
166
|
+
var r = void 0;
|
|
167
|
+
try {
|
|
168
|
+
r = n.then;
|
|
169
|
+
} catch (o) {
|
|
170
|
+
return void S(e, o);
|
|
171
|
+
}
|
|
172
|
+
b(e, n, r);
|
|
173
|
+
} else A(e, n);
|
|
174
|
+
}
|
|
175
|
+
function g(t) {
|
|
176
|
+
t._onerror && t._onerror(t._result), E(t);
|
|
177
|
+
}
|
|
178
|
+
function A(t, e) {
|
|
179
|
+
t._state === X && (t._result = e, t._state = Z, 0 !== t._subscribers.length && z(E, t));
|
|
180
|
+
}
|
|
181
|
+
function S(t, e) {
|
|
182
|
+
t._state === X && (t._state = $, t._result = e, z(g, t));
|
|
183
|
+
}
|
|
184
|
+
function j(t, e, n, r) {
|
|
185
|
+
var o = t._subscribers,
|
|
186
|
+
i = o.length;
|
|
187
|
+
t._onerror = null, o[i] = e, o[i + Z] = n, o[i + $] = r, 0 === i && t._state && z(E, t);
|
|
188
|
+
}
|
|
189
|
+
function E(t) {
|
|
190
|
+
var e = t._subscribers,
|
|
191
|
+
n = t._state;
|
|
192
|
+
if (0 !== e.length) {
|
|
193
|
+
for (var r = void 0, o = void 0, i = t._result, s = 0; s < e.length; s += 3) r = e[s], o = e[s + n], r ? T(n, r, o, i) : o(i);
|
|
194
|
+
t._subscribers.length = 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function T(t, n, r, o) {
|
|
198
|
+
var i = e(r),
|
|
199
|
+
s = void 0,
|
|
200
|
+
u = void 0,
|
|
201
|
+
c = !0;
|
|
202
|
+
if (i) {
|
|
203
|
+
try {
|
|
204
|
+
s = r(o);
|
|
205
|
+
} catch (a) {
|
|
206
|
+
c = !1, u = a;
|
|
207
|
+
}
|
|
208
|
+
if (n === s) return void S(n, d());
|
|
209
|
+
} else s = o;
|
|
210
|
+
n._state !== X || (i && c ? w(n, s) : c === !1 ? S(n, u) : t === Z ? A(n, s) : t === $ && S(n, s));
|
|
211
|
+
}
|
|
212
|
+
function M(t, e) {
|
|
213
|
+
try {
|
|
214
|
+
e(function (e) {
|
|
215
|
+
w(t, e);
|
|
216
|
+
}, function (e) {
|
|
217
|
+
S(t, e);
|
|
218
|
+
});
|
|
219
|
+
} catch (n) {
|
|
220
|
+
S(t, n);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function P() {
|
|
224
|
+
return tt++;
|
|
225
|
+
}
|
|
226
|
+
function x(t) {
|
|
227
|
+
t[V] = tt++, t._state = void 0, t._result = void 0, t._subscribers = [];
|
|
228
|
+
}
|
|
229
|
+
function C() {
|
|
230
|
+
return new Error("Array Methods must be provided an Array");
|
|
231
|
+
}
|
|
232
|
+
function O(t) {
|
|
233
|
+
return new et(this, t).promise;
|
|
234
|
+
}
|
|
235
|
+
function k(t) {
|
|
236
|
+
var e = this;
|
|
237
|
+
return new e(L(t) ? function (n, r) {
|
|
238
|
+
for (var o = t.length, i = 0; i < o; i++) e.resolve(t[i]).then(n, r);
|
|
239
|
+
} : function (t, e) {
|
|
240
|
+
return e(new TypeError("You must pass an array to race."));
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function F(t) {
|
|
244
|
+
var e = this,
|
|
245
|
+
n = new e(v);
|
|
246
|
+
return S(n, t), n;
|
|
247
|
+
}
|
|
248
|
+
function Y() {
|
|
249
|
+
throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");
|
|
250
|
+
}
|
|
251
|
+
function q() {
|
|
252
|
+
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
|
253
|
+
}
|
|
254
|
+
function D() {
|
|
255
|
+
var t = void 0;
|
|
256
|
+
if ("undefined" != typeof commonjsGlobal) t = commonjsGlobal;else if ("undefined" != typeof self) t = self;else try {
|
|
257
|
+
t = Function("return this")();
|
|
258
|
+
} catch (e) {
|
|
259
|
+
throw new Error("polyfill failed because global object is unavailable in this environment");
|
|
260
|
+
}
|
|
261
|
+
var n = t.Promise;
|
|
262
|
+
if (n) {
|
|
263
|
+
var r = null;
|
|
264
|
+
try {
|
|
265
|
+
r = Object.prototype.toString.call(n.resolve());
|
|
266
|
+
} catch (e) {}
|
|
267
|
+
if ("[object Promise]" === r && !n.cast) return;
|
|
268
|
+
}
|
|
269
|
+
t.Promise = nt;
|
|
270
|
+
}
|
|
271
|
+
var K = void 0;
|
|
272
|
+
K = Array.isArray ? Array.isArray : function (t) {
|
|
273
|
+
return "[object Array]" === Object.prototype.toString.call(t);
|
|
274
|
+
};
|
|
275
|
+
var L = K,
|
|
276
|
+
N = 0,
|
|
277
|
+
U = void 0,
|
|
278
|
+
W = void 0,
|
|
279
|
+
z = function z(t, e) {
|
|
280
|
+
Q[N] = t, Q[N + 1] = e, N += 2, 2 === N && (W ? W(a) : R());
|
|
281
|
+
},
|
|
282
|
+
B = "undefined" != typeof window ? window : void 0,
|
|
283
|
+
G = B || {},
|
|
284
|
+
H = G.MutationObserver || G.WebKitMutationObserver,
|
|
285
|
+
I = "undefined" == typeof self && "undefined" != typeof process && "[object process]" === {}.toString.call(process),
|
|
286
|
+
J = "undefined" != typeof Uint8ClampedArray && "undefined" != typeof importScripts && "undefined" != typeof MessageChannel,
|
|
287
|
+
Q = new Array(1e3),
|
|
288
|
+
R = void 0;
|
|
289
|
+
R = I ? o() : H ? s() : J ? u() : void 0 === B && "function" == typeof commonjsRequire ? f() : c();
|
|
290
|
+
var V = Math.random().toString(36).substring(2),
|
|
291
|
+
X = void 0,
|
|
292
|
+
Z = 1,
|
|
293
|
+
$ = 2,
|
|
294
|
+
tt = 0,
|
|
295
|
+
et = function () {
|
|
296
|
+
function t(t, e) {
|
|
297
|
+
this._instanceConstructor = t, this.promise = new t(v), this.promise[V] || x(this.promise), L(e) ? (this.length = e.length, this._remaining = e.length, this._result = new Array(this.length), 0 === this.length ? A(this.promise, this._result) : (this.length = this.length || 0, this._enumerate(e), 0 === this._remaining && A(this.promise, this._result))) : S(this.promise, C());
|
|
298
|
+
}
|
|
299
|
+
return t.prototype._enumerate = function (t) {
|
|
300
|
+
for (var e = 0; this._state === X && e < t.length; e++) this._eachEntry(t[e], e);
|
|
301
|
+
}, t.prototype._eachEntry = function (t, e) {
|
|
302
|
+
var n = this._instanceConstructor,
|
|
303
|
+
r = n.resolve;
|
|
304
|
+
if (r === h) {
|
|
305
|
+
var o = void 0,
|
|
306
|
+
i = void 0,
|
|
307
|
+
s = !1;
|
|
308
|
+
try {
|
|
309
|
+
o = t.then;
|
|
310
|
+
} catch (u) {
|
|
311
|
+
s = !0, i = u;
|
|
312
|
+
}
|
|
313
|
+
if (o === l && t._state !== X) this._settledAt(t._state, e, t._result);else if ("function" != typeof o) this._remaining--, this._result[e] = t;else if (n === nt) {
|
|
314
|
+
var c = new n(v);
|
|
315
|
+
s ? S(c, i) : b(c, t, o), this._willSettleAt(c, e);
|
|
316
|
+
} else this._willSettleAt(new n(function (e) {
|
|
317
|
+
return e(t);
|
|
318
|
+
}), e);
|
|
319
|
+
} else this._willSettleAt(r(t), e);
|
|
320
|
+
}, t.prototype._settledAt = function (t, e, n) {
|
|
321
|
+
var r = this.promise;
|
|
322
|
+
r._state === X && (this._remaining--, t === $ ? S(r, n) : this._result[e] = n), 0 === this._remaining && A(r, this._result);
|
|
323
|
+
}, t.prototype._willSettleAt = function (t, e) {
|
|
324
|
+
var n = this;
|
|
325
|
+
j(t, void 0, function (t) {
|
|
326
|
+
return n._settledAt(Z, e, t);
|
|
327
|
+
}, function (t) {
|
|
328
|
+
return n._settledAt($, e, t);
|
|
329
|
+
});
|
|
330
|
+
}, t;
|
|
331
|
+
}(),
|
|
332
|
+
nt = function () {
|
|
333
|
+
function t(e) {
|
|
334
|
+
this[V] = P(), this._result = this._state = void 0, this._subscribers = [], v !== e && ("function" != typeof e && Y(), this instanceof t ? M(this, e) : q());
|
|
335
|
+
}
|
|
336
|
+
return t.prototype["catch"] = function (t) {
|
|
337
|
+
return this.then(null, t);
|
|
338
|
+
}, t.prototype["finally"] = function (t) {
|
|
339
|
+
var n = this,
|
|
340
|
+
r = n.constructor;
|
|
341
|
+
return e(t) ? n.then(function (e) {
|
|
342
|
+
return r.resolve(t()).then(function () {
|
|
343
|
+
return e;
|
|
344
|
+
});
|
|
345
|
+
}, function (e) {
|
|
346
|
+
return r.resolve(t()).then(function () {
|
|
347
|
+
throw e;
|
|
348
|
+
});
|
|
349
|
+
}) : n.then(t, t);
|
|
350
|
+
}, t;
|
|
351
|
+
}();
|
|
352
|
+
return nt.prototype.then = l, nt.all = O, nt.race = k, nt.resolve = h, nt.reject = F, nt._setScheduler = n, nt._setAsap = r, nt._asap = z, nt.polyfill = D, nt.Promise = nt, nt;
|
|
353
|
+
});
|
|
354
|
+
})(es6Promise_min);
|
|
355
|
+
var es6Promise_minExports = es6Promise_min.exports;
|
|
356
|
+
var sha256$1 = {
|
|
357
|
+
exports: {}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
362
|
+
*
|
|
363
|
+
* @version 0.11.0
|
|
364
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
365
|
+
* @copyright Chen, Yi-Cyuan 2014-2024
|
|
366
|
+
* @license MIT
|
|
367
|
+
*/
|
|
368
|
+
|
|
369
|
+
(function (module) {
|
|
370
|
+
/*jslint bitwise: true */
|
|
371
|
+
(function () {
|
|
372
|
+
var ERROR = 'input is invalid type';
|
|
373
|
+
var WINDOW = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object';
|
|
374
|
+
var root = WINDOW ? window : {};
|
|
375
|
+
if (root.JS_SHA256_NO_WINDOW) {
|
|
376
|
+
WINDOW = false;
|
|
377
|
+
}
|
|
378
|
+
var WEB_WORKER = !WINDOW && (typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object';
|
|
379
|
+
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process.versions && process.versions.node;
|
|
380
|
+
if (NODE_JS) {
|
|
381
|
+
root = commonjsGlobal;
|
|
382
|
+
} else if (WEB_WORKER) {
|
|
383
|
+
root = self;
|
|
384
|
+
}
|
|
385
|
+
var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && 'object' === 'object' && module.exports;
|
|
386
|
+
var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
|
387
|
+
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
388
|
+
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
389
|
+
var SHIFT = [24, 16, 8, 0];
|
|
390
|
+
var K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
|
|
391
|
+
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
|
|
392
|
+
var blocks = [];
|
|
393
|
+
if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
|
|
394
|
+
Array.isArray = function (obj) {
|
|
395
|
+
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
|
399
|
+
ArrayBuffer.isView = function (obj) {
|
|
400
|
+
return _typeof(obj) === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
var createOutputMethod = function createOutputMethod(outputType, is224) {
|
|
404
|
+
return function (message) {
|
|
405
|
+
return new Sha256(is224, true).update(message)[outputType]();
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
var createMethod = function createMethod(is224) {
|
|
409
|
+
var method = createOutputMethod('hex', is224);
|
|
410
|
+
if (NODE_JS) {
|
|
411
|
+
method = nodeWrap(method, is224);
|
|
412
|
+
}
|
|
413
|
+
method.create = function () {
|
|
414
|
+
return new Sha256(is224);
|
|
415
|
+
};
|
|
416
|
+
method.update = function (message) {
|
|
417
|
+
return method.create().update(message);
|
|
418
|
+
};
|
|
419
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
420
|
+
var type = OUTPUT_TYPES[i];
|
|
421
|
+
method[type] = createOutputMethod(type, is224);
|
|
422
|
+
}
|
|
423
|
+
return method;
|
|
424
|
+
};
|
|
425
|
+
var nodeWrap = function nodeWrap(method, is224) {
|
|
426
|
+
var crypto = require$$0;
|
|
427
|
+
var Buffer = require$$1.Buffer;
|
|
428
|
+
var algorithm = is224 ? 'sha224' : 'sha256';
|
|
429
|
+
var bufferFrom;
|
|
430
|
+
if (Buffer.from && !root.JS_SHA256_NO_BUFFER_FROM) {
|
|
431
|
+
bufferFrom = Buffer.from;
|
|
432
|
+
} else {
|
|
433
|
+
bufferFrom = function bufferFrom(message) {
|
|
434
|
+
return new Buffer(message);
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
var nodeMethod = function nodeMethod(message) {
|
|
438
|
+
if (typeof message === 'string') {
|
|
439
|
+
return crypto.createHash(algorithm).update(message, 'utf8').digest('hex');
|
|
440
|
+
} else {
|
|
441
|
+
if (message === null || message === undefined) {
|
|
442
|
+
throw new Error(ERROR);
|
|
443
|
+
} else if (message.constructor === ArrayBuffer) {
|
|
444
|
+
message = new Uint8Array(message);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer) {
|
|
448
|
+
return crypto.createHash(algorithm).update(bufferFrom(message)).digest('hex');
|
|
449
|
+
} else {
|
|
450
|
+
return method(message);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
return nodeMethod;
|
|
454
|
+
};
|
|
455
|
+
var createHmacOutputMethod = function createHmacOutputMethod(outputType, is224) {
|
|
456
|
+
return function (key, message) {
|
|
457
|
+
return new HmacSha256(key, is224, true).update(message)[outputType]();
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
var createHmacMethod = function createHmacMethod(is224) {
|
|
461
|
+
var method = createHmacOutputMethod('hex', is224);
|
|
462
|
+
method.create = function (key) {
|
|
463
|
+
return new HmacSha256(key, is224);
|
|
464
|
+
};
|
|
465
|
+
method.update = function (key, message) {
|
|
466
|
+
return method.create(key).update(message);
|
|
467
|
+
};
|
|
468
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
469
|
+
var type = OUTPUT_TYPES[i];
|
|
470
|
+
method[type] = createHmacOutputMethod(type, is224);
|
|
471
|
+
}
|
|
472
|
+
return method;
|
|
473
|
+
};
|
|
474
|
+
function Sha256(is224, sharedMemory) {
|
|
475
|
+
if (sharedMemory) {
|
|
476
|
+
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
477
|
+
this.blocks = blocks;
|
|
478
|
+
} else {
|
|
479
|
+
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
480
|
+
}
|
|
481
|
+
if (is224) {
|
|
482
|
+
this.h0 = 0xc1059ed8;
|
|
483
|
+
this.h1 = 0x367cd507;
|
|
484
|
+
this.h2 = 0x3070dd17;
|
|
485
|
+
this.h3 = 0xf70e5939;
|
|
486
|
+
this.h4 = 0xffc00b31;
|
|
487
|
+
this.h5 = 0x68581511;
|
|
488
|
+
this.h6 = 0x64f98fa7;
|
|
489
|
+
this.h7 = 0xbefa4fa4;
|
|
490
|
+
} else {
|
|
491
|
+
// 256
|
|
492
|
+
this.h0 = 0x6a09e667;
|
|
493
|
+
this.h1 = 0xbb67ae85;
|
|
494
|
+
this.h2 = 0x3c6ef372;
|
|
495
|
+
this.h3 = 0xa54ff53a;
|
|
496
|
+
this.h4 = 0x510e527f;
|
|
497
|
+
this.h5 = 0x9b05688c;
|
|
498
|
+
this.h6 = 0x1f83d9ab;
|
|
499
|
+
this.h7 = 0x5be0cd19;
|
|
500
|
+
}
|
|
501
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
502
|
+
this.finalized = this.hashed = false;
|
|
503
|
+
this.first = true;
|
|
504
|
+
this.is224 = is224;
|
|
505
|
+
}
|
|
506
|
+
Sha256.prototype.update = function (message) {
|
|
507
|
+
if (this.finalized) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
var notString,
|
|
511
|
+
type = _typeof(message);
|
|
512
|
+
if (type !== 'string') {
|
|
513
|
+
if (type === 'object') {
|
|
514
|
+
if (message === null) {
|
|
515
|
+
throw new Error(ERROR);
|
|
516
|
+
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
517
|
+
message = new Uint8Array(message);
|
|
518
|
+
} else if (!Array.isArray(message)) {
|
|
519
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
520
|
+
throw new Error(ERROR);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
} else {
|
|
524
|
+
throw new Error(ERROR);
|
|
525
|
+
}
|
|
526
|
+
notString = true;
|
|
527
|
+
}
|
|
528
|
+
var code,
|
|
529
|
+
index = 0,
|
|
530
|
+
i,
|
|
531
|
+
length = message.length,
|
|
532
|
+
blocks = this.blocks;
|
|
533
|
+
while (index < length) {
|
|
534
|
+
if (this.hashed) {
|
|
535
|
+
this.hashed = false;
|
|
536
|
+
blocks[0] = this.block;
|
|
537
|
+
this.block = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
538
|
+
}
|
|
539
|
+
if (notString) {
|
|
540
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
541
|
+
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
|
|
542
|
+
}
|
|
543
|
+
} else {
|
|
544
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
545
|
+
code = message.charCodeAt(index);
|
|
546
|
+
if (code < 0x80) {
|
|
547
|
+
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
548
|
+
} else if (code < 0x800) {
|
|
549
|
+
blocks[i >>> 2] |= (0xc0 | code >>> 6) << SHIFT[i++ & 3];
|
|
550
|
+
blocks[i >>> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
551
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
552
|
+
blocks[i >>> 2] |= (0xe0 | code >>> 12) << SHIFT[i++ & 3];
|
|
553
|
+
blocks[i >>> 2] |= (0x80 | code >>> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
554
|
+
blocks[i >>> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
555
|
+
} else {
|
|
556
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | message.charCodeAt(++index) & 0x3ff);
|
|
557
|
+
blocks[i >>> 2] |= (0xf0 | code >>> 18) << SHIFT[i++ & 3];
|
|
558
|
+
blocks[i >>> 2] |= (0x80 | code >>> 12 & 0x3f) << SHIFT[i++ & 3];
|
|
559
|
+
blocks[i >>> 2] |= (0x80 | code >>> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
560
|
+
blocks[i >>> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
this.lastByteIndex = i;
|
|
565
|
+
this.bytes += i - this.start;
|
|
566
|
+
if (i >= 64) {
|
|
567
|
+
this.block = blocks[16];
|
|
568
|
+
this.start = i - 64;
|
|
569
|
+
this.hash();
|
|
570
|
+
this.hashed = true;
|
|
571
|
+
} else {
|
|
572
|
+
this.start = i;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (this.bytes > 4294967295) {
|
|
576
|
+
this.hBytes += this.bytes / 4294967296 << 0;
|
|
577
|
+
this.bytes = this.bytes % 4294967296;
|
|
578
|
+
}
|
|
579
|
+
return this;
|
|
580
|
+
};
|
|
581
|
+
Sha256.prototype.finalize = function () {
|
|
582
|
+
if (this.finalized) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
this.finalized = true;
|
|
586
|
+
var blocks = this.blocks,
|
|
587
|
+
i = this.lastByteIndex;
|
|
588
|
+
blocks[16] = this.block;
|
|
589
|
+
blocks[i >>> 2] |= EXTRA[i & 3];
|
|
590
|
+
this.block = blocks[16];
|
|
591
|
+
if (i >= 56) {
|
|
592
|
+
if (!this.hashed) {
|
|
593
|
+
this.hash();
|
|
594
|
+
}
|
|
595
|
+
blocks[0] = this.block;
|
|
596
|
+
blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
597
|
+
}
|
|
598
|
+
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
|
|
599
|
+
blocks[15] = this.bytes << 3;
|
|
600
|
+
this.hash();
|
|
601
|
+
};
|
|
602
|
+
Sha256.prototype.hash = function () {
|
|
603
|
+
var a = this.h0,
|
|
604
|
+
b = this.h1,
|
|
605
|
+
c = this.h2,
|
|
606
|
+
d = this.h3,
|
|
607
|
+
e = this.h4,
|
|
608
|
+
f = this.h5,
|
|
609
|
+
g = this.h6,
|
|
610
|
+
h = this.h7,
|
|
611
|
+
blocks = this.blocks,
|
|
612
|
+
j,
|
|
613
|
+
s0,
|
|
614
|
+
s1,
|
|
615
|
+
maj,
|
|
616
|
+
t1,
|
|
617
|
+
t2,
|
|
618
|
+
ch,
|
|
619
|
+
ab,
|
|
620
|
+
da,
|
|
621
|
+
cd,
|
|
622
|
+
bc;
|
|
623
|
+
for (j = 16; j < 64; ++j) {
|
|
624
|
+
// rightrotate
|
|
625
|
+
t1 = blocks[j - 15];
|
|
626
|
+
s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
|
|
627
|
+
t1 = blocks[j - 2];
|
|
628
|
+
s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
|
|
629
|
+
blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
|
|
630
|
+
}
|
|
631
|
+
bc = b & c;
|
|
632
|
+
for (j = 0; j < 64; j += 4) {
|
|
633
|
+
if (this.first) {
|
|
634
|
+
if (this.is224) {
|
|
635
|
+
ab = 300032;
|
|
636
|
+
t1 = blocks[0] - 1413257819;
|
|
637
|
+
h = t1 - 150054599 << 0;
|
|
638
|
+
d = t1 + 24177077 << 0;
|
|
639
|
+
} else {
|
|
640
|
+
ab = 704751109;
|
|
641
|
+
t1 = blocks[0] - 210244248;
|
|
642
|
+
h = t1 - 1521486534 << 0;
|
|
643
|
+
d = t1 + 143694565 << 0;
|
|
644
|
+
}
|
|
645
|
+
this.first = false;
|
|
646
|
+
} else {
|
|
647
|
+
s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
648
|
+
s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
649
|
+
ab = a & b;
|
|
650
|
+
maj = ab ^ a & c ^ bc;
|
|
651
|
+
ch = e & f ^ ~e & g;
|
|
652
|
+
t1 = h + s1 + ch + K[j] + blocks[j];
|
|
653
|
+
t2 = s0 + maj;
|
|
654
|
+
h = d + t1 << 0;
|
|
655
|
+
d = t1 + t2 << 0;
|
|
656
|
+
}
|
|
657
|
+
s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
|
|
658
|
+
s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
|
|
659
|
+
da = d & a;
|
|
660
|
+
maj = da ^ d & b ^ ab;
|
|
661
|
+
ch = h & e ^ ~h & f;
|
|
662
|
+
t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
|
|
663
|
+
t2 = s0 + maj;
|
|
664
|
+
g = c + t1 << 0;
|
|
665
|
+
c = t1 + t2 << 0;
|
|
666
|
+
s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
|
|
667
|
+
s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
|
|
668
|
+
cd = c & d;
|
|
669
|
+
maj = cd ^ c & a ^ da;
|
|
670
|
+
ch = g & h ^ ~g & e;
|
|
671
|
+
t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
|
|
672
|
+
t2 = s0 + maj;
|
|
673
|
+
f = b + t1 << 0;
|
|
674
|
+
b = t1 + t2 << 0;
|
|
675
|
+
s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
|
|
676
|
+
s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
|
|
677
|
+
bc = b & c;
|
|
678
|
+
maj = bc ^ b & d ^ cd;
|
|
679
|
+
ch = f & g ^ ~f & h;
|
|
680
|
+
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
|
|
681
|
+
t2 = s0 + maj;
|
|
682
|
+
e = a + t1 << 0;
|
|
683
|
+
a = t1 + t2 << 0;
|
|
684
|
+
this.chromeBugWorkAround = true;
|
|
685
|
+
}
|
|
686
|
+
this.h0 = this.h0 + a << 0;
|
|
687
|
+
this.h1 = this.h1 + b << 0;
|
|
688
|
+
this.h2 = this.h2 + c << 0;
|
|
689
|
+
this.h3 = this.h3 + d << 0;
|
|
690
|
+
this.h4 = this.h4 + e << 0;
|
|
691
|
+
this.h5 = this.h5 + f << 0;
|
|
692
|
+
this.h6 = this.h6 + g << 0;
|
|
693
|
+
this.h7 = this.h7 + h << 0;
|
|
694
|
+
};
|
|
695
|
+
Sha256.prototype.hex = function () {
|
|
696
|
+
this.finalize();
|
|
697
|
+
var h0 = this.h0,
|
|
698
|
+
h1 = this.h1,
|
|
699
|
+
h2 = this.h2,
|
|
700
|
+
h3 = this.h3,
|
|
701
|
+
h4 = this.h4,
|
|
702
|
+
h5 = this.h5,
|
|
703
|
+
h6 = this.h6,
|
|
704
|
+
h7 = this.h7;
|
|
705
|
+
var hex = HEX_CHARS[h0 >>> 28 & 0x0F] + HEX_CHARS[h0 >>> 24 & 0x0F] + HEX_CHARS[h0 >>> 20 & 0x0F] + HEX_CHARS[h0 >>> 16 & 0x0F] + HEX_CHARS[h0 >>> 12 & 0x0F] + HEX_CHARS[h0 >>> 8 & 0x0F] + HEX_CHARS[h0 >>> 4 & 0x0F] + HEX_CHARS[h0 & 0x0F] + HEX_CHARS[h1 >>> 28 & 0x0F] + HEX_CHARS[h1 >>> 24 & 0x0F] + HEX_CHARS[h1 >>> 20 & 0x0F] + HEX_CHARS[h1 >>> 16 & 0x0F] + HEX_CHARS[h1 >>> 12 & 0x0F] + HEX_CHARS[h1 >>> 8 & 0x0F] + HEX_CHARS[h1 >>> 4 & 0x0F] + HEX_CHARS[h1 & 0x0F] + HEX_CHARS[h2 >>> 28 & 0x0F] + HEX_CHARS[h2 >>> 24 & 0x0F] + HEX_CHARS[h2 >>> 20 & 0x0F] + HEX_CHARS[h2 >>> 16 & 0x0F] + HEX_CHARS[h2 >>> 12 & 0x0F] + HEX_CHARS[h2 >>> 8 & 0x0F] + HEX_CHARS[h2 >>> 4 & 0x0F] + HEX_CHARS[h2 & 0x0F] + HEX_CHARS[h3 >>> 28 & 0x0F] + HEX_CHARS[h3 >>> 24 & 0x0F] + HEX_CHARS[h3 >>> 20 & 0x0F] + HEX_CHARS[h3 >>> 16 & 0x0F] + HEX_CHARS[h3 >>> 12 & 0x0F] + HEX_CHARS[h3 >>> 8 & 0x0F] + HEX_CHARS[h3 >>> 4 & 0x0F] + HEX_CHARS[h3 & 0x0F] + HEX_CHARS[h4 >>> 28 & 0x0F] + HEX_CHARS[h4 >>> 24 & 0x0F] + HEX_CHARS[h4 >>> 20 & 0x0F] + HEX_CHARS[h4 >>> 16 & 0x0F] + HEX_CHARS[h4 >>> 12 & 0x0F] + HEX_CHARS[h4 >>> 8 & 0x0F] + HEX_CHARS[h4 >>> 4 & 0x0F] + HEX_CHARS[h4 & 0x0F] + HEX_CHARS[h5 >>> 28 & 0x0F] + HEX_CHARS[h5 >>> 24 & 0x0F] + HEX_CHARS[h5 >>> 20 & 0x0F] + HEX_CHARS[h5 >>> 16 & 0x0F] + HEX_CHARS[h5 >>> 12 & 0x0F] + HEX_CHARS[h5 >>> 8 & 0x0F] + HEX_CHARS[h5 >>> 4 & 0x0F] + HEX_CHARS[h5 & 0x0F] + HEX_CHARS[h6 >>> 28 & 0x0F] + HEX_CHARS[h6 >>> 24 & 0x0F] + HEX_CHARS[h6 >>> 20 & 0x0F] + HEX_CHARS[h6 >>> 16 & 0x0F] + HEX_CHARS[h6 >>> 12 & 0x0F] + HEX_CHARS[h6 >>> 8 & 0x0F] + HEX_CHARS[h6 >>> 4 & 0x0F] + HEX_CHARS[h6 & 0x0F];
|
|
706
|
+
if (!this.is224) {
|
|
707
|
+
hex += HEX_CHARS[h7 >>> 28 & 0x0F] + HEX_CHARS[h7 >>> 24 & 0x0F] + HEX_CHARS[h7 >>> 20 & 0x0F] + HEX_CHARS[h7 >>> 16 & 0x0F] + HEX_CHARS[h7 >>> 12 & 0x0F] + HEX_CHARS[h7 >>> 8 & 0x0F] + HEX_CHARS[h7 >>> 4 & 0x0F] + HEX_CHARS[h7 & 0x0F];
|
|
708
|
+
}
|
|
709
|
+
return hex;
|
|
710
|
+
};
|
|
711
|
+
Sha256.prototype.toString = Sha256.prototype.hex;
|
|
712
|
+
Sha256.prototype.digest = function () {
|
|
713
|
+
this.finalize();
|
|
714
|
+
var h0 = this.h0,
|
|
715
|
+
h1 = this.h1,
|
|
716
|
+
h2 = this.h2,
|
|
717
|
+
h3 = this.h3,
|
|
718
|
+
h4 = this.h4,
|
|
719
|
+
h5 = this.h5,
|
|
720
|
+
h6 = this.h6,
|
|
721
|
+
h7 = this.h7;
|
|
722
|
+
var arr = [h0 >>> 24 & 0xFF, h0 >>> 16 & 0xFF, h0 >>> 8 & 0xFF, h0 & 0xFF, h1 >>> 24 & 0xFF, h1 >>> 16 & 0xFF, h1 >>> 8 & 0xFF, h1 & 0xFF, h2 >>> 24 & 0xFF, h2 >>> 16 & 0xFF, h2 >>> 8 & 0xFF, h2 & 0xFF, h3 >>> 24 & 0xFF, h3 >>> 16 & 0xFF, h3 >>> 8 & 0xFF, h3 & 0xFF, h4 >>> 24 & 0xFF, h4 >>> 16 & 0xFF, h4 >>> 8 & 0xFF, h4 & 0xFF, h5 >>> 24 & 0xFF, h5 >>> 16 & 0xFF, h5 >>> 8 & 0xFF, h5 & 0xFF, h6 >>> 24 & 0xFF, h6 >>> 16 & 0xFF, h6 >>> 8 & 0xFF, h6 & 0xFF];
|
|
723
|
+
if (!this.is224) {
|
|
724
|
+
arr.push(h7 >>> 24 & 0xFF, h7 >>> 16 & 0xFF, h7 >>> 8 & 0xFF, h7 & 0xFF);
|
|
725
|
+
}
|
|
726
|
+
return arr;
|
|
727
|
+
};
|
|
728
|
+
Sha256.prototype.array = Sha256.prototype.digest;
|
|
729
|
+
Sha256.prototype.arrayBuffer = function () {
|
|
730
|
+
this.finalize();
|
|
731
|
+
var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
|
|
732
|
+
var dataView = new DataView(buffer);
|
|
733
|
+
dataView.setUint32(0, this.h0);
|
|
734
|
+
dataView.setUint32(4, this.h1);
|
|
735
|
+
dataView.setUint32(8, this.h2);
|
|
736
|
+
dataView.setUint32(12, this.h3);
|
|
737
|
+
dataView.setUint32(16, this.h4);
|
|
738
|
+
dataView.setUint32(20, this.h5);
|
|
739
|
+
dataView.setUint32(24, this.h6);
|
|
740
|
+
if (!this.is224) {
|
|
741
|
+
dataView.setUint32(28, this.h7);
|
|
742
|
+
}
|
|
743
|
+
return buffer;
|
|
744
|
+
};
|
|
745
|
+
function HmacSha256(key, is224, sharedMemory) {
|
|
746
|
+
var i,
|
|
747
|
+
type = _typeof(key);
|
|
748
|
+
if (type === 'string') {
|
|
749
|
+
var bytes = [],
|
|
750
|
+
length = key.length,
|
|
751
|
+
index = 0,
|
|
752
|
+
code;
|
|
753
|
+
for (i = 0; i < length; ++i) {
|
|
754
|
+
code = key.charCodeAt(i);
|
|
755
|
+
if (code < 0x80) {
|
|
756
|
+
bytes[index++] = code;
|
|
757
|
+
} else if (code < 0x800) {
|
|
758
|
+
bytes[index++] = 0xc0 | code >>> 6;
|
|
759
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
760
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
761
|
+
bytes[index++] = 0xe0 | code >>> 12;
|
|
762
|
+
bytes[index++] = 0x80 | code >>> 6 & 0x3f;
|
|
763
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
764
|
+
} else {
|
|
765
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | key.charCodeAt(++i) & 0x3ff);
|
|
766
|
+
bytes[index++] = 0xf0 | code >>> 18;
|
|
767
|
+
bytes[index++] = 0x80 | code >>> 12 & 0x3f;
|
|
768
|
+
bytes[index++] = 0x80 | code >>> 6 & 0x3f;
|
|
769
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
key = bytes;
|
|
773
|
+
} else {
|
|
774
|
+
if (type === 'object') {
|
|
775
|
+
if (key === null) {
|
|
776
|
+
throw new Error(ERROR);
|
|
777
|
+
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
|
|
778
|
+
key = new Uint8Array(key);
|
|
779
|
+
} else if (!Array.isArray(key)) {
|
|
780
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
|
|
781
|
+
throw new Error(ERROR);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
} else {
|
|
785
|
+
throw new Error(ERROR);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (key.length > 64) {
|
|
789
|
+
key = new Sha256(is224, true).update(key).array();
|
|
790
|
+
}
|
|
791
|
+
var oKeyPad = [],
|
|
792
|
+
iKeyPad = [];
|
|
793
|
+
for (i = 0; i < 64; ++i) {
|
|
794
|
+
var b = key[i] || 0;
|
|
795
|
+
oKeyPad[i] = 0x5c ^ b;
|
|
796
|
+
iKeyPad[i] = 0x36 ^ b;
|
|
797
|
+
}
|
|
798
|
+
Sha256.call(this, is224, sharedMemory);
|
|
799
|
+
this.update(iKeyPad);
|
|
800
|
+
this.oKeyPad = oKeyPad;
|
|
801
|
+
this.inner = true;
|
|
802
|
+
this.sharedMemory = sharedMemory;
|
|
803
|
+
}
|
|
804
|
+
HmacSha256.prototype = new Sha256();
|
|
805
|
+
HmacSha256.prototype.finalize = function () {
|
|
806
|
+
Sha256.prototype.finalize.call(this);
|
|
807
|
+
if (this.inner) {
|
|
808
|
+
this.inner = false;
|
|
809
|
+
var innerHash = this.array();
|
|
810
|
+
Sha256.call(this, this.is224, this.sharedMemory);
|
|
811
|
+
this.update(this.oKeyPad);
|
|
812
|
+
this.update(innerHash);
|
|
813
|
+
Sha256.prototype.finalize.call(this);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
var exports = createMethod();
|
|
817
|
+
exports.sha256 = exports;
|
|
818
|
+
exports.sha224 = createMethod(true);
|
|
819
|
+
exports.sha256.hmac = createHmacMethod();
|
|
820
|
+
exports.sha224.hmac = createHmacMethod(true);
|
|
821
|
+
if (COMMON_JS) {
|
|
822
|
+
module.exports = exports;
|
|
823
|
+
} else {
|
|
824
|
+
root.sha256 = exports.sha256;
|
|
825
|
+
root.sha224 = exports.sha224;
|
|
826
|
+
}
|
|
827
|
+
})();
|
|
828
|
+
})(sha256$1);
|
|
829
|
+
var sha256Exports = sha256$1.exports;
|
|
830
|
+
var sha256 = /*@__PURE__*/getDefaultExportFromCjs(sha256Exports);
|
|
831
|
+
var InvalidTokenError = /*#__PURE__*/function (_Error) {
|
|
832
|
+
function InvalidTokenError() {
|
|
833
|
+
_classCallCheck(this, InvalidTokenError);
|
|
834
|
+
return _callSuper(this, InvalidTokenError, arguments);
|
|
835
|
+
}
|
|
836
|
+
_inherits(InvalidTokenError, _Error);
|
|
837
|
+
return _createClass(InvalidTokenError);
|
|
838
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
839
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
840
|
+
function b64DecodeUnicode(str) {
|
|
841
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, function (m, p) {
|
|
842
|
+
var code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
843
|
+
if (code.length < 2) {
|
|
844
|
+
code = "0" + code;
|
|
845
|
+
}
|
|
846
|
+
return "%" + code;
|
|
847
|
+
}));
|
|
848
|
+
}
|
|
849
|
+
function base64UrlDecode(str) {
|
|
850
|
+
var output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
851
|
+
switch (output.length % 4) {
|
|
852
|
+
case 0:
|
|
853
|
+
break;
|
|
854
|
+
case 2:
|
|
855
|
+
output += "==";
|
|
856
|
+
break;
|
|
857
|
+
case 3:
|
|
858
|
+
output += "=";
|
|
859
|
+
break;
|
|
860
|
+
default:
|
|
861
|
+
throw new Error("base64 string is not of the correct length");
|
|
862
|
+
}
|
|
863
|
+
try {
|
|
864
|
+
return b64DecodeUnicode(output);
|
|
865
|
+
} catch (err) {
|
|
866
|
+
return atob(output);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function jwtDecode(token, options) {
|
|
870
|
+
if (typeof token !== "string") {
|
|
871
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
872
|
+
}
|
|
873
|
+
options || (options = {});
|
|
874
|
+
var pos = options.header === true ? 0 : 1;
|
|
875
|
+
var part = token.split(".")[pos];
|
|
876
|
+
if (typeof part !== "string") {
|
|
877
|
+
throw new InvalidTokenError("Invalid token specified: missing part #".concat(pos + 1));
|
|
878
|
+
}
|
|
879
|
+
var decoded;
|
|
880
|
+
try {
|
|
881
|
+
decoded = base64UrlDecode(part);
|
|
882
|
+
} catch (e) {
|
|
883
|
+
throw new InvalidTokenError("Invalid token specified: invalid base64 for part #".concat(pos + 1, " (").concat(e.message, ")"));
|
|
884
|
+
}
|
|
885
|
+
try {
|
|
886
|
+
return JSON.parse(decoded);
|
|
887
|
+
} catch (e) {
|
|
888
|
+
throw new InvalidTokenError("Invalid token specified: invalid json for part #".concat(pos + 1, " (").concat(e.message, ")"));
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (typeof es6Promise_minExports.Promise === 'undefined') {
|
|
892
|
+
throw Error('Keycloak requires an environment that supports Promises. Make sure that you include the appropriate polyfill.');
|
|
893
|
+
}
|
|
894
|
+
function Keycloak(config) {
|
|
895
|
+
if (!(this instanceof Keycloak)) {
|
|
896
|
+
throw new Error("The 'Keycloak' constructor must be invoked with 'new'.");
|
|
897
|
+
}
|
|
898
|
+
var kc = this;
|
|
899
|
+
var adapter;
|
|
900
|
+
var refreshQueue = [];
|
|
901
|
+
var callbackStorage;
|
|
902
|
+
var loginIframe = {
|
|
903
|
+
enable: true,
|
|
904
|
+
callbackList: [],
|
|
905
|
+
interval: 5
|
|
906
|
+
};
|
|
907
|
+
var scripts = document.getElementsByTagName('script');
|
|
908
|
+
for (var i = 0; i < scripts.length; i++) {
|
|
909
|
+
if ((scripts[i].src.indexOf('keycloak.js') !== -1 || scripts[i].src.indexOf('keycloak.min.js') !== -1) && scripts[i].src.indexOf('version=') !== -1) {
|
|
910
|
+
kc.iframeVersion = scripts[i].src.substring(scripts[i].src.indexOf('version=') + 8).split('&')[0];
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
var useNonce = true;
|
|
914
|
+
var logInfo = createLogger(console.info);
|
|
915
|
+
var logWarn = createLogger(console.warn);
|
|
916
|
+
kc.init = function (initOptions) {
|
|
917
|
+
if (kc.didInitialize) {
|
|
918
|
+
throw new Error("A 'Keycloak' instance can only be initialized once.");
|
|
919
|
+
}
|
|
920
|
+
kc.didInitialize = true;
|
|
921
|
+
kc.authenticated = false;
|
|
922
|
+
callbackStorage = createCallbackStorage();
|
|
923
|
+
var adapters = ['default', 'cordova', 'cordova-native'];
|
|
924
|
+
if (initOptions && adapters.indexOf(initOptions.adapter) > -1) {
|
|
925
|
+
adapter = loadAdapter(initOptions.adapter);
|
|
926
|
+
} else if (initOptions && _typeof(initOptions.adapter) === "object") {
|
|
927
|
+
adapter = initOptions.adapter;
|
|
928
|
+
} else {
|
|
929
|
+
if (window.Cordova || window.cordova) {
|
|
930
|
+
adapter = loadAdapter('cordova');
|
|
931
|
+
} else {
|
|
932
|
+
adapter = loadAdapter();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
if (initOptions) {
|
|
936
|
+
if (typeof initOptions.useNonce !== 'undefined') {
|
|
937
|
+
useNonce = initOptions.useNonce;
|
|
938
|
+
}
|
|
939
|
+
if (typeof initOptions.checkLoginIframe !== 'undefined') {
|
|
940
|
+
loginIframe.enable = initOptions.checkLoginIframe;
|
|
941
|
+
}
|
|
942
|
+
if (initOptions.checkLoginIframeInterval) {
|
|
943
|
+
loginIframe.interval = initOptions.checkLoginIframeInterval;
|
|
944
|
+
}
|
|
945
|
+
if (initOptions.onLoad === 'login-required') {
|
|
946
|
+
kc.loginRequired = true;
|
|
947
|
+
}
|
|
948
|
+
if (initOptions.responseMode) {
|
|
949
|
+
if (initOptions.responseMode === 'query' || initOptions.responseMode === 'fragment') {
|
|
950
|
+
kc.responseMode = initOptions.responseMode;
|
|
951
|
+
} else {
|
|
952
|
+
throw 'Invalid value for responseMode';
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
if (initOptions.flow) {
|
|
956
|
+
switch (initOptions.flow) {
|
|
957
|
+
case 'standard':
|
|
958
|
+
kc.responseType = 'code';
|
|
959
|
+
break;
|
|
960
|
+
case 'implicit':
|
|
961
|
+
kc.responseType = 'id_token token';
|
|
962
|
+
break;
|
|
963
|
+
case 'hybrid':
|
|
964
|
+
kc.responseType = 'code id_token token';
|
|
965
|
+
break;
|
|
966
|
+
default:
|
|
967
|
+
throw 'Invalid value for flow';
|
|
968
|
+
}
|
|
969
|
+
kc.flow = initOptions.flow;
|
|
970
|
+
}
|
|
971
|
+
if (initOptions.timeSkew != null) {
|
|
972
|
+
kc.timeSkew = initOptions.timeSkew;
|
|
973
|
+
}
|
|
974
|
+
if (initOptions.redirectUri) {
|
|
975
|
+
kc.redirectUri = initOptions.redirectUri;
|
|
976
|
+
}
|
|
977
|
+
if (initOptions.silentCheckSsoRedirectUri) {
|
|
978
|
+
kc.silentCheckSsoRedirectUri = initOptions.silentCheckSsoRedirectUri;
|
|
979
|
+
}
|
|
980
|
+
if (typeof initOptions.silentCheckSsoFallback === 'boolean') {
|
|
981
|
+
kc.silentCheckSsoFallback = initOptions.silentCheckSsoFallback;
|
|
982
|
+
} else {
|
|
983
|
+
kc.silentCheckSsoFallback = true;
|
|
984
|
+
}
|
|
985
|
+
if (typeof initOptions.pkceMethod !== "undefined") {
|
|
986
|
+
if (initOptions.pkceMethod !== "S256" && initOptions.pkceMethod !== false) {
|
|
987
|
+
throw new TypeError("Invalid value for pkceMethod', expected 'S256' or false but got ".concat(initOptions.pkceMethod, "."));
|
|
988
|
+
}
|
|
989
|
+
kc.pkceMethod = initOptions.pkceMethod;
|
|
990
|
+
} else {
|
|
991
|
+
kc.pkceMethod = "S256";
|
|
992
|
+
}
|
|
993
|
+
if (typeof initOptions.enableLogging === 'boolean') {
|
|
994
|
+
kc.enableLogging = initOptions.enableLogging;
|
|
995
|
+
} else {
|
|
996
|
+
kc.enableLogging = false;
|
|
997
|
+
}
|
|
998
|
+
if (initOptions.logoutMethod === 'POST') {
|
|
999
|
+
kc.logoutMethod = 'POST';
|
|
1000
|
+
} else {
|
|
1001
|
+
kc.logoutMethod = 'GET';
|
|
1002
|
+
}
|
|
1003
|
+
if (typeof initOptions.scope === 'string') {
|
|
1004
|
+
kc.scope = initOptions.scope;
|
|
1005
|
+
}
|
|
1006
|
+
if (typeof initOptions.acrValues === 'string') {
|
|
1007
|
+
kc.acrValues = initOptions.acrValues;
|
|
1008
|
+
}
|
|
1009
|
+
if (typeof initOptions.messageReceiveTimeout === 'number' && initOptions.messageReceiveTimeout > 0) {
|
|
1010
|
+
kc.messageReceiveTimeout = initOptions.messageReceiveTimeout;
|
|
1011
|
+
} else {
|
|
1012
|
+
kc.messageReceiveTimeout = 10000;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (!kc.responseMode) {
|
|
1016
|
+
kc.responseMode = 'fragment';
|
|
1017
|
+
}
|
|
1018
|
+
if (!kc.responseType) {
|
|
1019
|
+
kc.responseType = 'code';
|
|
1020
|
+
kc.flow = 'standard';
|
|
1021
|
+
}
|
|
1022
|
+
var promise = createPromise();
|
|
1023
|
+
var initPromise = createPromise();
|
|
1024
|
+
initPromise.promise.then(function () {
|
|
1025
|
+
kc.onReady && kc.onReady(kc.authenticated);
|
|
1026
|
+
promise.setSuccess(kc.authenticated);
|
|
1027
|
+
})["catch"](function (error) {
|
|
1028
|
+
promise.setError(error);
|
|
1029
|
+
});
|
|
1030
|
+
var configPromise = loadConfig();
|
|
1031
|
+
function onLoad() {
|
|
1032
|
+
var doLogin = function doLogin(prompt) {
|
|
1033
|
+
if (!prompt) {
|
|
1034
|
+
options.prompt = 'none';
|
|
1035
|
+
}
|
|
1036
|
+
if (initOptions && initOptions.locale) {
|
|
1037
|
+
options.locale = initOptions.locale;
|
|
1038
|
+
}
|
|
1039
|
+
kc.login(options).then(function () {
|
|
1040
|
+
initPromise.setSuccess();
|
|
1041
|
+
})["catch"](function (error) {
|
|
1042
|
+
initPromise.setError(error);
|
|
1043
|
+
});
|
|
1044
|
+
};
|
|
1045
|
+
var checkSsoSilently = function checkSsoSilently() {
|
|
1046
|
+
var ifrm = document.createElement("iframe");
|
|
1047
|
+
var src = kc.createLoginUrl({
|
|
1048
|
+
prompt: 'none',
|
|
1049
|
+
redirectUri: kc.silentCheckSsoRedirectUri
|
|
1050
|
+
});
|
|
1051
|
+
ifrm.setAttribute("src", src);
|
|
1052
|
+
ifrm.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin");
|
|
1053
|
+
ifrm.setAttribute("title", "keycloak-silent-check-sso");
|
|
1054
|
+
ifrm.style.display = "none";
|
|
1055
|
+
document.body.appendChild(ifrm);
|
|
1056
|
+
var _messageCallback = function messageCallback(event) {
|
|
1057
|
+
if (event.origin !== window.location.origin || ifrm.contentWindow !== event.source) {
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
var oauth = parseCallback(event.data);
|
|
1061
|
+
processCallback(oauth, initPromise);
|
|
1062
|
+
document.body.removeChild(ifrm);
|
|
1063
|
+
window.removeEventListener("message", _messageCallback);
|
|
1064
|
+
};
|
|
1065
|
+
window.addEventListener("message", _messageCallback);
|
|
1066
|
+
};
|
|
1067
|
+
var options = {};
|
|
1068
|
+
switch (initOptions.onLoad) {
|
|
1069
|
+
case 'check-sso':
|
|
1070
|
+
if (loginIframe.enable) {
|
|
1071
|
+
setupCheckLoginIframe().then(function () {
|
|
1072
|
+
checkLoginIframe().then(function (unchanged) {
|
|
1073
|
+
if (!unchanged) {
|
|
1074
|
+
kc.silentCheckSsoRedirectUri ? checkSsoSilently() : doLogin(false);
|
|
1075
|
+
} else {
|
|
1076
|
+
initPromise.setSuccess();
|
|
1077
|
+
}
|
|
1078
|
+
})["catch"](function (error) {
|
|
1079
|
+
initPromise.setError(error);
|
|
1080
|
+
});
|
|
1081
|
+
});
|
|
1082
|
+
} else {
|
|
1083
|
+
kc.silentCheckSsoRedirectUri ? checkSsoSilently() : doLogin(false);
|
|
1084
|
+
}
|
|
1085
|
+
break;
|
|
1086
|
+
case 'login-required':
|
|
1087
|
+
doLogin(true);
|
|
1088
|
+
break;
|
|
1089
|
+
default:
|
|
1090
|
+
throw 'Invalid value for onLoad';
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
function processInit() {
|
|
1094
|
+
var callback = parseCallback(window.location.href);
|
|
1095
|
+
if (callback) {
|
|
1096
|
+
window.history.replaceState(window.history.state, null, callback.newUrl);
|
|
1097
|
+
}
|
|
1098
|
+
if (callback && callback.valid) {
|
|
1099
|
+
return setupCheckLoginIframe().then(function () {
|
|
1100
|
+
processCallback(callback, initPromise);
|
|
1101
|
+
})["catch"](function (error) {
|
|
1102
|
+
initPromise.setError(error);
|
|
1103
|
+
});
|
|
1104
|
+
} else if (initOptions) {
|
|
1105
|
+
if (initOptions.token && initOptions.refreshToken) {
|
|
1106
|
+
setToken(initOptions.token, initOptions.refreshToken, initOptions.idToken);
|
|
1107
|
+
if (loginIframe.enable) {
|
|
1108
|
+
setupCheckLoginIframe().then(function () {
|
|
1109
|
+
checkLoginIframe().then(function (unchanged) {
|
|
1110
|
+
if (unchanged) {
|
|
1111
|
+
kc.onAuthSuccess && kc.onAuthSuccess();
|
|
1112
|
+
initPromise.setSuccess();
|
|
1113
|
+
scheduleCheckIframe();
|
|
1114
|
+
} else {
|
|
1115
|
+
initPromise.setSuccess();
|
|
1116
|
+
}
|
|
1117
|
+
})["catch"](function (error) {
|
|
1118
|
+
initPromise.setError(error);
|
|
1119
|
+
});
|
|
1120
|
+
});
|
|
1121
|
+
} else {
|
|
1122
|
+
kc.updateToken(-1).then(function () {
|
|
1123
|
+
kc.onAuthSuccess && kc.onAuthSuccess();
|
|
1124
|
+
initPromise.setSuccess();
|
|
1125
|
+
})["catch"](function (error) {
|
|
1126
|
+
kc.onAuthError && kc.onAuthError();
|
|
1127
|
+
if (initOptions.onLoad) {
|
|
1128
|
+
onLoad();
|
|
1129
|
+
} else {
|
|
1130
|
+
initPromise.setError(error);
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
} else if (initOptions.onLoad) {
|
|
1135
|
+
onLoad();
|
|
1136
|
+
} else {
|
|
1137
|
+
initPromise.setSuccess();
|
|
1138
|
+
}
|
|
1139
|
+
} else {
|
|
1140
|
+
initPromise.setSuccess();
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
function domReady() {
|
|
1144
|
+
var promise = createPromise();
|
|
1145
|
+
var _checkReadyState = function checkReadyState() {
|
|
1146
|
+
if (document.readyState === 'interactive' || document.readyState === 'complete') {
|
|
1147
|
+
document.removeEventListener('readystatechange', _checkReadyState);
|
|
1148
|
+
promise.setSuccess();
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
document.addEventListener('readystatechange', _checkReadyState);
|
|
1152
|
+
_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)
|
|
1153
|
+
|
|
1154
|
+
return promise.promise;
|
|
1155
|
+
}
|
|
1156
|
+
configPromise.then(function () {
|
|
1157
|
+
domReady().then(check3pCookiesSupported).then(processInit)["catch"](function (error) {
|
|
1158
|
+
promise.setError(error);
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
configPromise["catch"](function (error) {
|
|
1162
|
+
promise.setError(error);
|
|
1163
|
+
});
|
|
1164
|
+
return promise.promise;
|
|
1165
|
+
};
|
|
1166
|
+
kc.login = function (options) {
|
|
1167
|
+
return adapter.login(options);
|
|
1168
|
+
};
|
|
1169
|
+
function generateRandomData(len) {
|
|
1170
|
+
// use web crypto APIs if possible
|
|
1171
|
+
var array = null;
|
|
1172
|
+
var crypto = window.crypto || window.msCrypto;
|
|
1173
|
+
if (crypto && crypto.getRandomValues && window.Uint8Array) {
|
|
1174
|
+
array = new Uint8Array(len);
|
|
1175
|
+
crypto.getRandomValues(array);
|
|
1176
|
+
return array;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// fallback to Math random
|
|
1180
|
+
array = new Array(len);
|
|
1181
|
+
for (var j = 0; j < array.length; j++) {
|
|
1182
|
+
array[j] = Math.floor(256 * Math.random());
|
|
1183
|
+
}
|
|
1184
|
+
return array;
|
|
1185
|
+
}
|
|
1186
|
+
function generateCodeVerifier(len) {
|
|
1187
|
+
return generateRandomString(len, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
|
|
1188
|
+
}
|
|
1189
|
+
function generateRandomString(len, alphabet) {
|
|
1190
|
+
var randomData = generateRandomData(len);
|
|
1191
|
+
var chars = new Array(len);
|
|
1192
|
+
for (var i = 0; i < len; i++) {
|
|
1193
|
+
chars[i] = alphabet.charCodeAt(randomData[i] % alphabet.length);
|
|
1194
|
+
}
|
|
1195
|
+
return String.fromCharCode.apply(null, chars);
|
|
1196
|
+
}
|
|
1197
|
+
function generatePkceChallenge(pkceMethod, codeVerifier) {
|
|
1198
|
+
if (pkceMethod !== "S256") {
|
|
1199
|
+
throw new TypeError("Invalid value for 'pkceMethod', expected 'S256' but got '".concat(pkceMethod, "'."));
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
// hash codeVerifier, then encode as url-safe base64 without padding
|
|
1203
|
+
var hashBytes = new Uint8Array(sha256.arrayBuffer(codeVerifier));
|
|
1204
|
+
var encodedHash = bytesToBase64(hashBytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
|
|
1205
|
+
return encodedHash;
|
|
1206
|
+
}
|
|
1207
|
+
function buildClaimsParameter(requestedAcr) {
|
|
1208
|
+
var claims = {
|
|
1209
|
+
id_token: {
|
|
1210
|
+
acr: requestedAcr
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
return JSON.stringify(claims);
|
|
1214
|
+
}
|
|
1215
|
+
kc.createLoginUrl = function (options) {
|
|
1216
|
+
var state = createUUID();
|
|
1217
|
+
var nonce = createUUID();
|
|
1218
|
+
var redirectUri = adapter.redirectUri(options);
|
|
1219
|
+
var callbackState = {
|
|
1220
|
+
state: state,
|
|
1221
|
+
nonce: nonce,
|
|
1222
|
+
redirectUri: encodeURIComponent(redirectUri),
|
|
1223
|
+
loginOptions: options
|
|
1224
|
+
};
|
|
1225
|
+
if (options && options.prompt) {
|
|
1226
|
+
callbackState.prompt = options.prompt;
|
|
1227
|
+
}
|
|
1228
|
+
var baseUrl;
|
|
1229
|
+
if (options && options.action == 'register') {
|
|
1230
|
+
baseUrl = kc.endpoints.register();
|
|
1231
|
+
} else {
|
|
1232
|
+
baseUrl = kc.endpoints.authorize();
|
|
1233
|
+
}
|
|
1234
|
+
var scope = options && options.scope || kc.scope;
|
|
1235
|
+
if (!scope) {
|
|
1236
|
+
// if scope is not set, default to "openid"
|
|
1237
|
+
scope = "openid";
|
|
1238
|
+
} else if (scope.indexOf("openid") === -1) {
|
|
1239
|
+
// if openid scope is missing, prefix the given scopes with it
|
|
1240
|
+
scope = "openid " + scope;
|
|
1241
|
+
}
|
|
1242
|
+
var url = baseUrl + '?client_id=' + encodeURIComponent(kc.clientId) + '&redirect_uri=' + encodeURIComponent(redirectUri) + '&state=' + encodeURIComponent(state) + '&response_mode=' + encodeURIComponent(kc.responseMode) + '&response_type=' + encodeURIComponent(kc.responseType) + '&scope=' + encodeURIComponent(scope);
|
|
1243
|
+
if (useNonce) {
|
|
1244
|
+
url = url + '&nonce=' + encodeURIComponent(nonce);
|
|
1245
|
+
}
|
|
1246
|
+
if (options && options.prompt) {
|
|
1247
|
+
url += '&prompt=' + encodeURIComponent(options.prompt);
|
|
1248
|
+
}
|
|
1249
|
+
if (options && options.maxAge) {
|
|
1250
|
+
url += '&max_age=' + encodeURIComponent(options.maxAge);
|
|
1251
|
+
}
|
|
1252
|
+
if (options && options.loginHint) {
|
|
1253
|
+
url += '&login_hint=' + encodeURIComponent(options.loginHint);
|
|
1254
|
+
}
|
|
1255
|
+
if (options && options.idpHint) {
|
|
1256
|
+
url += '&kc_idp_hint=' + encodeURIComponent(options.idpHint);
|
|
1257
|
+
}
|
|
1258
|
+
if (options && options.action && options.action != 'register') {
|
|
1259
|
+
url += '&kc_action=' + encodeURIComponent(options.action);
|
|
1260
|
+
}
|
|
1261
|
+
if (options && options.locale) {
|
|
1262
|
+
url += '&ui_locales=' + encodeURIComponent(options.locale);
|
|
1263
|
+
}
|
|
1264
|
+
if (options && options.acr) {
|
|
1265
|
+
var claimsParameter = buildClaimsParameter(options.acr);
|
|
1266
|
+
url += '&claims=' + encodeURIComponent(claimsParameter);
|
|
1267
|
+
}
|
|
1268
|
+
if (options && options.acrValues || kc.acrValues) {
|
|
1269
|
+
url += '&acr_values=' + encodeURIComponent(options.acrValues || kc.acrValues);
|
|
1270
|
+
}
|
|
1271
|
+
if (kc.pkceMethod) {
|
|
1272
|
+
var codeVerifier = generateCodeVerifier(96);
|
|
1273
|
+
callbackState.pkceCodeVerifier = codeVerifier;
|
|
1274
|
+
var pkceChallenge = generatePkceChallenge(kc.pkceMethod, codeVerifier);
|
|
1275
|
+
url += '&code_challenge=' + pkceChallenge;
|
|
1276
|
+
url += '&code_challenge_method=' + kc.pkceMethod;
|
|
1277
|
+
}
|
|
1278
|
+
callbackStorage.add(callbackState);
|
|
1279
|
+
return url;
|
|
1280
|
+
};
|
|
1281
|
+
kc.logout = function (options) {
|
|
1282
|
+
return adapter.logout(options);
|
|
1283
|
+
};
|
|
1284
|
+
kc.createLogoutUrl = function (options) {
|
|
1285
|
+
var _options$logoutMethod;
|
|
1286
|
+
var logoutMethod = (_options$logoutMethod = options === null || options === void 0 ? void 0 : options.logoutMethod) !== null && _options$logoutMethod !== void 0 ? _options$logoutMethod : kc.logoutMethod;
|
|
1287
|
+
if (logoutMethod === 'POST') {
|
|
1288
|
+
return kc.endpoints.logout();
|
|
1289
|
+
}
|
|
1290
|
+
var url = kc.endpoints.logout() + '?client_id=' + encodeURIComponent(kc.clientId) + '&post_logout_redirect_uri=' + encodeURIComponent(adapter.redirectUri(options, false));
|
|
1291
|
+
if (kc.idToken) {
|
|
1292
|
+
url += '&id_token_hint=' + encodeURIComponent(kc.idToken);
|
|
1293
|
+
}
|
|
1294
|
+
return url;
|
|
1295
|
+
};
|
|
1296
|
+
kc.register = function (options) {
|
|
1297
|
+
return adapter.register(options);
|
|
1298
|
+
};
|
|
1299
|
+
kc.createRegisterUrl = function (options) {
|
|
1300
|
+
if (!options) {
|
|
1301
|
+
options = {};
|
|
1302
|
+
}
|
|
1303
|
+
options.action = 'register';
|
|
1304
|
+
return kc.createLoginUrl(options);
|
|
1305
|
+
};
|
|
1306
|
+
kc.createAccountUrl = function (options) {
|
|
1307
|
+
var realm = getRealmUrl();
|
|
1308
|
+
var url = undefined;
|
|
1309
|
+
if (typeof realm !== 'undefined') {
|
|
1310
|
+
url = realm + '/account' + '?referrer=' + encodeURIComponent(kc.clientId) + '&referrer_uri=' + encodeURIComponent(adapter.redirectUri(options));
|
|
1311
|
+
}
|
|
1312
|
+
return url;
|
|
1313
|
+
};
|
|
1314
|
+
kc.accountManagement = function () {
|
|
1315
|
+
return adapter.accountManagement();
|
|
1316
|
+
};
|
|
1317
|
+
kc.hasRealmRole = function (role) {
|
|
1318
|
+
var access = kc.realmAccess;
|
|
1319
|
+
return !!access && access.roles.indexOf(role) >= 0;
|
|
1320
|
+
};
|
|
1321
|
+
kc.hasResourceRole = function (role, resource) {
|
|
1322
|
+
if (!kc.resourceAccess) {
|
|
1323
|
+
return false;
|
|
1324
|
+
}
|
|
1325
|
+
var access = kc.resourceAccess[resource || kc.clientId];
|
|
1326
|
+
return !!access && access.roles.indexOf(role) >= 0;
|
|
1327
|
+
};
|
|
1328
|
+
kc.loadUserProfile = function () {
|
|
1329
|
+
var url = getRealmUrl() + '/account';
|
|
1330
|
+
var req = new XMLHttpRequest();
|
|
1331
|
+
req.open('GET', url, true);
|
|
1332
|
+
req.setRequestHeader('Accept', 'application/json');
|
|
1333
|
+
req.setRequestHeader('Authorization', 'bearer ' + kc.token);
|
|
1334
|
+
var promise = createPromise();
|
|
1335
|
+
req.onreadystatechange = function () {
|
|
1336
|
+
if (req.readyState == 4) {
|
|
1337
|
+
if (req.status == 200) {
|
|
1338
|
+
kc.profile = JSON.parse(req.responseText);
|
|
1339
|
+
promise.setSuccess(kc.profile);
|
|
1340
|
+
} else {
|
|
1341
|
+
promise.setError();
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
req.send();
|
|
1346
|
+
return promise.promise;
|
|
1347
|
+
};
|
|
1348
|
+
kc.loadUserInfo = function () {
|
|
1349
|
+
var url = kc.endpoints.userinfo();
|
|
1350
|
+
var req = new XMLHttpRequest();
|
|
1351
|
+
req.open('GET', url, true);
|
|
1352
|
+
req.setRequestHeader('Accept', 'application/json');
|
|
1353
|
+
req.setRequestHeader('Authorization', 'bearer ' + kc.token);
|
|
1354
|
+
var promise = createPromise();
|
|
1355
|
+
req.onreadystatechange = function () {
|
|
1356
|
+
if (req.readyState == 4) {
|
|
1357
|
+
if (req.status == 200) {
|
|
1358
|
+
kc.userInfo = JSON.parse(req.responseText);
|
|
1359
|
+
promise.setSuccess(kc.userInfo);
|
|
1360
|
+
} else {
|
|
1361
|
+
promise.setError();
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
req.send();
|
|
1366
|
+
return promise.promise;
|
|
1367
|
+
};
|
|
1368
|
+
kc.isTokenExpired = function (minValidity) {
|
|
1369
|
+
if (!kc.tokenParsed || !kc.refreshToken && kc.flow != 'implicit') {
|
|
1370
|
+
throw 'Not authenticated';
|
|
1371
|
+
}
|
|
1372
|
+
if (kc.timeSkew == null) {
|
|
1373
|
+
logInfo('[KEYCLOAK] Unable to determine if token is expired as timeskew is not set');
|
|
1374
|
+
return true;
|
|
1375
|
+
}
|
|
1376
|
+
var expiresIn = kc.tokenParsed['exp'] - Math.ceil(new Date().getTime() / 1000) + kc.timeSkew;
|
|
1377
|
+
if (minValidity) {
|
|
1378
|
+
if (isNaN(minValidity)) {
|
|
1379
|
+
throw 'Invalid minValidity';
|
|
1380
|
+
}
|
|
1381
|
+
expiresIn -= minValidity;
|
|
1382
|
+
}
|
|
1383
|
+
return expiresIn < 0;
|
|
1384
|
+
};
|
|
1385
|
+
kc.updateToken = function (minValidity) {
|
|
1386
|
+
var promise = createPromise();
|
|
1387
|
+
if (!kc.refreshToken) {
|
|
1388
|
+
promise.setError();
|
|
1389
|
+
return promise.promise;
|
|
1390
|
+
}
|
|
1391
|
+
minValidity = minValidity || 5;
|
|
1392
|
+
var exec = function exec() {
|
|
1393
|
+
var refreshToken = false;
|
|
1394
|
+
if (minValidity == -1) {
|
|
1395
|
+
refreshToken = true;
|
|
1396
|
+
logInfo('[KEYCLOAK] Refreshing token: forced refresh');
|
|
1397
|
+
} else if (!kc.tokenParsed || kc.isTokenExpired(minValidity)) {
|
|
1398
|
+
refreshToken = true;
|
|
1399
|
+
logInfo('[KEYCLOAK] Refreshing token: token expired');
|
|
1400
|
+
}
|
|
1401
|
+
if (!refreshToken) {
|
|
1402
|
+
promise.setSuccess(false);
|
|
1403
|
+
} else {
|
|
1404
|
+
var params = 'grant_type=refresh_token&' + 'refresh_token=' + kc.refreshToken;
|
|
1405
|
+
var url = kc.endpoints.token();
|
|
1406
|
+
refreshQueue.push(promise);
|
|
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
|
+
params += '&client_id=' + encodeURIComponent(kc.clientId);
|
|
1413
|
+
var timeLocal = new Date().getTime();
|
|
1414
|
+
req.onreadystatechange = function () {
|
|
1415
|
+
if (req.readyState == 4) {
|
|
1416
|
+
if (req.status == 200) {
|
|
1417
|
+
logInfo('[KEYCLOAK] Token refreshed');
|
|
1418
|
+
timeLocal = (timeLocal + new Date().getTime()) / 2;
|
|
1419
|
+
var tokenResponse = JSON.parse(req.responseText);
|
|
1420
|
+
setToken(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], timeLocal);
|
|
1421
|
+
kc.onAuthRefreshSuccess && kc.onAuthRefreshSuccess();
|
|
1422
|
+
for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
|
|
1423
|
+
p.setSuccess(true);
|
|
1424
|
+
}
|
|
1425
|
+
} else {
|
|
1426
|
+
logWarn('[KEYCLOAK] Failed to refresh token');
|
|
1427
|
+
if (req.status == 400) {
|
|
1428
|
+
kc.clearToken();
|
|
1429
|
+
}
|
|
1430
|
+
kc.onAuthRefreshError && kc.onAuthRefreshError();
|
|
1431
|
+
for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
|
|
1432
|
+
p.setError(true);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
req.send(params);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
if (loginIframe.enable) {
|
|
1442
|
+
var iframePromise = checkLoginIframe();
|
|
1443
|
+
iframePromise.then(function () {
|
|
1444
|
+
exec();
|
|
1445
|
+
})["catch"](function (error) {
|
|
1446
|
+
promise.setError(error);
|
|
1447
|
+
});
|
|
1448
|
+
} else {
|
|
1449
|
+
exec();
|
|
1450
|
+
}
|
|
1451
|
+
return promise.promise;
|
|
1452
|
+
};
|
|
1453
|
+
kc.clearToken = function () {
|
|
1454
|
+
if (kc.token) {
|
|
1455
|
+
setToken(null, null, null);
|
|
1456
|
+
kc.onAuthLogout && kc.onAuthLogout();
|
|
1457
|
+
if (kc.loginRequired) {
|
|
1458
|
+
kc.login();
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
function getRealmUrl() {
|
|
1463
|
+
if (typeof kc.authServerUrl !== 'undefined') {
|
|
1464
|
+
if (kc.authServerUrl.charAt(kc.authServerUrl.length - 1) == '/') {
|
|
1465
|
+
return kc.authServerUrl + 'realms/' + encodeURIComponent(kc.realm);
|
|
1466
|
+
} else {
|
|
1467
|
+
return kc.authServerUrl + '/realms/' + encodeURIComponent(kc.realm);
|
|
1468
|
+
}
|
|
1469
|
+
} else {
|
|
1470
|
+
return undefined;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
function getOrigin() {
|
|
1474
|
+
if (!window.location.origin) {
|
|
1475
|
+
return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
|
|
1476
|
+
} else {
|
|
1477
|
+
return window.location.origin;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
function processCallback(oauth, promise) {
|
|
1481
|
+
var code = oauth.code;
|
|
1482
|
+
var error = oauth.error;
|
|
1483
|
+
var prompt = oauth.prompt;
|
|
1484
|
+
var timeLocal = new Date().getTime();
|
|
1485
|
+
if (oauth['kc_action_status']) {
|
|
1486
|
+
kc.onActionUpdate && kc.onActionUpdate(oauth['kc_action_status']);
|
|
1487
|
+
}
|
|
1488
|
+
if (error) {
|
|
1489
|
+
if (prompt != 'none') {
|
|
1490
|
+
if (oauth.error_description && oauth.error_description === "authentication_expired") {
|
|
1491
|
+
kc.login(oauth.loginOptions);
|
|
1492
|
+
} else {
|
|
1493
|
+
var errorData = {
|
|
1494
|
+
error: error,
|
|
1495
|
+
error_description: oauth.error_description
|
|
1496
|
+
};
|
|
1497
|
+
kc.onAuthError && kc.onAuthError(errorData);
|
|
1498
|
+
promise && promise.setError(errorData);
|
|
1499
|
+
}
|
|
1500
|
+
} else {
|
|
1501
|
+
promise && promise.setSuccess();
|
|
1502
|
+
}
|
|
1503
|
+
return;
|
|
1504
|
+
} else if (kc.flow != 'standard' && (oauth.access_token || oauth.id_token)) {
|
|
1505
|
+
authSuccess(oauth.access_token, null, oauth.id_token, true);
|
|
1506
|
+
}
|
|
1507
|
+
if (kc.flow != 'implicit' && code) {
|
|
1508
|
+
var params = 'code=' + code + '&grant_type=authorization_code';
|
|
1509
|
+
var url = kc.endpoints.token();
|
|
1510
|
+
var req = new XMLHttpRequest();
|
|
1511
|
+
req.open('POST', url, true);
|
|
1512
|
+
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
1513
|
+
params += '&client_id=' + encodeURIComponent(kc.clientId);
|
|
1514
|
+
params += '&redirect_uri=' + oauth.redirectUri;
|
|
1515
|
+
if (oauth.pkceCodeVerifier) {
|
|
1516
|
+
params += '&code_verifier=' + oauth.pkceCodeVerifier;
|
|
1517
|
+
}
|
|
1518
|
+
req.withCredentials = true;
|
|
1519
|
+
req.onreadystatechange = function () {
|
|
1520
|
+
if (req.readyState == 4) {
|
|
1521
|
+
if (req.status == 200) {
|
|
1522
|
+
var tokenResponse = JSON.parse(req.responseText);
|
|
1523
|
+
authSuccess(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], kc.flow === 'standard');
|
|
1524
|
+
scheduleCheckIframe();
|
|
1525
|
+
} else {
|
|
1526
|
+
kc.onAuthError && kc.onAuthError();
|
|
1527
|
+
promise && promise.setError();
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
req.send(params);
|
|
1532
|
+
}
|
|
1533
|
+
function authSuccess(accessToken, refreshToken, idToken, fulfillPromise) {
|
|
1534
|
+
timeLocal = (timeLocal + new Date().getTime()) / 2;
|
|
1535
|
+
setToken(accessToken, refreshToken, idToken, timeLocal);
|
|
1536
|
+
if (useNonce && kc.idTokenParsed && kc.idTokenParsed.nonce != oauth.storedNonce) {
|
|
1537
|
+
logInfo('[KEYCLOAK] Invalid nonce, clearing token');
|
|
1538
|
+
kc.clearToken();
|
|
1539
|
+
promise && promise.setError();
|
|
1540
|
+
} else {
|
|
1541
|
+
if (fulfillPromise) {
|
|
1542
|
+
kc.onAuthSuccess && kc.onAuthSuccess();
|
|
1543
|
+
promise && promise.setSuccess();
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
function loadConfig(url) {
|
|
1549
|
+
var promise = createPromise();
|
|
1550
|
+
var configUrl;
|
|
1551
|
+
if (!config) {
|
|
1552
|
+
configUrl = 'keycloak.json';
|
|
1553
|
+
} else if (typeof config === 'string') {
|
|
1554
|
+
configUrl = config;
|
|
1555
|
+
}
|
|
1556
|
+
function setupOidcEndoints(oidcConfiguration) {
|
|
1557
|
+
if (!oidcConfiguration) {
|
|
1558
|
+
kc.endpoints = {
|
|
1559
|
+
authorize: function authorize() {
|
|
1560
|
+
return getRealmUrl() + '/protocol/openid-connect/auth';
|
|
1561
|
+
},
|
|
1562
|
+
token: function token() {
|
|
1563
|
+
return getRealmUrl() + '/protocol/openid-connect/token';
|
|
1564
|
+
},
|
|
1565
|
+
logout: function logout() {
|
|
1566
|
+
return getRealmUrl() + '/protocol/openid-connect/logout';
|
|
1567
|
+
},
|
|
1568
|
+
checkSessionIframe: function checkSessionIframe() {
|
|
1569
|
+
var src = getRealmUrl() + '/protocol/openid-connect/login-status-iframe.html';
|
|
1570
|
+
if (kc.iframeVersion) {
|
|
1571
|
+
src = src + '?version=' + kc.iframeVersion;
|
|
1572
|
+
}
|
|
1573
|
+
return src;
|
|
1574
|
+
},
|
|
1575
|
+
thirdPartyCookiesIframe: function thirdPartyCookiesIframe() {
|
|
1576
|
+
var src = getRealmUrl() + '/protocol/openid-connect/3p-cookies/step1.html';
|
|
1577
|
+
if (kc.iframeVersion) {
|
|
1578
|
+
src = src + '?version=' + kc.iframeVersion;
|
|
1579
|
+
}
|
|
1580
|
+
return src;
|
|
1581
|
+
},
|
|
1582
|
+
register: function register() {
|
|
1583
|
+
return getRealmUrl() + '/protocol/openid-connect/registrations';
|
|
1584
|
+
},
|
|
1585
|
+
userinfo: function userinfo() {
|
|
1586
|
+
return getRealmUrl() + '/protocol/openid-connect/userinfo';
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
} else {
|
|
1590
|
+
kc.endpoints = {
|
|
1591
|
+
authorize: function authorize() {
|
|
1592
|
+
return oidcConfiguration.authorization_endpoint;
|
|
1593
|
+
},
|
|
1594
|
+
token: function token() {
|
|
1595
|
+
return oidcConfiguration.token_endpoint;
|
|
1596
|
+
},
|
|
1597
|
+
logout: function logout() {
|
|
1598
|
+
if (!oidcConfiguration.end_session_endpoint) {
|
|
1599
|
+
throw "Not supported by the OIDC server";
|
|
1600
|
+
}
|
|
1601
|
+
return oidcConfiguration.end_session_endpoint;
|
|
1602
|
+
},
|
|
1603
|
+
checkSessionIframe: function checkSessionIframe() {
|
|
1604
|
+
if (!oidcConfiguration.check_session_iframe) {
|
|
1605
|
+
throw "Not supported by the OIDC server";
|
|
1606
|
+
}
|
|
1607
|
+
return oidcConfiguration.check_session_iframe;
|
|
1608
|
+
},
|
|
1609
|
+
register: function register() {
|
|
1610
|
+
throw 'Redirection to "Register user" page not supported in standard OIDC mode';
|
|
1611
|
+
},
|
|
1612
|
+
userinfo: function userinfo() {
|
|
1613
|
+
if (!oidcConfiguration.userinfo_endpoint) {
|
|
1614
|
+
throw "Not supported by the OIDC server";
|
|
1615
|
+
}
|
|
1616
|
+
return oidcConfiguration.userinfo_endpoint;
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
if (configUrl) {
|
|
1622
|
+
var req = new XMLHttpRequest();
|
|
1623
|
+
req.open('GET', configUrl, true);
|
|
1624
|
+
req.setRequestHeader('Accept', 'application/json');
|
|
1625
|
+
req.onreadystatechange = function () {
|
|
1626
|
+
if (req.readyState == 4) {
|
|
1627
|
+
if (req.status == 200 || fileLoaded(req)) {
|
|
1628
|
+
var config = JSON.parse(req.responseText);
|
|
1629
|
+
kc.authServerUrl = config['auth-server-url'];
|
|
1630
|
+
kc.realm = config['realm'];
|
|
1631
|
+
kc.clientId = config['resource'];
|
|
1632
|
+
setupOidcEndoints(null);
|
|
1633
|
+
promise.setSuccess();
|
|
1634
|
+
} else {
|
|
1635
|
+
promise.setError();
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
req.send();
|
|
1640
|
+
} else {
|
|
1641
|
+
if (!config.clientId) {
|
|
1642
|
+
throw 'clientId missing';
|
|
1643
|
+
}
|
|
1644
|
+
kc.clientId = config.clientId;
|
|
1645
|
+
var oidcProvider = config['oidcProvider'];
|
|
1646
|
+
if (!oidcProvider) {
|
|
1647
|
+
if (!config['url']) {
|
|
1648
|
+
var scripts = document.getElementsByTagName('script');
|
|
1649
|
+
for (var i = 0; i < scripts.length; i++) {
|
|
1650
|
+
if (scripts[i].src.match(/.*keycloak\.js/)) {
|
|
1651
|
+
config.url = scripts[i].src.substr(0, scripts[i].src.indexOf('/js/keycloak.js'));
|
|
1652
|
+
break;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
if (!config.realm) {
|
|
1657
|
+
throw 'realm missing';
|
|
1658
|
+
}
|
|
1659
|
+
kc.authServerUrl = config.url;
|
|
1660
|
+
kc.realm = config.realm;
|
|
1661
|
+
setupOidcEndoints(null);
|
|
1662
|
+
promise.setSuccess();
|
|
1663
|
+
} else {
|
|
1664
|
+
if (typeof oidcProvider === 'string') {
|
|
1665
|
+
var oidcProviderConfigUrl;
|
|
1666
|
+
if (oidcProvider.charAt(oidcProvider.length - 1) == '/') {
|
|
1667
|
+
oidcProviderConfigUrl = oidcProvider + '.well-known/openid-configuration';
|
|
1668
|
+
} else {
|
|
1669
|
+
oidcProviderConfigUrl = oidcProvider + '/.well-known/openid-configuration';
|
|
1670
|
+
}
|
|
1671
|
+
var req = new XMLHttpRequest();
|
|
1672
|
+
req.open('GET', oidcProviderConfigUrl, true);
|
|
1673
|
+
req.setRequestHeader('Accept', 'application/json');
|
|
1674
|
+
req.onreadystatechange = function () {
|
|
1675
|
+
if (req.readyState == 4) {
|
|
1676
|
+
if (req.status == 200 || fileLoaded(req)) {
|
|
1677
|
+
var oidcProviderConfig = JSON.parse(req.responseText);
|
|
1678
|
+
setupOidcEndoints(oidcProviderConfig);
|
|
1679
|
+
promise.setSuccess();
|
|
1680
|
+
} else {
|
|
1681
|
+
promise.setError();
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
req.send();
|
|
1686
|
+
} else {
|
|
1687
|
+
setupOidcEndoints(oidcProvider);
|
|
1688
|
+
promise.setSuccess();
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return promise.promise;
|
|
1693
|
+
}
|
|
1694
|
+
function fileLoaded(xhr) {
|
|
1695
|
+
return xhr.status == 0 && xhr.responseText && xhr.responseURL.startsWith('file:');
|
|
1696
|
+
}
|
|
1697
|
+
function setToken(token, refreshToken, idToken, timeLocal) {
|
|
1698
|
+
if (kc.tokenTimeoutHandle) {
|
|
1699
|
+
clearTimeout(kc.tokenTimeoutHandle);
|
|
1700
|
+
kc.tokenTimeoutHandle = null;
|
|
1701
|
+
}
|
|
1702
|
+
if (refreshToken) {
|
|
1703
|
+
kc.refreshToken = refreshToken;
|
|
1704
|
+
kc.refreshTokenParsed = jwtDecode(refreshToken);
|
|
1705
|
+
} else {
|
|
1706
|
+
delete kc.refreshToken;
|
|
1707
|
+
delete kc.refreshTokenParsed;
|
|
1708
|
+
}
|
|
1709
|
+
if (idToken) {
|
|
1710
|
+
kc.idToken = idToken;
|
|
1711
|
+
kc.idTokenParsed = jwtDecode(idToken);
|
|
1712
|
+
} else {
|
|
1713
|
+
delete kc.idToken;
|
|
1714
|
+
delete kc.idTokenParsed;
|
|
1715
|
+
}
|
|
1716
|
+
if (token) {
|
|
1717
|
+
kc.token = token;
|
|
1718
|
+
kc.tokenParsed = jwtDecode(token);
|
|
1719
|
+
kc.sessionId = kc.tokenParsed.sid;
|
|
1720
|
+
kc.authenticated = true;
|
|
1721
|
+
kc.subject = kc.tokenParsed.sub;
|
|
1722
|
+
kc.realmAccess = kc.tokenParsed.realm_access;
|
|
1723
|
+
kc.resourceAccess = kc.tokenParsed.resource_access;
|
|
1724
|
+
if (timeLocal) {
|
|
1725
|
+
kc.timeSkew = Math.floor(timeLocal / 1000) - kc.tokenParsed.iat;
|
|
1726
|
+
}
|
|
1727
|
+
if (kc.timeSkew != null) {
|
|
1728
|
+
logInfo('[KEYCLOAK] Estimated time difference between browser and server is ' + kc.timeSkew + ' seconds');
|
|
1729
|
+
if (kc.onTokenExpired) {
|
|
1730
|
+
var expiresIn = (kc.tokenParsed['exp'] - new Date().getTime() / 1000 + kc.timeSkew) * 1000;
|
|
1731
|
+
logInfo('[KEYCLOAK] Token expires in ' + Math.round(expiresIn / 1000) + ' s');
|
|
1732
|
+
if (expiresIn <= 0) {
|
|
1733
|
+
kc.onTokenExpired();
|
|
1734
|
+
} else {
|
|
1735
|
+
kc.tokenTimeoutHandle = setTimeout(kc.onTokenExpired, expiresIn);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
} else {
|
|
1740
|
+
delete kc.token;
|
|
1741
|
+
delete kc.tokenParsed;
|
|
1742
|
+
delete kc.subject;
|
|
1743
|
+
delete kc.realmAccess;
|
|
1744
|
+
delete kc.resourceAccess;
|
|
1745
|
+
kc.authenticated = false;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
function createUUID() {
|
|
1749
|
+
var hexDigits = '0123456789abcdef';
|
|
1750
|
+
var s = generateRandomString(36, hexDigits).split("");
|
|
1751
|
+
s[14] = '4';
|
|
1752
|
+
s[19] = hexDigits.substr(s[19] & 0x3 | 0x8, 1);
|
|
1753
|
+
s[8] = s[13] = s[18] = s[23] = '-';
|
|
1754
|
+
var uuid = s.join('');
|
|
1755
|
+
return uuid;
|
|
1756
|
+
}
|
|
1757
|
+
function parseCallback(url) {
|
|
1758
|
+
var oauth = parseCallbackUrl(url);
|
|
1759
|
+
if (!oauth) {
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
var oauthState = callbackStorage.get(oauth.state);
|
|
1763
|
+
if (oauthState) {
|
|
1764
|
+
oauth.valid = true;
|
|
1765
|
+
oauth.redirectUri = oauthState.redirectUri;
|
|
1766
|
+
oauth.storedNonce = oauthState.nonce;
|
|
1767
|
+
oauth.prompt = oauthState.prompt;
|
|
1768
|
+
oauth.pkceCodeVerifier = oauthState.pkceCodeVerifier;
|
|
1769
|
+
oauth.loginOptions = oauthState.loginOptions;
|
|
1770
|
+
}
|
|
1771
|
+
return oauth;
|
|
1772
|
+
}
|
|
1773
|
+
function parseCallbackUrl(url) {
|
|
1774
|
+
var supportedParams;
|
|
1775
|
+
switch (kc.flow) {
|
|
1776
|
+
case 'standard':
|
|
1777
|
+
supportedParams = ['code', 'state', 'session_state', 'kc_action_status', 'iss'];
|
|
1778
|
+
break;
|
|
1779
|
+
case 'implicit':
|
|
1780
|
+
supportedParams = ['access_token', 'token_type', 'id_token', 'state', 'session_state', 'expires_in', 'kc_action_status', 'iss'];
|
|
1781
|
+
break;
|
|
1782
|
+
case 'hybrid':
|
|
1783
|
+
supportedParams = ['access_token', 'token_type', 'id_token', 'code', 'state', 'session_state', 'expires_in', 'kc_action_status', 'iss'];
|
|
1784
|
+
break;
|
|
1785
|
+
}
|
|
1786
|
+
supportedParams.push('error');
|
|
1787
|
+
supportedParams.push('error_description');
|
|
1788
|
+
supportedParams.push('error_uri');
|
|
1789
|
+
var queryIndex = url.indexOf('?');
|
|
1790
|
+
var fragmentIndex = url.indexOf('#');
|
|
1791
|
+
var newUrl;
|
|
1792
|
+
var parsed;
|
|
1793
|
+
if (kc.responseMode === 'query' && queryIndex !== -1) {
|
|
1794
|
+
newUrl = url.substring(0, queryIndex);
|
|
1795
|
+
parsed = parseCallbackParams(url.substring(queryIndex + 1, fragmentIndex !== -1 ? fragmentIndex : url.length), supportedParams);
|
|
1796
|
+
if (parsed.paramsString !== '') {
|
|
1797
|
+
newUrl += '?' + parsed.paramsString;
|
|
1798
|
+
}
|
|
1799
|
+
if (fragmentIndex !== -1) {
|
|
1800
|
+
newUrl += url.substring(fragmentIndex);
|
|
1801
|
+
}
|
|
1802
|
+
} else if (kc.responseMode === 'fragment' && fragmentIndex !== -1) {
|
|
1803
|
+
newUrl = url.substring(0, fragmentIndex);
|
|
1804
|
+
parsed = parseCallbackParams(url.substring(fragmentIndex + 1), supportedParams);
|
|
1805
|
+
if (parsed.paramsString !== '') {
|
|
1806
|
+
newUrl += '#' + parsed.paramsString;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
if (parsed && parsed.oauthParams) {
|
|
1810
|
+
if (kc.flow === 'standard' || kc.flow === 'hybrid') {
|
|
1811
|
+
if ((parsed.oauthParams.code || parsed.oauthParams.error) && parsed.oauthParams.state) {
|
|
1812
|
+
parsed.oauthParams.newUrl = newUrl;
|
|
1813
|
+
return parsed.oauthParams;
|
|
1814
|
+
}
|
|
1815
|
+
} else if (kc.flow === 'implicit') {
|
|
1816
|
+
if ((parsed.oauthParams.access_token || parsed.oauthParams.error) && parsed.oauthParams.state) {
|
|
1817
|
+
parsed.oauthParams.newUrl = newUrl;
|
|
1818
|
+
return parsed.oauthParams;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
function parseCallbackParams(paramsString, supportedParams) {
|
|
1824
|
+
var p = paramsString.split('&');
|
|
1825
|
+
var result = {
|
|
1826
|
+
paramsString: '',
|
|
1827
|
+
oauthParams: {}
|
|
1828
|
+
};
|
|
1829
|
+
for (var i = 0; i < p.length; i++) {
|
|
1830
|
+
var split = p[i].indexOf("=");
|
|
1831
|
+
var key = p[i].slice(0, split);
|
|
1832
|
+
if (supportedParams.indexOf(key) !== -1) {
|
|
1833
|
+
result.oauthParams[key] = p[i].slice(split + 1);
|
|
1834
|
+
} else {
|
|
1835
|
+
if (result.paramsString !== '') {
|
|
1836
|
+
result.paramsString += '&';
|
|
1837
|
+
}
|
|
1838
|
+
result.paramsString += p[i];
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
return result;
|
|
1842
|
+
}
|
|
1843
|
+
function createPromise() {
|
|
1844
|
+
// Need to create a native Promise which also preserves the
|
|
1845
|
+
// interface of the custom promise type previously used by the API
|
|
1846
|
+
var p = {
|
|
1847
|
+
setSuccess: function setSuccess(result) {
|
|
1848
|
+
p.resolve(result);
|
|
1849
|
+
},
|
|
1850
|
+
setError: function setError(result) {
|
|
1851
|
+
p.reject(result);
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
p.promise = new es6Promise_minExports.Promise(function (resolve, reject) {
|
|
1855
|
+
p.resolve = resolve;
|
|
1856
|
+
p.reject = reject;
|
|
1857
|
+
});
|
|
1858
|
+
return p;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// Function to extend existing native Promise with timeout
|
|
1862
|
+
function applyTimeoutToPromise(promise, timeout, errorMessage) {
|
|
1863
|
+
var timeoutHandle = null;
|
|
1864
|
+
var timeoutPromise = new es6Promise_minExports.Promise(function (resolve, reject) {
|
|
1865
|
+
timeoutHandle = setTimeout(function () {
|
|
1866
|
+
reject({
|
|
1867
|
+
"error": errorMessage
|
|
1868
|
+
});
|
|
1869
|
+
}, timeout);
|
|
1870
|
+
});
|
|
1871
|
+
return es6Promise_minExports.Promise.race([promise, timeoutPromise])["finally"](function () {
|
|
1872
|
+
clearTimeout(timeoutHandle);
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
function setupCheckLoginIframe() {
|
|
1876
|
+
var promise = createPromise();
|
|
1877
|
+
if (!loginIframe.enable) {
|
|
1878
|
+
promise.setSuccess();
|
|
1879
|
+
return promise.promise;
|
|
1880
|
+
}
|
|
1881
|
+
if (loginIframe.iframe) {
|
|
1882
|
+
promise.setSuccess();
|
|
1883
|
+
return promise.promise;
|
|
1884
|
+
}
|
|
1885
|
+
var iframe = document.createElement('iframe');
|
|
1886
|
+
loginIframe.iframe = iframe;
|
|
1887
|
+
iframe.onload = function () {
|
|
1888
|
+
var authUrl = kc.endpoints.authorize();
|
|
1889
|
+
if (authUrl.charAt(0) === '/') {
|
|
1890
|
+
loginIframe.iframeOrigin = getOrigin();
|
|
1891
|
+
} else {
|
|
1892
|
+
loginIframe.iframeOrigin = authUrl.substring(0, authUrl.indexOf('/', 8));
|
|
1893
|
+
}
|
|
1894
|
+
promise.setSuccess();
|
|
1895
|
+
};
|
|
1896
|
+
var src = kc.endpoints.checkSessionIframe();
|
|
1897
|
+
iframe.setAttribute('src', src);
|
|
1898
|
+
iframe.setAttribute('sandbox', 'allow-storage-access-by-user-activation allow-scripts allow-same-origin');
|
|
1899
|
+
iframe.setAttribute('title', 'keycloak-session-iframe');
|
|
1900
|
+
iframe.style.display = 'none';
|
|
1901
|
+
document.body.appendChild(iframe);
|
|
1902
|
+
var messageCallback = function messageCallback(event) {
|
|
1903
|
+
if (event.origin !== loginIframe.iframeOrigin || loginIframe.iframe.contentWindow !== event.source) {
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
if (!(event.data == 'unchanged' || event.data == 'changed' || event.data == 'error')) {
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
if (event.data != 'unchanged') {
|
|
1910
|
+
kc.clearToken();
|
|
1911
|
+
}
|
|
1912
|
+
var callbacks = loginIframe.callbackList.splice(0, loginIframe.callbackList.length);
|
|
1913
|
+
for (var i = callbacks.length - 1; i >= 0; --i) {
|
|
1914
|
+
var promise = callbacks[i];
|
|
1915
|
+
if (event.data == 'error') {
|
|
1916
|
+
promise.setError();
|
|
1917
|
+
} else {
|
|
1918
|
+
promise.setSuccess(event.data == 'unchanged');
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
};
|
|
1922
|
+
window.addEventListener('message', messageCallback, false);
|
|
1923
|
+
return promise.promise;
|
|
1924
|
+
}
|
|
1925
|
+
function scheduleCheckIframe() {
|
|
1926
|
+
if (loginIframe.enable) {
|
|
1927
|
+
if (kc.token) {
|
|
1928
|
+
setTimeout(function () {
|
|
1929
|
+
checkLoginIframe().then(function (unchanged) {
|
|
1930
|
+
if (unchanged) {
|
|
1931
|
+
scheduleCheckIframe();
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
}, loginIframe.interval * 1000);
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
function checkLoginIframe() {
|
|
1939
|
+
var promise = createPromise();
|
|
1940
|
+
if (loginIframe.iframe && loginIframe.iframeOrigin) {
|
|
1941
|
+
var msg = kc.clientId + ' ' + (kc.sessionId ? kc.sessionId : '');
|
|
1942
|
+
loginIframe.callbackList.push(promise);
|
|
1943
|
+
var origin = loginIframe.iframeOrigin;
|
|
1944
|
+
if (loginIframe.callbackList.length == 1) {
|
|
1945
|
+
loginIframe.iframe.contentWindow.postMessage(msg, origin);
|
|
1946
|
+
}
|
|
1947
|
+
} else {
|
|
1948
|
+
promise.setSuccess();
|
|
1949
|
+
}
|
|
1950
|
+
return promise.promise;
|
|
1951
|
+
}
|
|
1952
|
+
function check3pCookiesSupported() {
|
|
1953
|
+
var promise = createPromise();
|
|
1954
|
+
if (loginIframe.enable || kc.silentCheckSsoRedirectUri) {
|
|
1955
|
+
var iframe = document.createElement('iframe');
|
|
1956
|
+
iframe.setAttribute('src', kc.endpoints.thirdPartyCookiesIframe());
|
|
1957
|
+
iframe.setAttribute('sandbox', 'allow-storage-access-by-user-activation allow-scripts allow-same-origin');
|
|
1958
|
+
iframe.setAttribute('title', 'keycloak-3p-check-iframe');
|
|
1959
|
+
iframe.style.display = 'none';
|
|
1960
|
+
document.body.appendChild(iframe);
|
|
1961
|
+
var _messageCallback2 = function messageCallback(event) {
|
|
1962
|
+
if (iframe.contentWindow !== event.source) {
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
if (event.data !== "supported" && event.data !== "unsupported") {
|
|
1966
|
+
return;
|
|
1967
|
+
} else if (event.data === "unsupported") {
|
|
1968
|
+
logWarn("[KEYCLOAK] Your browser is blocking access to 3rd-party cookies, this means:\n\n" + " - It is not possible to retrieve tokens without redirecting to the Keycloak server (a.k.a. no support for silent authentication).\n" + " - It is not possible to automatically detect changes to the session status (such as the user logging out in another tab).\n\n" + "For more information see: https://www.keycloak.org/docs/latest/securing_apps/#_modern_browsers");
|
|
1969
|
+
loginIframe.enable = false;
|
|
1970
|
+
if (kc.silentCheckSsoFallback) {
|
|
1971
|
+
kc.silentCheckSsoRedirectUri = false;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
document.body.removeChild(iframe);
|
|
1975
|
+
window.removeEventListener("message", _messageCallback2);
|
|
1976
|
+
promise.setSuccess();
|
|
1977
|
+
};
|
|
1978
|
+
window.addEventListener('message', _messageCallback2, false);
|
|
1979
|
+
} else {
|
|
1980
|
+
promise.setSuccess();
|
|
1981
|
+
}
|
|
1982
|
+
return applyTimeoutToPromise(promise.promise, kc.messageReceiveTimeout, "Timeout when waiting for 3rd party check iframe message.");
|
|
1983
|
+
}
|
|
1984
|
+
function loadAdapter(type) {
|
|
1985
|
+
if (!type || type == 'default') {
|
|
1986
|
+
return {
|
|
1987
|
+
login: function login(options) {
|
|
1988
|
+
window.location.assign(kc.createLoginUrl(options));
|
|
1989
|
+
return createPromise().promise;
|
|
1990
|
+
},
|
|
1991
|
+
logout: function () {
|
|
1992
|
+
var _logout = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
1993
|
+
var _options$logoutMethod2;
|
|
1994
|
+
var logoutMethod, logoutUrl, response;
|
|
1995
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1996
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1997
|
+
case 0:
|
|
1998
|
+
logoutMethod = (_options$logoutMethod2 = options === null || options === void 0 ? void 0 : options.logoutMethod) !== null && _options$logoutMethod2 !== void 0 ? _options$logoutMethod2 : kc.logoutMethod;
|
|
1999
|
+
if (!(logoutMethod === "GET")) {
|
|
2000
|
+
_context.next = 4;
|
|
2001
|
+
break;
|
|
2002
|
+
}
|
|
2003
|
+
window.location.replace(kc.createLogoutUrl(options));
|
|
2004
|
+
return _context.abrupt("return");
|
|
2005
|
+
case 4:
|
|
2006
|
+
logoutUrl = kc.createLogoutUrl(options);
|
|
2007
|
+
_context.next = 7;
|
|
2008
|
+
return fetch(logoutUrl, {
|
|
2009
|
+
method: "POST",
|
|
2010
|
+
headers: {
|
|
2011
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
2012
|
+
},
|
|
2013
|
+
body: new URLSearchParams({
|
|
2014
|
+
id_token_hint: kc.idToken,
|
|
2015
|
+
client_id: kc.clientId,
|
|
2016
|
+
post_logout_redirect_uri: adapter.redirectUri(options, false)
|
|
2017
|
+
})
|
|
2018
|
+
});
|
|
2019
|
+
case 7:
|
|
2020
|
+
response = _context.sent;
|
|
2021
|
+
if (!response.redirected) {
|
|
2022
|
+
_context.next = 11;
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
window.location.href = response.url;
|
|
2026
|
+
return _context.abrupt("return");
|
|
2027
|
+
case 11:
|
|
2028
|
+
if (!response.ok) {
|
|
2029
|
+
_context.next = 14;
|
|
2030
|
+
break;
|
|
2031
|
+
}
|
|
2032
|
+
window.location.reload();
|
|
2033
|
+
return _context.abrupt("return");
|
|
2034
|
+
case 14:
|
|
2035
|
+
throw new Error("Logout failed, request returned an error code.");
|
|
2036
|
+
case 15:
|
|
2037
|
+
case "end":
|
|
2038
|
+
return _context.stop();
|
|
2039
|
+
}
|
|
2040
|
+
}, _callee);
|
|
2041
|
+
}));
|
|
2042
|
+
function logout(_x) {
|
|
2043
|
+
return _logout.apply(this, arguments);
|
|
2044
|
+
}
|
|
2045
|
+
return logout;
|
|
2046
|
+
}(),
|
|
2047
|
+
register: function register(options) {
|
|
2048
|
+
window.location.assign(kc.createRegisterUrl(options));
|
|
2049
|
+
return createPromise().promise;
|
|
2050
|
+
},
|
|
2051
|
+
accountManagement: function accountManagement() {
|
|
2052
|
+
var accountUrl = kc.createAccountUrl();
|
|
2053
|
+
if (typeof accountUrl !== 'undefined') {
|
|
2054
|
+
window.location.href = accountUrl;
|
|
2055
|
+
} else {
|
|
2056
|
+
throw "Not supported by the OIDC server";
|
|
2057
|
+
}
|
|
2058
|
+
return createPromise().promise;
|
|
2059
|
+
},
|
|
2060
|
+
redirectUri: function redirectUri(options, encodeHash) {
|
|
2061
|
+
if (options && options.redirectUri) {
|
|
2062
|
+
return options.redirectUri;
|
|
2063
|
+
} else if (kc.redirectUri) {
|
|
2064
|
+
return kc.redirectUri;
|
|
2065
|
+
} else {
|
|
2066
|
+
return location.href;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
if (type == 'cordova') {
|
|
2072
|
+
loginIframe.enable = false;
|
|
2073
|
+
var cordovaOpenWindowWrapper = function cordovaOpenWindowWrapper(loginUrl, target, options) {
|
|
2074
|
+
if (window.cordova && window.cordova.InAppBrowser) {
|
|
2075
|
+
// Use inappbrowser for IOS and Android if available
|
|
2076
|
+
return window.cordova.InAppBrowser.open(loginUrl, target, options);
|
|
2077
|
+
} else {
|
|
2078
|
+
return window.open(loginUrl, target, options);
|
|
2079
|
+
}
|
|
2080
|
+
};
|
|
2081
|
+
var shallowCloneCordovaOptions = function shallowCloneCordovaOptions(userOptions) {
|
|
2082
|
+
if (userOptions && userOptions.cordovaOptions) {
|
|
2083
|
+
return Object.keys(userOptions.cordovaOptions).reduce(function (options, optionName) {
|
|
2084
|
+
options[optionName] = userOptions.cordovaOptions[optionName];
|
|
2085
|
+
return options;
|
|
2086
|
+
}, {});
|
|
2087
|
+
} else {
|
|
2088
|
+
return {};
|
|
2089
|
+
}
|
|
2090
|
+
};
|
|
2091
|
+
var formatCordovaOptions = function formatCordovaOptions(cordovaOptions) {
|
|
2092
|
+
return Object.keys(cordovaOptions).reduce(function (options, optionName) {
|
|
2093
|
+
options.push(optionName + "=" + cordovaOptions[optionName]);
|
|
2094
|
+
return options;
|
|
2095
|
+
}, []).join(",");
|
|
2096
|
+
};
|
|
2097
|
+
var createCordovaOptions = function createCordovaOptions(userOptions) {
|
|
2098
|
+
var cordovaOptions = shallowCloneCordovaOptions(userOptions);
|
|
2099
|
+
cordovaOptions.location = 'no';
|
|
2100
|
+
if (userOptions && userOptions.prompt == 'none') {
|
|
2101
|
+
cordovaOptions.hidden = 'yes';
|
|
2102
|
+
}
|
|
2103
|
+
return formatCordovaOptions(cordovaOptions);
|
|
2104
|
+
};
|
|
2105
|
+
var getCordovaRedirectUri = function getCordovaRedirectUri() {
|
|
2106
|
+
return kc.redirectUri || 'http://localhost';
|
|
2107
|
+
};
|
|
2108
|
+
return {
|
|
2109
|
+
login: function login(options) {
|
|
2110
|
+
var promise = createPromise();
|
|
2111
|
+
var cordovaOptions = createCordovaOptions(options);
|
|
2112
|
+
var loginUrl = kc.createLoginUrl(options);
|
|
2113
|
+
var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions);
|
|
2114
|
+
var completed = false;
|
|
2115
|
+
var closed = false;
|
|
2116
|
+
var closeBrowser = function closeBrowser() {
|
|
2117
|
+
closed = true;
|
|
2118
|
+
ref.close();
|
|
2119
|
+
};
|
|
2120
|
+
ref.addEventListener('loadstart', function (event) {
|
|
2121
|
+
if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
|
|
2122
|
+
var callback = parseCallback(event.url);
|
|
2123
|
+
processCallback(callback, promise);
|
|
2124
|
+
closeBrowser();
|
|
2125
|
+
completed = true;
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
ref.addEventListener('loaderror', function (event) {
|
|
2129
|
+
if (!completed) {
|
|
2130
|
+
if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
|
|
2131
|
+
var callback = parseCallback(event.url);
|
|
2132
|
+
processCallback(callback, promise);
|
|
2133
|
+
closeBrowser();
|
|
2134
|
+
completed = true;
|
|
2135
|
+
} else {
|
|
2136
|
+
promise.setError();
|
|
2137
|
+
closeBrowser();
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
});
|
|
2141
|
+
ref.addEventListener('exit', function (event) {
|
|
2142
|
+
if (!closed) {
|
|
2143
|
+
promise.setError({
|
|
2144
|
+
reason: "closed_by_user"
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
});
|
|
2148
|
+
return promise.promise;
|
|
2149
|
+
},
|
|
2150
|
+
logout: function logout(options) {
|
|
2151
|
+
var promise = createPromise();
|
|
2152
|
+
var logoutUrl = kc.createLogoutUrl(options);
|
|
2153
|
+
var ref = cordovaOpenWindowWrapper(logoutUrl, '_blank', 'location=no,hidden=yes,clearcache=yes');
|
|
2154
|
+
var error;
|
|
2155
|
+
ref.addEventListener('loadstart', function (event) {
|
|
2156
|
+
if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
|
|
2157
|
+
ref.close();
|
|
2158
|
+
}
|
|
2159
|
+
});
|
|
2160
|
+
ref.addEventListener('loaderror', function (event) {
|
|
2161
|
+
if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
|
|
2162
|
+
ref.close();
|
|
2163
|
+
} else {
|
|
2164
|
+
error = true;
|
|
2165
|
+
ref.close();
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
ref.addEventListener('exit', function (event) {
|
|
2169
|
+
if (error) {
|
|
2170
|
+
promise.setError();
|
|
2171
|
+
} else {
|
|
2172
|
+
kc.clearToken();
|
|
2173
|
+
promise.setSuccess();
|
|
2174
|
+
}
|
|
2175
|
+
});
|
|
2176
|
+
return promise.promise;
|
|
2177
|
+
},
|
|
2178
|
+
register: function register(options) {
|
|
2179
|
+
var promise = createPromise();
|
|
2180
|
+
var registerUrl = kc.createRegisterUrl();
|
|
2181
|
+
var cordovaOptions = createCordovaOptions(options);
|
|
2182
|
+
var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', cordovaOptions);
|
|
2183
|
+
ref.addEventListener('loadstart', function (event) {
|
|
2184
|
+
if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
|
|
2185
|
+
ref.close();
|
|
2186
|
+
var oauth = parseCallback(event.url);
|
|
2187
|
+
processCallback(oauth, promise);
|
|
2188
|
+
}
|
|
2189
|
+
});
|
|
2190
|
+
return promise.promise;
|
|
2191
|
+
},
|
|
2192
|
+
accountManagement: function accountManagement() {
|
|
2193
|
+
var accountUrl = kc.createAccountUrl();
|
|
2194
|
+
if (typeof accountUrl !== 'undefined') {
|
|
2195
|
+
var ref = cordovaOpenWindowWrapper(accountUrl, '_blank', 'location=no');
|
|
2196
|
+
ref.addEventListener('loadstart', function (event) {
|
|
2197
|
+
if (event.url.indexOf(getCordovaRedirectUri()) == 0) {
|
|
2198
|
+
ref.close();
|
|
2199
|
+
}
|
|
2200
|
+
});
|
|
2201
|
+
} else {
|
|
2202
|
+
throw "Not supported by the OIDC server";
|
|
2203
|
+
}
|
|
2204
|
+
},
|
|
2205
|
+
redirectUri: function redirectUri(options) {
|
|
2206
|
+
return getCordovaRedirectUri();
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
if (type == 'cordova-native') {
|
|
2211
|
+
loginIframe.enable = false;
|
|
2212
|
+
return {
|
|
2213
|
+
login: function login(options) {
|
|
2214
|
+
var promise = createPromise();
|
|
2215
|
+
var loginUrl = kc.createLoginUrl(options);
|
|
2216
|
+
universalLinks.subscribe('keycloak', function (event) {
|
|
2217
|
+
universalLinks.unsubscribe('keycloak');
|
|
2218
|
+
window.cordova.plugins.browsertab.close();
|
|
2219
|
+
var oauth = parseCallback(event.url);
|
|
2220
|
+
processCallback(oauth, promise);
|
|
2221
|
+
});
|
|
2222
|
+
window.cordova.plugins.browsertab.openUrl(loginUrl);
|
|
2223
|
+
return promise.promise;
|
|
2224
|
+
},
|
|
2225
|
+
logout: function logout(options) {
|
|
2226
|
+
var promise = createPromise();
|
|
2227
|
+
var logoutUrl = kc.createLogoutUrl(options);
|
|
2228
|
+
universalLinks.subscribe('keycloak', function (event) {
|
|
2229
|
+
universalLinks.unsubscribe('keycloak');
|
|
2230
|
+
window.cordova.plugins.browsertab.close();
|
|
2231
|
+
kc.clearToken();
|
|
2232
|
+
promise.setSuccess();
|
|
2233
|
+
});
|
|
2234
|
+
window.cordova.plugins.browsertab.openUrl(logoutUrl);
|
|
2235
|
+
return promise.promise;
|
|
2236
|
+
},
|
|
2237
|
+
register: function register(options) {
|
|
2238
|
+
var promise = createPromise();
|
|
2239
|
+
var registerUrl = kc.createRegisterUrl(options);
|
|
2240
|
+
universalLinks.subscribe('keycloak', function (event) {
|
|
2241
|
+
universalLinks.unsubscribe('keycloak');
|
|
2242
|
+
window.cordova.plugins.browsertab.close();
|
|
2243
|
+
var oauth = parseCallback(event.url);
|
|
2244
|
+
processCallback(oauth, promise);
|
|
2245
|
+
});
|
|
2246
|
+
window.cordova.plugins.browsertab.openUrl(registerUrl);
|
|
2247
|
+
return promise.promise;
|
|
2248
|
+
},
|
|
2249
|
+
accountManagement: function accountManagement() {
|
|
2250
|
+
var accountUrl = kc.createAccountUrl();
|
|
2251
|
+
if (typeof accountUrl !== 'undefined') {
|
|
2252
|
+
window.cordova.plugins.browsertab.openUrl(accountUrl);
|
|
2253
|
+
} else {
|
|
2254
|
+
throw "Not supported by the OIDC server";
|
|
2255
|
+
}
|
|
2256
|
+
},
|
|
2257
|
+
redirectUri: function redirectUri(options) {
|
|
2258
|
+
if (options && options.redirectUri) {
|
|
2259
|
+
return options.redirectUri;
|
|
2260
|
+
} else if (kc.redirectUri) {
|
|
2261
|
+
return kc.redirectUri;
|
|
2262
|
+
} else {
|
|
2263
|
+
return "http://localhost";
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
throw 'invalid adapter type: ' + type;
|
|
2269
|
+
}
|
|
2270
|
+
var _LocalStorage = function LocalStorage() {
|
|
2271
|
+
if (!(this instanceof _LocalStorage)) {
|
|
2272
|
+
return new _LocalStorage();
|
|
2273
|
+
}
|
|
2274
|
+
localStorage.setItem('kc-test', 'test');
|
|
2275
|
+
localStorage.removeItem('kc-test');
|
|
2276
|
+
var cs = this;
|
|
2277
|
+
function clearExpired() {
|
|
2278
|
+
var time = new Date().getTime();
|
|
2279
|
+
for (var i = 0; i < localStorage.length; i++) {
|
|
2280
|
+
var key = localStorage.key(i);
|
|
2281
|
+
if (key && key.indexOf('kc-callback-') == 0) {
|
|
2282
|
+
var value = localStorage.getItem(key);
|
|
2283
|
+
if (value) {
|
|
2284
|
+
try {
|
|
2285
|
+
var expires = JSON.parse(value).expires;
|
|
2286
|
+
if (!expires || expires < time) {
|
|
2287
|
+
localStorage.removeItem(key);
|
|
2288
|
+
}
|
|
2289
|
+
} catch (err) {
|
|
2290
|
+
localStorage.removeItem(key);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
cs.get = function (state) {
|
|
2297
|
+
if (!state) {
|
|
2298
|
+
return;
|
|
2299
|
+
}
|
|
2300
|
+
var key = 'kc-callback-' + state;
|
|
2301
|
+
var value = localStorage.getItem(key);
|
|
2302
|
+
if (value) {
|
|
2303
|
+
localStorage.removeItem(key);
|
|
2304
|
+
value = JSON.parse(value);
|
|
2305
|
+
}
|
|
2306
|
+
clearExpired();
|
|
2307
|
+
return value;
|
|
2308
|
+
};
|
|
2309
|
+
cs.add = function (state) {
|
|
2310
|
+
clearExpired();
|
|
2311
|
+
var key = 'kc-callback-' + state.state;
|
|
2312
|
+
state.expires = new Date().getTime() + 60 * 60 * 1000;
|
|
2313
|
+
localStorage.setItem(key, JSON.stringify(state));
|
|
2314
|
+
};
|
|
2315
|
+
};
|
|
2316
|
+
var _CookieStorage = function CookieStorage() {
|
|
2317
|
+
if (!(this instanceof _CookieStorage)) {
|
|
2318
|
+
return new _CookieStorage();
|
|
2319
|
+
}
|
|
2320
|
+
var cs = this;
|
|
2321
|
+
cs.get = function (state) {
|
|
2322
|
+
if (!state) {
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
var value = getCookie('kc-callback-' + state);
|
|
2326
|
+
setCookie('kc-callback-' + state, '', cookieExpiration(-100));
|
|
2327
|
+
if (value) {
|
|
2328
|
+
return JSON.parse(value);
|
|
2329
|
+
}
|
|
2330
|
+
};
|
|
2331
|
+
cs.add = function (state) {
|
|
2332
|
+
setCookie('kc-callback-' + state.state, JSON.stringify(state), cookieExpiration(60));
|
|
2333
|
+
};
|
|
2334
|
+
cs.removeItem = function (key) {
|
|
2335
|
+
setCookie(key, '', cookieExpiration(-100));
|
|
2336
|
+
};
|
|
2337
|
+
var cookieExpiration = function cookieExpiration(minutes) {
|
|
2338
|
+
var exp = new Date();
|
|
2339
|
+
exp.setTime(exp.getTime() + minutes * 60 * 1000);
|
|
2340
|
+
return exp;
|
|
2341
|
+
};
|
|
2342
|
+
var getCookie = function getCookie(key) {
|
|
2343
|
+
var name = key + '=';
|
|
2344
|
+
var ca = document.cookie.split(';');
|
|
2345
|
+
for (var i = 0; i < ca.length; i++) {
|
|
2346
|
+
var c = ca[i];
|
|
2347
|
+
while (c.charAt(0) == ' ') {
|
|
2348
|
+
c = c.substring(1);
|
|
2349
|
+
}
|
|
2350
|
+
if (c.indexOf(name) == 0) {
|
|
2351
|
+
return c.substring(name.length, c.length);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
return '';
|
|
2355
|
+
};
|
|
2356
|
+
var setCookie = function setCookie(key, value, expirationDate) {
|
|
2357
|
+
var cookie = key + '=' + value + '; ' + 'expires=' + expirationDate.toUTCString() + '; ';
|
|
2358
|
+
document.cookie = cookie;
|
|
2359
|
+
};
|
|
2360
|
+
};
|
|
2361
|
+
function createCallbackStorage() {
|
|
2362
|
+
try {
|
|
2363
|
+
return new _LocalStorage();
|
|
2364
|
+
} catch (err) {}
|
|
2365
|
+
return new _CookieStorage();
|
|
2366
|
+
}
|
|
2367
|
+
function createLogger(fn) {
|
|
2368
|
+
return function () {
|
|
2369
|
+
if (kc.enableLogging) {
|
|
2370
|
+
fn.apply(console, Array.prototype.slice.call(arguments));
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
// See: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
|
|
2377
|
+
function bytesToBase64(bytes) {
|
|
2378
|
+
var binString = String.fromCodePoint.apply(String, _toConsumableArray(bytes));
|
|
2379
|
+
return btoa(binString);
|
|
2380
|
+
}
|
|
2381
|
+
return Keycloak;
|
|
2382
|
+
});
|