@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.
- package/README.md +171 -0
- package/dist/ocid-connect-js.js +1738 -0
- package/dist/ocid-connect-js.js.map +1 -0
- package/lib/index.js +27 -0
- package/lib/react/LoginButton.js +125 -0
- package/lib/react/LoginCallBack.js +92 -0
- package/lib/react/OCConnect.js +66 -0
- package/lib/react/OCContext.js +24 -0
- package/lib/react/OCLogo.js +50 -0
- package/lib/react/index.js +44 -0
- package/lib/sdk/auth.js +225 -0
- package/lib/sdk/crypto/base64.js +46 -0
- package/lib/sdk/crypto/index.js +38 -0
- package/lib/sdk/crypto/verifyToken.js +63 -0
- package/lib/sdk/crypto/webcrypto.js +25 -0
- package/lib/sdk/endpoints/buildAuthEndpointUrl.js +32 -0
- package/lib/sdk/endpoints/index.js +16 -0
- package/lib/sdk/index.js +27 -0
- package/lib/sdk/lib/AuthInfoManager.js +55 -0
- package/lib/sdk/lib/StorageManager.js +118 -0
- package/lib/sdk/lib/TokenManager.js +164 -0
- package/lib/sdk/lib/TransactionManager.js +63 -0
- package/lib/sdk/lib/index.js +36 -0
- package/lib/sdk/lib/pkce.js +51 -0
- package/lib/sdk/utils/createPkceMeta.js +32 -0
- package/lib/sdk/utils/errors.js +55 -0
- package/lib/sdk/utils/index.js +49 -0
- package/lib/sdk/utils/jwtParser.js +24 -0
- package/lib/sdk/utils/prepareTokenParams.js +67 -0
- package/lib/sdk/utils/urlParser.js +24 -0
- package/package.json +81 -0
|
@@ -0,0 +1,92 @@
|
|
|
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["default"] = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _OCContext = require("./OCContext");
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
12
|
+
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; }
|
|
13
|
+
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); }
|
|
14
|
+
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); }); }; } /*!
|
|
15
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
16
|
+
*
|
|
17
|
+
* 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:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
20
|
+
*
|
|
21
|
+
* 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.
|
|
22
|
+
*/
|
|
23
|
+
var handledRedirect = false;
|
|
24
|
+
var LoginCallBack = function LoginCallBack(_ref) {
|
|
25
|
+
var successCallback = _ref.successCallback,
|
|
26
|
+
errorCallback = _ref.errorCallback,
|
|
27
|
+
customErrorComponent = _ref.customErrorComponent,
|
|
28
|
+
customLoadingComponent = _ref.customLoadingComponent;
|
|
29
|
+
var _useOCAuth = (0, _OCContext.useOCAuth)(),
|
|
30
|
+
ocAuth = _useOCAuth.ocAuth,
|
|
31
|
+
authState = _useOCAuth.authState,
|
|
32
|
+
updateAuthState = _useOCAuth.updateAuthState;
|
|
33
|
+
(0, _react.useEffect)(function () {
|
|
34
|
+
var handleLogin = /*#__PURE__*/function () {
|
|
35
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
36
|
+
var _authState;
|
|
37
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
38
|
+
while (1) switch (_context.prev = _context.next) {
|
|
39
|
+
case 0:
|
|
40
|
+
if (!ocAuth) {
|
|
41
|
+
_context.next = 12;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
_context.prev = 1;
|
|
45
|
+
_context.next = 4;
|
|
46
|
+
return ocAuth.handleLoginRedirect();
|
|
47
|
+
case 4:
|
|
48
|
+
_authState = _context.sent;
|
|
49
|
+
if (_authState.idToken) {
|
|
50
|
+
updateAuthState(_authState);
|
|
51
|
+
handledRedirect = true;
|
|
52
|
+
successCallback();
|
|
53
|
+
} else {
|
|
54
|
+
updateAuthState({
|
|
55
|
+
error: 'missing idToken from redirect callback'
|
|
56
|
+
});
|
|
57
|
+
if (errorCallback) {
|
|
58
|
+
errorCallback();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
_context.next = 12;
|
|
62
|
+
break;
|
|
63
|
+
case 8:
|
|
64
|
+
_context.prev = 8;
|
|
65
|
+
_context.t0 = _context["catch"](1);
|
|
66
|
+
updateAuthState({
|
|
67
|
+
error: _context.t0
|
|
68
|
+
});
|
|
69
|
+
if (errorCallback) {
|
|
70
|
+
errorCallback();
|
|
71
|
+
}
|
|
72
|
+
case 12:
|
|
73
|
+
case "end":
|
|
74
|
+
return _context.stop();
|
|
75
|
+
}
|
|
76
|
+
}, _callee, null, [[1, 8]]);
|
|
77
|
+
}));
|
|
78
|
+
return function handleLogin() {
|
|
79
|
+
return _ref2.apply(this, arguments);
|
|
80
|
+
};
|
|
81
|
+
}();
|
|
82
|
+
if (!handledRedirect) {
|
|
83
|
+
handleLogin();
|
|
84
|
+
}
|
|
85
|
+
}, [ocAuth]);
|
|
86
|
+
if (authState.error !== undefined && !errorCallback) {
|
|
87
|
+
return customErrorComponent ? customErrorComponent : /*#__PURE__*/_react["default"].createElement("div", null, "Error Logging in: ", authState.error.message);
|
|
88
|
+
} else {
|
|
89
|
+
return customLoadingComponent ? customLoadingComponent : /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("h3", null, "Loading ......"));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var _default = exports["default"] = LoginCallBack;
|
|
@@ -0,0 +1,66 @@
|
|
|
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["default"] = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _OCContext = require("./OCContext");
|
|
10
|
+
var _auth = require("../sdk/auth");
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
13
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
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; } }
|
|
16
|
+
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; }
|
|
17
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /*!
|
|
19
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
20
|
+
*
|
|
21
|
+
* 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:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* 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.
|
|
26
|
+
*/
|
|
27
|
+
var OCConnect = function OCConnect(_ref) {
|
|
28
|
+
var children = _ref.children,
|
|
29
|
+
opts = _ref.opts,
|
|
30
|
+
sandboxMode = _ref.sandboxMode;
|
|
31
|
+
var _useState = (0, _react.useState)({}),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
ocAuth = _useState2[0],
|
|
34
|
+
setOcAuth = _useState2[1];
|
|
35
|
+
var _useState3 = (0, _react.useState)({
|
|
36
|
+
isAuthenticated: false
|
|
37
|
+
}),
|
|
38
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
39
|
+
authState = _useState4[0],
|
|
40
|
+
setAuthState = _useState4[1];
|
|
41
|
+
(0, _react.useEffect)(function () {
|
|
42
|
+
var authSdk = sandboxMode ? new _auth.OCAuthSandbox(opts) : new _auth.OCAuthLive(opts);
|
|
43
|
+
setOcAuth(authSdk);
|
|
44
|
+
updateAuthState(authSdk.getAuthState());
|
|
45
|
+
}, []);
|
|
46
|
+
var updateAuthState = function updateAuthState(authState) {
|
|
47
|
+
var accessToken = authState.accessToken,
|
|
48
|
+
idToken = authState.idToken,
|
|
49
|
+
isAuthenticated = authState.isAuthenticated,
|
|
50
|
+
error = authState.error;
|
|
51
|
+
setAuthState({
|
|
52
|
+
accessToken: accessToken,
|
|
53
|
+
idToken: idToken,
|
|
54
|
+
isAuthenticated: isAuthenticated,
|
|
55
|
+
error: error
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return /*#__PURE__*/_react["default"].createElement(_OCContext.OCContext.Provider, {
|
|
59
|
+
value: {
|
|
60
|
+
ocAuth: ocAuth,
|
|
61
|
+
authState: authState,
|
|
62
|
+
updateAuthState: updateAuthState
|
|
63
|
+
}
|
|
64
|
+
}, children);
|
|
65
|
+
};
|
|
66
|
+
var _default = exports["default"] = OCConnect;
|
|
@@ -0,0 +1,24 @@
|
|
|
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.useOCAuth = exports.OCContext = void 0;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
11
|
+
/*!
|
|
12
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
13
|
+
*
|
|
14
|
+
* 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:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* 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.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var OCContext = exports.OCContext = /*#__PURE__*/React.createContext(null);
|
|
22
|
+
var useOCAuth = exports.useOCAuth = function useOCAuth() {
|
|
23
|
+
return React.useContext(OCContext);
|
|
24
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = OCLogo;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
+
/*!
|
|
10
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
11
|
+
*
|
|
12
|
+
* 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:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* 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.
|
|
17
|
+
*/
|
|
18
|
+
/* eslint-disable react/no-unknown-property */
|
|
19
|
+
|
|
20
|
+
function OCLogo(_ref) {
|
|
21
|
+
var _ref$width = _ref.width,
|
|
22
|
+
width = _ref$width === void 0 ? "26px" : _ref$width,
|
|
23
|
+
_ref$height = _ref.height,
|
|
24
|
+
height = _ref$height === void 0 ? "25px" : _ref$height,
|
|
25
|
+
_ref$style = _ref.style,
|
|
26
|
+
style = _ref$style === void 0 ? {
|
|
27
|
+
width: "26px",
|
|
28
|
+
height: "26px"
|
|
29
|
+
} : _ref$style;
|
|
30
|
+
return /*#__PURE__*/_react["default"].createElement("svg", {
|
|
31
|
+
width: width,
|
|
32
|
+
height: height,
|
|
33
|
+
viewBox: "0 0 26 25",
|
|
34
|
+
fill: "none",
|
|
35
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
36
|
+
style: style
|
|
37
|
+
}, /*#__PURE__*/_react["default"].createElement("path", {
|
|
38
|
+
d: "M13.1121 0.205309C10.687 0.234799 8.3251 0.963632 6.32343 2.30007C4.32176 3.63651 2.76977 5.5209 1.86266 7.71614C0.955549 9.91138 0.73387 12.3194 1.2255 14.6373C1.71713 16.9552 2.90007 19.0794 4.62559 20.7427C6.3511 22.406 8.54206 23.5342 10.9228 23.9851C13.3036 24.4361 15.7679 24.1897 18.0056 23.2771C20.2433 22.3645 22.1545 20.8264 23.4987 18.8562C24.8429 16.886 25.5602 14.5718 25.5602 12.2048C25.5396 9.00246 24.2166 5.93922 21.8821 3.68892C19.5477 1.43862 16.393 0.185527 13.1121 0.205309Z",
|
|
39
|
+
fill: "#00EDBE"
|
|
40
|
+
}), /*#__PURE__*/_react["default"].createElement("path", {
|
|
41
|
+
d: "M18.0322 7.7674C17.9989 7.16737 18.1488 6.5712 18.463 6.05445H8.42848C8.33855 6.05413 8.24944 6.07111 8.16623 6.10441C8.08302 6.13771 8.00734 6.18668 7.94352 6.24852C7.8797 6.31036 7.829 6.38387 7.79428 6.46484C7.75957 6.54581 7.74153 6.63267 7.74121 6.72044V8.81396C7.74153 8.90173 7.75957 8.98858 7.79428 9.06956C7.829 9.15053 7.8797 9.22404 7.94352 9.28588C8.00734 9.34772 8.08302 9.39669 8.16623 9.42999C8.24944 9.46329 8.33855 9.48027 8.42848 9.47995H18.463C18.1488 8.9632 17.9989 8.36743 18.0322 7.7674Z",
|
|
42
|
+
fill: "#141BEB"
|
|
43
|
+
}), /*#__PURE__*/_react["default"].createElement("path", {
|
|
44
|
+
d: "M6.17665 12.2379C6.20939 12.8379 6.05886 13.4339 5.74414 13.9504H15.7787C15.8686 13.9507 15.9578 13.9338 16.041 13.9005C16.1242 13.8672 16.1998 13.8182 16.2637 13.7563C16.3275 13.6945 16.3782 13.621 16.4129 13.54C16.4476 13.459 16.4656 13.3722 16.466 13.2844V11.1909C16.4656 11.1031 16.4476 11.0163 16.4129 10.9353C16.3782 10.8543 16.3275 10.7808 16.2637 10.719C16.1998 10.6571 16.1242 10.6082 16.041 10.5749C15.9578 10.5416 15.8686 10.5246 15.7787 10.5249H5.74414C6.05836 11.0417 6.20832 11.6378 6.17501 12.2379",
|
|
45
|
+
fill: "#141BEB"
|
|
46
|
+
}), /*#__PURE__*/_react["default"].createElement("path", {
|
|
47
|
+
d: "M18.0322 16.7086C17.9989 16.1085 18.1488 15.5124 18.463 14.9956H8.42848C8.33855 14.9953 8.24944 15.0123 8.16623 15.0456C8.08302 15.0789 8.00734 15.1278 7.94352 15.1897C7.8797 15.2515 7.829 15.325 7.79428 15.406C7.75957 15.487 7.74153 15.5738 7.74121 15.6616V17.7551C7.74153 17.8429 7.75957 17.9297 7.79428 18.0107C7.829 18.0917 7.8797 18.1652 7.94352 18.227C8.00734 18.2889 8.08302 18.3379 8.16623 18.3712C8.24944 18.4045 8.33855 18.4214 8.42848 18.4211H18.463C18.1488 17.9044 17.9989 17.3082 18.0322 16.7082",
|
|
48
|
+
fill: "#141BEB"
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
LoginButton: true,
|
|
8
|
+
LoginCallBack: true,
|
|
9
|
+
OCConnect: true
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "LoginButton", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function get() {
|
|
14
|
+
return _LoginButton["default"];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "LoginCallBack", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function get() {
|
|
20
|
+
return _LoginCallBack["default"];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "OCConnect", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function get() {
|
|
26
|
+
return _OCConnect["default"];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var _LoginButton = _interopRequireDefault(require("./LoginButton"));
|
|
30
|
+
var _LoginCallBack = _interopRequireDefault(require("./LoginCallBack"));
|
|
31
|
+
var _OCConnect = _interopRequireDefault(require("./OCConnect"));
|
|
32
|
+
var _OCContext = require("./OCContext");
|
|
33
|
+
Object.keys(_OCContext).forEach(function (key) {
|
|
34
|
+
if (key === "default" || key === "__esModule") return;
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
36
|
+
if (key in exports && exports[key] === _OCContext[key]) return;
|
|
37
|
+
Object.defineProperty(exports, key, {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function get() {
|
|
40
|
+
return _OCContext[key];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
package/lib/sdk/auth.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OCAuthSandbox = exports.OCAuthLive = exports.OCAuthCore = void 0;
|
|
7
|
+
var _AuthInfoManager = _interopRequireDefault(require("./lib/AuthInfoManager"));
|
|
8
|
+
var _TokenManager = _interopRequireDefault(require("./lib/TokenManager"));
|
|
9
|
+
var _TransactionManager = _interopRequireDefault(require("./lib/TransactionManager"));
|
|
10
|
+
var _StorageManager = require("./lib/StorageManager");
|
|
11
|
+
var _utils = require("./utils");
|
|
12
|
+
var _endpoints = require("./endpoints");
|
|
13
|
+
var _errors = require("./utils/errors");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
15
|
+
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); }
|
|
16
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
17
|
+
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); }
|
|
18
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
19
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
20
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
21
|
+
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); }
|
|
22
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
23
|
+
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; }
|
|
24
|
+
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); }
|
|
25
|
+
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); }); }; }
|
|
26
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
27
|
+
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); } }
|
|
28
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
29
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
30
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
31
|
+
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); } /*!
|
|
32
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
33
|
+
*
|
|
34
|
+
* 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:
|
|
35
|
+
*
|
|
36
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
37
|
+
*
|
|
38
|
+
* 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.
|
|
39
|
+
*/
|
|
40
|
+
var OCAuthCore = exports.OCAuthCore = /*#__PURE__*/function () {
|
|
41
|
+
function OCAuthCore(loginEndpoint, redirectUri, transactionManager, tokenManager) {
|
|
42
|
+
_classCallCheck(this, OCAuthCore);
|
|
43
|
+
_defineProperty(this, "tokenManager", void 0);
|
|
44
|
+
_defineProperty(this, "authInfoManager", void 0);
|
|
45
|
+
_defineProperty(this, "transactionManager", void 0);
|
|
46
|
+
_defineProperty(this, "redirectUri", void 0);
|
|
47
|
+
_defineProperty(this, "loginEndPoint", void 0);
|
|
48
|
+
this.transactionManager = transactionManager;
|
|
49
|
+
this.tokenManager = tokenManager;
|
|
50
|
+
this.authInfoManager = new _AuthInfoManager["default"]();
|
|
51
|
+
this.loginEndPoint = loginEndpoint;
|
|
52
|
+
this.redirectUri = redirectUri;
|
|
53
|
+
this.syncAuthInfo();
|
|
54
|
+
}
|
|
55
|
+
return _createClass(OCAuthCore, [{
|
|
56
|
+
key: "clearStorage",
|
|
57
|
+
value: function clearStorage() {
|
|
58
|
+
this.transactionManager.clearStorage();
|
|
59
|
+
this.tokenManager.clear();
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "signInWithRedirect",
|
|
63
|
+
value: function () {
|
|
64
|
+
var _signInWithRedirect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
65
|
+
var paramsClone, signinParams, meta, requestUrl;
|
|
66
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
67
|
+
while (1) switch (_context.prev = _context.next) {
|
|
68
|
+
case 0:
|
|
69
|
+
// we use ONLY code flow with PKCE, so lacks a lot of options
|
|
70
|
+
// available in other OAuth SDKs.
|
|
71
|
+
paramsClone = Object.assign({}, params);
|
|
72
|
+
paramsClone.redirectUri = this.redirectUri;
|
|
73
|
+
_context.next = 4;
|
|
74
|
+
return (0, _utils.prepareTokenParams)(paramsClone);
|
|
75
|
+
case 4:
|
|
76
|
+
signinParams = _context.sent;
|
|
77
|
+
meta = (0, _utils.createPkceMeta)(signinParams);
|
|
78
|
+
this.transactionManager.save(meta);
|
|
79
|
+
requestUrl = (0, _endpoints.buildAuthEndpointUrl)(signinParams, this.loginEndPoint);
|
|
80
|
+
window.location.assign(requestUrl);
|
|
81
|
+
case 9:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context.stop();
|
|
84
|
+
}
|
|
85
|
+
}, _callee, this);
|
|
86
|
+
}));
|
|
87
|
+
function signInWithRedirect(_x) {
|
|
88
|
+
return _signInWithRedirect.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
return signInWithRedirect;
|
|
91
|
+
}()
|
|
92
|
+
}, {
|
|
93
|
+
key: "handleLoginRedirect",
|
|
94
|
+
value: function () {
|
|
95
|
+
var _handleLoginRedirect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
96
|
+
var urlParams, meta, codeVerifier;
|
|
97
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
98
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
99
|
+
case 0:
|
|
100
|
+
urlParams = (0, _utils.parseUrl)(); // Again we only handle PKCE code flow
|
|
101
|
+
if (!urlParams.code) {
|
|
102
|
+
_context2.next = 13;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
meta = this.transactionManager.getTransactionMeta();
|
|
106
|
+
codeVerifier = meta.codeVerifier;
|
|
107
|
+
if (!codeVerifier) {
|
|
108
|
+
_context2.next = 12;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
_context2.next = 7;
|
|
112
|
+
return this.tokenManager.exchangeTokenFromCode(urlParams.code, codeVerifier);
|
|
113
|
+
case 7:
|
|
114
|
+
// clear transaction meta, coz it's completed
|
|
115
|
+
this.transactionManager.clear();
|
|
116
|
+
this.syncAuthInfo();
|
|
117
|
+
return _context2.abrupt("return", this.getAuthState());
|
|
118
|
+
case 12:
|
|
119
|
+
throw new _errors.AuthError('codeVerifier not found, cannot complete flow');
|
|
120
|
+
case 13:
|
|
121
|
+
return _context2.abrupt("return", {});
|
|
122
|
+
case 14:
|
|
123
|
+
case "end":
|
|
124
|
+
return _context2.stop();
|
|
125
|
+
}
|
|
126
|
+
}, _callee2, this);
|
|
127
|
+
}));
|
|
128
|
+
function handleLoginRedirect() {
|
|
129
|
+
return _handleLoginRedirect.apply(this, arguments);
|
|
130
|
+
}
|
|
131
|
+
return handleLoginRedirect;
|
|
132
|
+
}()
|
|
133
|
+
}, {
|
|
134
|
+
key: "isAuthenticated",
|
|
135
|
+
value: function isAuthenticated() {
|
|
136
|
+
// if both token exist and not expired
|
|
137
|
+
return !this.tokenManager.hasExpired();
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
key: "syncAuthInfo",
|
|
141
|
+
value: function syncAuthInfo() {
|
|
142
|
+
if (this.tokenManager.hasExpired()) {
|
|
143
|
+
this.authInfoManager.clear();
|
|
144
|
+
} else {
|
|
145
|
+
var idToken = this.tokenManager.getIdToken();
|
|
146
|
+
var _parseJwt = (0, _utils.parseJwt)(idToken),
|
|
147
|
+
edu_username = _parseJwt.edu_username,
|
|
148
|
+
eth_address = _parseJwt.eth_address;
|
|
149
|
+
this.authInfoManager.setIdInfo({
|
|
150
|
+
edu_username: edu_username,
|
|
151
|
+
eth_address: eth_address
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "getAuthState",
|
|
157
|
+
value: function getAuthState() {
|
|
158
|
+
var authState = {
|
|
159
|
+
accessToken: this.getAccessToken(),
|
|
160
|
+
idToken: this.getIdToken(),
|
|
161
|
+
isAuthenticated: this.isAuthenticated()
|
|
162
|
+
};
|
|
163
|
+
return authState;
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: "getAuthInfo",
|
|
167
|
+
value: function getAuthInfo() {
|
|
168
|
+
return this.authInfoManager.getAuthInfo();
|
|
169
|
+
}
|
|
170
|
+
}, {
|
|
171
|
+
key: "getIdToken",
|
|
172
|
+
value: function getIdToken() {
|
|
173
|
+
return this.tokenManager.getIdToken();
|
|
174
|
+
}
|
|
175
|
+
}, {
|
|
176
|
+
key: "getAccessToken",
|
|
177
|
+
value: function getAccessToken() {
|
|
178
|
+
return this.tokenManager.getAccessToken();
|
|
179
|
+
}
|
|
180
|
+
}]);
|
|
181
|
+
}();
|
|
182
|
+
var OCAuthLS = /*#__PURE__*/function (_OCAuthCore2) {
|
|
183
|
+
function OCAuthLS(loginEndPoint, tokenEndpoint, redirectUri, publicKey) {
|
|
184
|
+
_classCallCheck(this, OCAuthLS);
|
|
185
|
+
var pkceTransactionManager = new _TransactionManager["default"](_StorageManager.LocalStorageManager);
|
|
186
|
+
var tokenManager = new _TokenManager["default"](_StorageManager.LocalStorageManager, tokenEndpoint, publicKey);
|
|
187
|
+
return _callSuper(this, OCAuthLS, [loginEndPoint, redirectUri, pkceTransactionManager, tokenManager]);
|
|
188
|
+
}
|
|
189
|
+
_inherits(OCAuthLS, _OCAuthCore2);
|
|
190
|
+
return _createClass(OCAuthLS);
|
|
191
|
+
}(OCAuthCore);
|
|
192
|
+
var LIVE_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBIDHtLbgVM76SXZ4iuIjuO+ERQPnVpJzagOsZdYxFG3ZJmvfdpr/Z29SLUbdZWafrOlAVlKe1Ovf/tcH671tTw==';
|
|
193
|
+
var SANDBOX_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/EymMLXd/MVYPK5r2xXQj91ZVvX3OQ+QagvR2N6lCvRVjnzmOtPRTf+u5g1RliWnmuxbV3gTm0/0VuV/40Salg==';
|
|
194
|
+
var OCAuthLive = exports.OCAuthLive = /*#__PURE__*/function (_OCAuthLS) {
|
|
195
|
+
function OCAuthLive() {
|
|
196
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
197
|
+
_classCallCheck(this, OCAuthLive);
|
|
198
|
+
var overrideTokenEndpoint = opts.tokenEndPoint,
|
|
199
|
+
overrideLoginEndpoint = opts.loginEndPoint,
|
|
200
|
+
overridePublicKey = opts.publicKey,
|
|
201
|
+
redirectUri = opts.redirectUri;
|
|
202
|
+
var tokenEndpoint = overrideTokenEndpoint || 'https://api.login.opencampus.xyz/auth/token';
|
|
203
|
+
var loginEndpoint = overrideLoginEndpoint || 'https://api.login.opencampus.xyz/auth/login';
|
|
204
|
+
var publicKey = overridePublicKey || LIVE_PUBLIC_KEY;
|
|
205
|
+
return _callSuper(this, OCAuthLive, [loginEndpoint, tokenEndpoint, redirectUri, publicKey]);
|
|
206
|
+
}
|
|
207
|
+
_inherits(OCAuthLive, _OCAuthLS);
|
|
208
|
+
return _createClass(OCAuthLive);
|
|
209
|
+
}(OCAuthLS);
|
|
210
|
+
var OCAuthSandbox = exports.OCAuthSandbox = /*#__PURE__*/function (_OCAuthLS2) {
|
|
211
|
+
function OCAuthSandbox() {
|
|
212
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
213
|
+
_classCallCheck(this, OCAuthSandbox);
|
|
214
|
+
var overrideTokenEndpoint = opts.tokenEndPoint,
|
|
215
|
+
overrideLoginEndpoint = opts.loginEndPoint,
|
|
216
|
+
overridePublicKey = opts.publicKey,
|
|
217
|
+
redirectUri = opts.redirectUri;
|
|
218
|
+
var tokenEndpoint = overrideTokenEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/token';
|
|
219
|
+
var loginEndpoint = overrideLoginEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/login';
|
|
220
|
+
var publicKey = overridePublicKey || SANDBOX_PUBLIC_KEY;
|
|
221
|
+
return _callSuper(this, OCAuthSandbox, [loginEndpoint, tokenEndpoint, redirectUri, publicKey]);
|
|
222
|
+
}
|
|
223
|
+
_inherits(OCAuthSandbox, _OCAuthLS2);
|
|
224
|
+
return _createClass(OCAuthSandbox);
|
|
225
|
+
}(OCAuthLS);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.base64ToBase64Url = base64ToBase64Url;
|
|
7
|
+
exports.base64UrlDecode = base64UrlDecode;
|
|
8
|
+
exports.base64UrlToBase64 = base64UrlToBase64;
|
|
9
|
+
exports.stringToBase64Url = stringToBase64Url;
|
|
10
|
+
exports.stringToBuffer = stringToBuffer;
|
|
11
|
+
var _webcrypto = require("./webcrypto");
|
|
12
|
+
/*!
|
|
13
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
14
|
+
*
|
|
15
|
+
* 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:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* 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.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// converts a standard base64-encoded string to a "url/filename safe" variant
|
|
23
|
+
function base64ToBase64Url(b64) {
|
|
24
|
+
return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// converts a "url/filename safe" base64 string to a "standard" base64 string
|
|
28
|
+
function base64UrlToBase64(b64u) {
|
|
29
|
+
return b64u.replace(/-/g, '+').replace(/_/g, '/');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// converts a string to base64 (url/filename safe variant)
|
|
33
|
+
function stringToBase64Url(str) {
|
|
34
|
+
var b64 = (0, _webcrypto.btoa)(str);
|
|
35
|
+
return base64ToBase64Url(b64);
|
|
36
|
+
}
|
|
37
|
+
function stringToBuffer(str) {
|
|
38
|
+
var buffer = new Uint8Array(str.length);
|
|
39
|
+
for (var i = 0; i < str.length; i++) {
|
|
40
|
+
buffer[i] = str.charCodeAt(i);
|
|
41
|
+
}
|
|
42
|
+
return buffer;
|
|
43
|
+
}
|
|
44
|
+
function base64UrlDecode(str) {
|
|
45
|
+
return (0, _webcrypto.atob)(base64UrlToBase64(str));
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _webcrypto = require("./webcrypto");
|
|
7
|
+
Object.keys(_webcrypto).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _webcrypto[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _webcrypto[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _base = require("./base64");
|
|
18
|
+
Object.keys(_base).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _base[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _base[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _verifyToken = require("./verifyToken");
|
|
29
|
+
Object.keys(_verifyToken).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _verifyToken[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _verifyToken[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|