@opencampus/ocid-connect-js 1.2.5 → 2.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.
Files changed (45) hide show
  1. package/README.md +76 -3
  2. package/dist/ocid-connect-js.js +783 -128
  3. package/dist/ocid-connect-js.js.map +1 -1
  4. package/lib/index.d.ts +2 -0
  5. package/lib/react/LoginButton.d.ts +6 -0
  6. package/lib/react/LoginButton.js +1 -1
  7. package/lib/react/LoginCallBack.d.ts +7 -0
  8. package/lib/react/LoginCallBack.js +22 -9
  9. package/lib/react/OCConnect.d.ts +7 -0
  10. package/lib/react/OCConnect.js +7 -7
  11. package/lib/react/OCContext.d.ts +3 -0
  12. package/lib/react/OCSpinner.css +25 -0
  13. package/lib/react/OCSpinner.d.ts +6 -0
  14. package/lib/react/OCSpinner.js +39 -0
  15. package/lib/react/index.d.ts +4 -0
  16. package/lib/sdk/auth.d.ts +32 -0
  17. package/lib/sdk/auth.js +26 -19
  18. package/lib/sdk/crypto/base64.d.ts +5 -0
  19. package/lib/sdk/crypto/index.d.ts +3 -0
  20. package/lib/sdk/crypto/verifyToken.d.ts +1 -0
  21. package/lib/sdk/crypto/verifyToken.js +1 -1
  22. package/lib/sdk/crypto/webcrypto.d.ts +13 -0
  23. package/lib/sdk/endpoints/buildAuthEndpointUrl.d.ts +1 -0
  24. package/lib/sdk/endpoints/buildAuthEndpointUrl.js +8 -7
  25. package/lib/sdk/endpoints/index.d.ts +1 -0
  26. package/lib/sdk/index.d.ts +2 -0
  27. package/lib/sdk/lib/AuthInfoManager.d.ts +11 -0
  28. package/lib/sdk/lib/CookieStorageProvider.d.ts +8 -0
  29. package/lib/sdk/lib/CookieStorageProvider.js +16 -5
  30. package/lib/sdk/lib/StorageManager.d.ts +23 -0
  31. package/lib/sdk/lib/StorageManager.js +1 -1
  32. package/lib/sdk/lib/TokenManager.d.ts +16 -0
  33. package/lib/sdk/lib/TokenManager.js +2 -2
  34. package/lib/sdk/lib/TransactionManager.d.ts +9 -0
  35. package/lib/sdk/lib/index.d.ts +3 -0
  36. package/lib/sdk/lib/pkce.d.ts +11 -0
  37. package/lib/sdk/utils/createPkceMeta.d.ts +5 -0
  38. package/lib/sdk/utils/errors.d.ts +15 -0
  39. package/lib/sdk/utils/errors.js +2 -2
  40. package/lib/sdk/utils/index.d.ts +4 -0
  41. package/lib/sdk/utils/jwtParser.d.ts +1 -0
  42. package/lib/sdk/utils/prepareTokenParams.d.ts +9 -0
  43. package/lib/sdk/utils/prepareTokenParams.js +11 -10
  44. package/lib/sdk/utils/urlParser.d.ts +5 -0
  45. package/package.json +6 -2
@@ -0,0 +1,3 @@
1
+ export { default as TokenManager } from "./TokenManager";
2
+ export { default as TransactionManager } from "./TransactionManager";
3
+ export * from "./StorageManager";
@@ -0,0 +1,11 @@
1
+ export const MIN_VERIFIER_LENGTH: 43;
2
+ export const MAX_VERIFIER_LENGTH: 128;
3
+ export const DEFAULT_CODE_CHALLENGE_METHOD: "S256";
4
+ declare namespace _default {
5
+ export { DEFAULT_CODE_CHALLENGE_METHOD };
6
+ export { generateVerifier };
7
+ export { computeChallenge };
8
+ }
9
+ export default _default;
10
+ declare function generateVerifier(prefix: any): string;
11
+ declare function computeChallenge(str: any): Promise<any>;
@@ -0,0 +1,5 @@
1
+ export function createPkceMeta(signinParams: any): {
2
+ codeChallenge: any;
3
+ codeVerifier: any;
4
+ codeChallengeMethod: any;
5
+ };
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * Copyright 2024-Present Animoca Brands Corporation Ltd.
3
+ *
4
+ * 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:
5
+ *
6
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ *
8
+ * 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.
9
+ */
10
+ export class InternalError extends Error {
11
+ }
12
+ export class InvalidParamsError extends InternalError {
13
+ }
14
+ export class AuthError extends Error {
15
+ }
@@ -36,7 +36,7 @@ var InternalError = exports.InternalError = /*#__PURE__*/function (_Error) {
36
36
  }
37
37
  _inherits(InternalError, _Error);
38
38
  return _createClass(InternalError);
