@opencampus/ocid-connect-js 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.
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ TokenManager: true,
8
+ TransactionManager: true
9
+ };
10
+ Object.defineProperty(exports, "TokenManager", {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _TokenManager["default"];
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "TransactionManager", {
17
+ enumerable: true,
18
+ get: function get() {
19
+ return _TransactionManager["default"];
20
+ }
21
+ });
22
+ var _TokenManager = _interopRequireDefault(require("./TokenManager"));
23
+ var _TransactionManager = _interopRequireDefault(require("./TransactionManager"));
24
+ var _StorageManager = require("./StorageManager");
25
+ Object.keys(_StorageManager).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _StorageManager[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function get() {
32
+ return _StorageManager[key];
33
+ }
34
+ });
35
+ });
36
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.MIN_VERIFIER_LENGTH = exports.MAX_VERIFIER_LENGTH = exports.DEFAULT_CODE_CHALLENGE_METHOD = void 0;
7
+ var _crypto = require("../crypto");
8
+ /*!
9
+ * Copyright 2024-Present Animoca Brands Corporation Ltd.
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ */
17
+ /* eslint-disable complexity, max-statements */
18
+
19
+ var MIN_VERIFIER_LENGTH = exports.MIN_VERIFIER_LENGTH = 43;
20
+ var MAX_VERIFIER_LENGTH = exports.MAX_VERIFIER_LENGTH = 128;
21
+ var DEFAULT_CODE_CHALLENGE_METHOD = exports.DEFAULT_CODE_CHALLENGE_METHOD = 'S256';
22
+ function dec2hex(dec) {
23
+ return ('0' + dec.toString(16)).substr(-2);
24
+ }
25
+ function getRandomString(length) {
26
+ var a = new Uint8Array(Math.ceil(length / 2));
27
+ _crypto.webcrypto.getRandomValues(a);
28
+ var str = Array.from(a, dec2hex).join('');
29
+ return str.slice(0, length);
30
+ }
31
+ function generateVerifier(prefix) {
32
+ var verifier = prefix || '';
33
+ if (verifier.length < MIN_VERIFIER_LENGTH) {
34
+ verifier = verifier + getRandomString(MIN_VERIFIER_LENGTH - verifier.length);
35
+ }
36
+ return encodeURIComponent(verifier).slice(0, MAX_VERIFIER_LENGTH);
37
+ }
38
+ function computeChallenge(str) {
39
+ var buffer = new TextEncoder().encode(str);
40
+ return _crypto.webcrypto.subtle.digest('SHA-256', buffer).then(function (arrayBuffer) {
41
+ var hash = String.fromCharCode.apply(null, new Uint8Array(arrayBuffer));
42
+ var b64u = (0, _crypto.stringToBase64Url)(hash); // url-safe base64 variant
43
+
44
+ return b64u;
45
+ });
46
+ }
47
+ var _default = exports["default"] = {
48
+ DEFAULT_CODE_CHALLENGE_METHOD: DEFAULT_CODE_CHALLENGE_METHOD,
49
+ generateVerifier: generateVerifier,
50
+ computeChallenge: computeChallenge
51
+ };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPkceMeta = void 0;
7
+ var _errors = require("./errors");
8
+ /*!
9
+ * Copyright 2024-Present Animoca Brands Corporation Ltd.
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ */
17
+
18
+ var createPkceMeta = exports.createPkceMeta = function createPkceMeta(signinParams) {
19
+ // prepare the meta that needs to be persisted in storage
20
+ // extracted from the signinParams
21
+ var codeChallenge = signinParams.codeChallenge,
22
+ codeVerifier = signinParams.codeVerifier,
23
+ codeChallengeMethod = signinParams.codeChallengeMethod;
24
+ if (!codeChallenge || !codeVerifier || !codeChallengeMethod) {
25
+ throw new _errors.InvalidParamsError('codeChallenge, codeVerifier & codeChallengeMethod are required');
26
+ }
27
+ return {
28
+ codeChallenge: codeChallenge,
29
+ codeVerifier: codeVerifier,
30
+ codeChallengeMethod: codeChallengeMethod
31
+ };
32
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.InvalidParamsError = exports.InternalError = exports.AuthError = void 0;
8
+ 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); } }
9
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
11
+ 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); }
12
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
13
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
14
+ 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); }
15
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
16
+ 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); }
17
+ 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); }
18
+ 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; }
19
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
20
+ function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
21
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
22
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
23
+ /*!
24
+ * Copyright 2024-Present Animoca Brands Corporation Ltd.
25
+ *
26
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
27
+ *
28
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
29
+ *
30
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
+ */
32
+ var InternalError = exports.InternalError = /*#__PURE__*/function (_Error) {
33
+ function InternalError() {
34
+ _classCallCheck(this, InternalError);
35
+ return _callSuper(this, InternalError, arguments);
36
+ }
37
+ _inherits(InternalError, _Error);
38
+ return _createClass(InternalError);
39
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
40
+ var InvalidParamsError = exports.InvalidParamsError = /*#__PURE__*/function (_InternalError) {
41
+ function InvalidParamsError() {
42
+ _classCallCheck(this, InvalidParamsError);
43
+ return _callSuper(this, InvalidParamsError, arguments);
44
+ }
45
+ _inherits(InvalidParamsError, _InternalError);
46
+ return _createClass(InvalidParamsError);
47
+ }(InternalError);
48
+ var AuthError = exports.AuthError = /*#__PURE__*/function (_Error2) {
49
+ function AuthError() {
50
+ _classCallCheck(this, AuthError);
51
+ return _callSuper(this, AuthError, arguments);
52
+ }
53
+ _inherits(AuthError, _Error2);
54
+ return _createClass(AuthError);
55
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _urlParser = require("./urlParser");
7
+ Object.keys(_urlParser).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _urlParser[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _urlParser[key];
14
+ }
15
+ });
16
+ });
17
+ var _prepareTokenParams = require("./prepareTokenParams");
18
+ Object.keys(_prepareTokenParams).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _prepareTokenParams[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _prepareTokenParams[key];
25
+ }
26
+ });
27
+ });
28
+ var _createPkceMeta = require("./createPkceMeta");
29
+ Object.keys(_createPkceMeta).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _createPkceMeta[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function get() {
35
+ return _createPkceMeta[key];
36
+ }
37
+ });
38
+ });
39
+ var _jwtParser = require("./jwtParser");
40
+ Object.keys(_jwtParser).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _jwtParser[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _jwtParser[key];
47
+ }
48
+ });
49
+ });
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseJwt = void 0;
7
+ /*!
8
+ * Copyright 2024-Present Animoca Brands Corporation Ltd.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ */
16
+
17
+ var parseJwt = exports.parseJwt = function parseJwt(token) {
18
+ var base64Url = token.split('.')[1];
19
+ var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
20
+ var jsonPayload = decodeURIComponent(window.atob(base64).split('').map(function (c) {
21
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
22
+ }).join(''));
23
+ return JSON.parse(jsonPayload);
24
+ };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.prepareTokenParams = void 0;
8
+ var _pkce = _interopRequireDefault(require("../lib/pkce"));
9
+ var _errors = require("./errors");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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
+ * Copyright 2024-Present Animoca Brands Corporation Ltd.
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ */
22
+ var prepareTokenParams = exports.prepareTokenParams = /*#__PURE__*/function () {
23
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
24
+ var redirectUri, state, codeVerifier, codeChallenge, tokenParams;
25
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
26
+ while (1) switch (_context.prev = _context.next) {
27
+ case 0:
28
+ // prepare all the params needed for building the signin flow
29
+ // mandatory redirect_uri, for now, we only allow user to set redirect_uri and state
30
+ // again this is not a full on OIDC/OAuth flow allowing user to set all the options
31
+ // we prepare all the rest
32
+ redirectUri = params.redirectUri, state = params.state;
33
+ if (redirectUri) {
34
+ _context.next = 3;
35
+ break;
36
+ }
37
+ throw new _errors.InvalidParamsError(' No redirect uri params!');
38
+ case 3:
39
+ // must be pkce
40
+ codeVerifier = _pkce["default"].generateVerifier();
41
+ _context.next = 6;
42
+ return _pkce["default"].computeChallenge(codeVerifier);
43
+ case 6:
44
+ codeChallenge = _context.sent;
45
+ // pack up the full set of token params needed
46
+ tokenParams = {
47
+ redirectUri: redirectUri,
48
+ codeVerifier: codeVerifier,
49
+ codeChallenge: codeChallenge,
50
+ codeChallengeMethod: _pkce["default"].DEFAULT_CODE_CHALLENGE_METHOD,
51
+ scope: 'openid',
52
+ responseType: 'code'
53
+ }; // just filter out undefined and null, honor other falsy states
54
+ if (state !== undefined && state !== null) {
55
+ tokenParams.state = state;
56
+ }
57
+ return _context.abrupt("return", tokenParams);
58
+ case 10:
59
+ case "end":
60
+ return _context.stop();
61
+ }
62
+ }, _callee);
63
+ }));
64
+ return function prepareTokenParams(_x) {
65
+ return _ref.apply(this, arguments);
66
+ };
67
+ }();
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseUrl = void 0;
7
+ /*!
8
+ * Copyright 2024-Present Animoca Brands Corporation Ltd.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ */
16
+ var parseUrl = exports.parseUrl = function parseUrl() {
17
+ var queryString = window.location.search;
18
+ var urlParams = new URLSearchParams(queryString);
19
+ var validParams = {};
20
+ if (urlParams.has('id_token')) validParams.id_token = urlParams.get('id_token');
21
+ if (urlParams.has('code')) validParams.code = urlParams.get('code');
22
+ if (urlParams.has('state')) validParams.state = urlParams.get('state');
23
+ return validParams;
24
+ };
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@opencampus/ocid-connect-js",
3
+ "version": "1.0.0",
4
+ "author": "Animoca Brands",
5
+ "license": "MIT",
6
+ "description": "OCID Connector Library",
7
+ "main": "./lib",
8
+ "files": [
9
+ "dist",
10
+ "lib"
11
+ ],
12
+ "scripts": {
13
+ "build-dev": "gulp clean && gulp copy && webpack",
14
+ "lib": "babel ./src --out-dir ./lib",
15
+ "build": "NODE_OPTIONS=--openssl-legacy-provider npm run lib && NODE_OPTIONS=--openssl-legacy-provider gulp dist",
16
+ "prepublishOnly": "npm run build",
17
+ "lint": "eslint src",
18
+ "precommit": "lint-staged"
19
+ },
20
+ "devDependencies": {
21
+ "@babel/cli": "^7.0.0",
22
+ "@babel/core": "^7.16.0",
23
+ "@babel/eslint-parser": "^7.16.3",
24
+ "@babel/plugin-proposal-class-properties": "^7.1.0",
25
+ "@babel/polyfill": "^7.0.0",
26
+ "@babel/preset-env": "^7.1.0",
27
+ "@babel/preset-react": "^7.0.0",
28
+ "@testing-library/react": "^13.3.0",
29
+ "@testing-library/user-event": "^14.3.0",
30
+ "autoprefixer": "^7.1.2",
31
+ "babel-core": "^7.0.0-bridge.0",
32
+ "babel-loader": "^8.0.4",
33
+ "babel-preset-airbnb": "^2.1.1",
34
+ "css-loader": "^2.1.1",
35
+ "deepmerge": "^1.1.0",
36
+ "del": "^2.2.2",
37
+ "es5-shim": "^4.5.9",
38
+ "eslint": "^8.4.1",
39
+ "eslint-plugin-import": "^2.25.3",
40
+ "eslint-plugin-react": "^7.27.1",
41
+ "gulp": "^4.0.0",
42
+ "js-beautify": "^1.7.5",
43
+ "json-loader": "^0.5.4",
44
+ "lint-staged": "^12.1.2",
45
+ "opn": "^5.4.0",
46
+ "postcss-loader": "^1.3.3",
47
+ "prettier": "^1.14.3",
48
+ "raf": "^3.4.0",
49
+ "react": "^18.0.0",
50
+ "react-dom": "^18.0.0",
51
+ "sinon": "^2.1.0",
52
+ "style-loader": "^0.16.1",
53
+ "uglifyjs-webpack-plugin": "^2.0.1",
54
+ "webpack": "^4.21.0",
55
+ "webpack-cli": "^3.1.2",
56
+ "regenerator-runtime": "^0.14.1"
57
+ },
58
+ "dependencies": {},
59
+ "peerDependencies": {
60
+ "react": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0",
61
+ "react-dom": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0"
62
+ },
63
+ "lint-staged": {
64
+ "*.{js,json,md}": [
65
+ "prettier --write",
66
+ "git add"
67
+ ]
68
+ },
69
+ "repository": {
70
+ "type": "git"
71
+ },
72
+ "npmName": "@opencampus/ocid-connect-js",
73
+ "npmFileMap": [
74
+ {
75
+ "basePath": "/dist/",
76
+ "files": [
77
+ "*.js"
78
+ ]
79
+ }
80
+ ]
81
+ }