39
- }( /*#__PURE__*/_wrapNativeSuper(Error));
39
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
40
40
  var InvalidParamsError = exports.InvalidParamsError = /*#__PURE__*/function (_InternalError) {
41
41
  function InvalidParamsError() {
42
42
  _classCallCheck(this, InvalidParamsError);
@@ -52,4 +52,4 @@ var AuthError = exports.AuthError = /*#__PURE__*/function (_Error2) {
52
52
  }
53
53
  _inherits(AuthError, _Error2);
54
54
  return _createClass(AuthError);
55
- }( /*#__PURE__*/_wrapNativeSuper(Error));
55
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
@@ -0,0 +1,4 @@
1
+ export * from "./urlParser";
2
+ export * from "./prepareTokenParams";
3
+ export * from "./createPkceMeta";
4
+ export * from "./jwtParser";
@@ -0,0 +1 @@
1
+ export function parseJwt(token: any): any;
@@ -0,0 +1,9 @@
1
+ export function prepareTokenParams(params: any): Promise<{
2
+ clientId: any;
3
+ redirectUri: any;
4
+ codeVerifier: string;
5
+ codeChallenge: any;
6
+ codeChallengeMethod: string;
7
+ scope: string;
8
+ responseType: string;
9
+ }>;
@@ -11,17 +11,17 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
11
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
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
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.
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
21
  */
22
22
  var prepareTokenParams = exports.prepareTokenParams = /*#__PURE__*/function () {
23
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
24
- var redirectUri, state, codeVerifier, codeChallenge, tokenParams;
23
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
24
+ var clientId, redirectUri, state, codeVerifier, codeChallenge, tokenParams;
25
25
  return _regeneratorRuntime().wrap(function _callee$(_context) {
26
26
  while (1) switch (_context.prev = _context.next) {
27
27
  case 0:
@@ -29,7 +29,7 @@ var prepareTokenParams = exports.prepareTokenParams = /*#__PURE__*/function () {
29
29
  // mandatory redirect_uri, for now, we only allow user to set redirect_uri and state
30
30
  // again this is not a full on OIDC/OAuth flow allowing user to set all the options
31
31
  // we prepare all the rest
32
- redirectUri = params.redirectUri, state = params.state;
32
+ clientId = params.clientId, redirectUri = params.redirectUri, state = params.state;
33
33
  if (redirectUri) {
34
34
  _context.next = 3;
35
35
  break;
@@ -44,6 +44,7 @@ var prepareTokenParams = exports.prepareTokenParams = /*#__PURE__*/function () {
44
44
  codeChallenge = _context.sent;
45
45
  // pack up the full set of token params needed
46
46
  tokenParams = {
47
+ clientId: clientId,
47
48
  redirectUri: redirectUri,
48
49
  codeVerifier: codeVerifier,
49
50
  codeChallenge: codeChallenge,
@@ -0,0 +1,5 @@
1
+ export function parseUrl(): {
2
+ id_token: string;
3
+ code: string;
4
+ state: string;
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencampus/ocid-connect-js",
3
- "version": "1.2.5",
3
+ "version": "2.0.0",
4
4
  "author": "Animoca Brands",
5
5
  "license": "MIT",
6
6
  "description": "OCID Connector Library",
@@ -11,7 +11,8 @@
11
11
  ],
12
12
  "scripts": {
13
13
  "build-dev": "gulp clean && gulp copy && webpack",
14
- "lib": "babel ./src --out-dir ./lib",
14
+ "generate-types": "tsc --declaration --allowJs --emitDeclarationOnly",
15
+ "lib": "babel ./src --out-dir ./lib && cp ./src/react/*.css lib/react/ && yarn generate-types",
15
16
  "build": "NODE_OPTIONS=--openssl-legacy-provider npm run lib && NODE_OPTIONS=--openssl-legacy-provider gulp dist",
16
17
  "prepublishOnly": "npm run build",
17
18
  "lint": "eslint src",
@@ -27,6 +28,7 @@
27
28
  "@babel/preset-react": "^7.0.0",
28
29
  "@testing-library/react": "^13.3.0",
29
30
  "@testing-library/user-event": "^14.3.0",
31
+ "@types/node": "^22.10.3",
30
32
  "autoprefixer": "^7.1.2",
31
33
  "babel-core": "^7.0.0-bridge.0",
32
34
  "babel-loader": "^8.0.4",
@@ -50,6 +52,8 @@
50
52
  "react-dom": "^18.0.0",
51
53
  "sinon": "^2.1.0",
52
54
  "style-loader": "^0.16.1",
55
+ "typescript": "^5.7.2",
56
+ "typescript-json-schema": "^0.65.1",
53
57
  "uglifyjs-webpack-plugin": "^2.0.1",
54
58
  "webpack": "^4.21.0",
55
59
  "webpack-cli": "^3.1.2",