authscape 1.0.370 → 1.0.372

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/index.js CHANGED
@@ -6,17 +6,20 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.AuthScapeApp = AuthScapeApp;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
10
- var _Backdrop = _interopRequireDefault(require("@mui/material/Backdrop"));
11
9
  var _reactToastify = require("react-toastify");
12
10
  var _styles = require("@mui/material/styles");
13
- var _material = require("@mui/material");
14
11
  var _head = _interopRequireDefault(require("next/head"));
15
12
  var _navigation = require("next/navigation");
13
+ var _axios = _interopRequireDefault(require("axios"));
14
+ var _queryString = _interopRequireDefault(require("query-string"));
15
+ var _nookies = require("nookies");
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
19
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
20
+ 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
21
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
22
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
20
23
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
24
  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."); }
22
25
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -25,118 +28,169 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
25
28
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
26
29
  function AuthScapeApp(_ref) {
27
30
  var Component = _ref.Component,
31
+ layout = _ref.layout,
28
32
  pageProps = _ref.pageProps,
29
33
  _ref$muiTheme = _ref.muiTheme,
30
34
  muiTheme = _ref$muiTheme === void 0 ? {} : _ref$muiTheme,
31
35
  _ref$enforceLoggedIn = _ref.enforceLoggedIn,
32
36
  enforceLoggedIn = _ref$enforceLoggedIn === void 0 ? false : _ref$enforceLoggedIn,
33
37
  _ref$enableAuth = _ref.enableAuth,
34
- enableAuth = _ref$enableAuth === void 0 ? true : _ref$enableAuth,
35
- _ref$onAuthentication = _ref.onAuthenticationLoaded,
36
- onAuthenticationLoaded = _ref$onAuthentication === void 0 ? null : _ref$onAuthentication,
37
- _ref$children = _ref.children,
38
- children = _ref$children === void 0 ? null : _ref$children;
38
+ enableAuth = _ref$enableAuth === void 0 ? true : _ref$enableAuth;
39
39
  var _useState = (0, _react.useState)(false),
40
40
  _useState2 = _slicedToArray(_useState, 2),
41
- isLoading = _useState2[0],
42
- setIsLoading = _useState2[1];
43
- var _useState3 = (0, _react.useState)(false),
44
- _useState4 = _slicedToArray(_useState3, 2),
45
- loadedUser = _useState4[0],
46
- setLoadedUser = _useState4[1];
47
- var _useState5 = (0, _react.useState)(null),
48
- _useState6 = _slicedToArray(_useState5, 2),
49
- currentUser = _useState6[0],
50
- setCurrentUser = _useState6[1];
51
- var _useState7 = (0, _react.useState)(false),
52
- _useState8 = _slicedToArray(_useState7, 2),
53
- loadingLogin = _useState8[0],
54
- setLoadingLogin = _useState8[1];
55
- var validateCode = function validateCode() {
56
- if (queryCode != null) {
57
- setLoadingLogin(true);
58
- signInValidator(queryCode);
59
- } else {
60
- if (enforceLoggedIn) {
61
- if (currentUser == null) {
62
- authService().login();
63
- }
64
- }
65
- }
66
- };
41
+ frontEndLoadedState = _useState2[0],
42
+ setFrontEndLoadedState = _useState2[1];
43
+ var loadingAuth = (0, _react.useRef)(false);
44
+ var frontEndLoaded = (0, _react.useRef)(false);
45
+ var signedInUser = (0, _react.useRef)(null);
46
+ var queryCodeUsed = (0, _react.useRef)(null);
67
47
  var searchParams = (0, _navigation.useSearchParams)();
68
48
  var queryRef = searchParams.get('ref');
69
49
  var queryCode = searchParams.get('code');
70
- validateCode(queryCode);
71
-
72
- // const router = useRouter();
73
-
74
- // useEffect(() => {
75
-
76
- // if (loadedUser && router.isReady)
77
- // {
78
- // if (process.env.googleAnalytics4 != null)
79
- // {
80
- // init(process.env.googleAnalytics4);
81
- // }
82
-
83
- // if (queryRef != null)
84
- // {
85
- // localStorage.setItem("ref", queryRef);
86
- // }
87
-
88
- // // sign in validation
89
- // if (queryCode != null)
90
- // {
91
- // setLoadingLogin(true);
92
- // signInValidator(queryCode);
93
- // }
94
- // else
95
- // {
96
- // if (enforceLoggedIn)
97
- // {
98
- // if (currentUser == null)
99
- // {
100
- // authService().login();
101
- // }
102
- // }
103
- // }
104
- // }
105
-
106
- // }, [loadedUser, router.isReady])
107
-
50
+ var pathname = (0, _navigation.usePathname)();
51
+ var signInValidator = /*#__PURE__*/function () {
52
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(queryCode) {
53
+ var codeVerifier, headers, queryString, response, domainHost, redirectUri;
54
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
55
+ while (1) switch (_context.prev = _context.next) {
56
+ case 0:
57
+ if (!(queryCodeUsed.current != queryCode)) {
58
+ _context.next = 4;
59
+ break;
60
+ }
61
+ queryCodeUsed.current = queryCode;
62
+ _context.next = 5;
63
+ break;
64
+ case 4:
65
+ return _context.abrupt("return");
66
+ case 5:
67
+ codeVerifier = window.localStorage.getItem("verifier");
68
+ if (!(queryCode != null && codeVerifier != null)) {
69
+ _context.next = 28;
70
+ break;
71
+ }
72
+ headers = {
73
+ 'Content-Type': 'application/x-www-form-urlencoded'
74
+ };
75
+ queryString = _queryString["default"].stringify({
76
+ code: queryCode,
77
+ grant_type: "authorization_code",
78
+ redirect_uri: window.location.origin + "/signin-oidc",
79
+ client_id: process.env.client_id,
80
+ client_secret: process.env.client_secret,
81
+ code_verifier: codeVerifier
82
+ });
83
+ _context.prev = 9;
84
+ _context.next = 12;
85
+ return _axios["default"].post(process.env.authorityUri + '/connect/token', queryString, {
86
+ headers: headers
87
+ });
88
+ case 12:
89
+ response = _context.sent;
90
+ domainHost = window.location.hostname.split('.').slice(-2).join('.');
91
+ window.localStorage.removeItem("verifier");
92
+ _context.next = 17;
93
+ return (0, _nookies.setCookie)(null, "access_token", response.data.access_token, {
94
+ maxAge: 2147483647,
95
+ path: '/',
96
+ domain: domainHost,
97
+ secure: true
98
+ });
99
+ case 17:
100
+ _context.next = 19;
101
+ return (0, _nookies.setCookie)(null, "expires_in", response.data.expires_in, {
102
+ maxAge: 2147483647,
103
+ path: '/',
104
+ domain: domainHost,
105
+ secure: true
106
+ });
107
+ case 19:
108
+ _context.next = 21;
109
+ return (0, _nookies.setCookie)(null, "refresh_token", response.data.refresh_token, {
110
+ maxAge: 2147483647,
111
+ path: '/',
112
+ domain: domainHost,
113
+ secure: true
114
+ });
115
+ case 21:
116
+ redirectUri = localStorage.getItem("redirectUri");
117
+ localStorage.clear();
118
+ if (redirectUri != null) {
119
+ window.location.href = redirectUri;
120
+ } else {
121
+ window.location.href = "/";
122
+ }
123
+ _context.next = 28;
124
+ break;
125
+ case 26:
126
+ _context.prev = 26;
127
+ _context.t0 = _context["catch"](9);
128
+ case 28:
129
+ case "end":
130
+ return _context.stop();
131
+ }
132
+ }, _callee, null, [[9, 26]]);
133
+ }));
134
+ return function signInValidator(_x2) {
135
+ return _ref2.apply(this, arguments);
136
+ };
137
+ }();
138
+ var validateUserSignedIn = /*#__PURE__*/function () {
139
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
140
+ var usr;
141
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
142
+ while (1) switch (_context2.prev = _context2.next) {
143
+ case 0:
144
+ loadingAuth.current = true;
145
+ if (!enableAuth) {
146
+ _context2.next = 6;
147
+ break;
148
+ }
149
+ _context2.next = 4;
150
+ return apiService().GetCurrentUser();
151
+ case 4:
152
+ usr = _context2.sent;
153
+ if (usr != null) {
154
+ signedInUser.current = usr;
155
+ }
156
+ case 6:
157
+ setFrontEndLoadedState(true);
158
+ frontEndLoaded.current = true;
159
+ case 8:
160
+ case "end":
161
+ return _context2.stop();
162
+ }
163
+ }, _callee2);
164
+ }));
165
+ return function validateUserSignedIn() {
166
+ return _ref3.apply(this, arguments);
167
+ };
168
+ }();
169
+ if (queryCode != null) {
170
+ signInValidator(queryCode);
171
+ } else {
172
+ if (!loadingAuth.current) {
173
+ validateUserSignedIn();
174
+ }
175
+ }
108
176
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_head["default"], null, /*#__PURE__*/_react["default"].createElement("meta", {
109
177
  name: "viewport",
110
- content: "width=device-width, initial-scale=1"
178
+ content: "width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"
111
179
  }), pageProps != null && pageProps.oemCompanyId != null && /*#__PURE__*/_react["default"].createElement("link", {
112
180
  href: process.env.apiUri + "/api/WhiteLabel/GetDataFromRecord?oemCompanyId=" + pageProps.oemCompanyId,
113
181
  rel: "stylesheet"
114
182
  })), /*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
115
183
  theme: muiTheme
116
- }, loadingLogin && /*#__PURE__*/_react["default"].createElement(_material.Box, null, "Please wait. Loading..."), !loadingLogin && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(AuthorizationComponent, {
117
- setCurrentUser: setCurrentUser,
118
- isEnabled: enableAuth,
119
- userLoaded: function userLoaded(signedInUser) {
120
- setLoadedUser(true);
121
- if (onAuthenticationLoaded != null) {
122
- onAuthenticationLoaded(signedInUser);
123
- }
124
- }
125
- }, children == null && /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
126
- currentUser: currentUser,
127
- toast: _reactToastify.toast,
128
- setIsLoading: setIsLoading,
129
- loadedUser: loadedUser,
130
- logEvent: logEvent
131
- })), children != null && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, children)), /*#__PURE__*/_react["default"].createElement(_Backdrop["default"], {
132
- sx: {
133
- color: '#fff',
134
- zIndex: 99999
135
- },
136
- open: isLoading
137
- }, /*#__PURE__*/_react["default"].createElement(_CircularProgress["default"], {
138
- color: "inherit"
139
- })), /*#__PURE__*/_react["default"].createElement(_reactToastify.ToastContainer, null))), loadedUser && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production" && /*#__PURE__*/_react["default"].createElement("script", {
184
+ }, frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, layout != null && layout({
185
+ children: /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
186
+ currentUser: signedInUser.current,
187
+ toast: _reactToastify.toast
188
+ })),
189
+ currentUser: signedInUser.current
190
+ }), layout == null && /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
191
+ currentUser: signedInUser.current,
192
+ toast: _reactToastify.toast
193
+ }))), /*#__PURE__*/_react["default"].createElement(_reactToastify.ToastContainer, null)), frontEndLoaded.current && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production" && /*#__PURE__*/_react["default"].createElement("script", {
140
194
  dangerouslySetInnerHTML: {
141
195
  __html: "\n (function(c,l,a,r,i,t,y){\n c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };\n t=l.createElement(r);\n t.async=1;\n t.src=\"https://www.clarity.ms/tag/\"+i;\n y=l.getElementsByTagName(r)[0];\n y.parentNode.insertBefore(t,y);\n })(window, document, \"clarity\", \"script\", \"" + process.env.microsoftClarityTrackingCode + "\");"
142
196
  }
@@ -3005,7 +3059,6 @@ exports.SpreadsheetViewer = SpreadsheetViewer;
3005
3059
  var _material = require("@mui/material");
3006
3060
  var _react = _interopRequireWildcard(require("react"));
3007
3061
  var _reactgrid = require("@silevis/reactgrid");
3008
- var _authscape = require("authscape");
3009
3062
  var _reactDeviceDetect = require("react-device-detect");
3010
3063
  var signalR = _interopRequireWildcard(require("@microsoft/signalr"));
3011
3064
  var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
@@ -3181,7 +3234,7 @@ function SpreadsheetViewer(_ref) {
3181
3234
  while (1) switch (_context.prev = _context.next) {
3182
3235
  case 0:
3183
3236
  _context.next = 2;
3184
- return (0, _authscape.apiService)().get(url);
3237
+ return apiService().get(url);
3185
3238
  case 2:
3186
3239
  response = _context.sent;
3187
3240
  if (response != null && response.status == 200) {
@@ -3209,7 +3262,7 @@ function SpreadsheetViewer(_ref) {
3209
3262
  while (1) switch (_context2.prev = _context2.next) {
3210
3263
  case 0:
3211
3264
  _context2.next = 2;
3212
- return (0, _authscape.apiService)().get("/AuthScapeSpreadSheet/GetActiveSessions?documentId=" + documentId);
3265
+ return apiService().get("/AuthScapeSpreadSheet/GetActiveSessions?documentId=" + documentId);
3213
3266
  case 2:
3214
3267
  response = _context2.sent;
3215
3268
  sessionData = response.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.370",
3
+ "version": "1.0.372",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,7 +14,6 @@
14
14
  "@stripe/stripe-js": "^1.32.0",
15
15
  "js-file-download": "^0.4.12",
16
16
  "nookies": "^2.5.2",
17
- "react": "^18.2.0",
18
17
  "react-data-table-component": "^7.5.2",
19
18
  "react-dom": "^18.2.0"
20
19
  },
@@ -23,12 +22,17 @@
23
22
  "@babel/core": "^7.22.1",
24
23
  "@babel/preset-env": "^7.22.2",
25
24
  "@babel/preset-react": "^7.0.0",
26
- "react": "^18.2.0",
27
25
  "react-dom": "^18.2.0"
28
26
  },
29
27
  "dependencies": {
28
+ "@emotion/react": "^11.11.3",
29
+ "@emotion/styled": "^11.11.0",
30
30
  "@microsoft/signalr": "^8.0.0",
31
31
  "@monaco-editor/react": "^4.5.1",
32
+ "@mui/icons-material": "^5.15.10",
33
+ "@mui/material": "^5.15.10",
34
+ "@mui/x-data-grid": "^6.19.4",
35
+ "@mui/x-date-pickers": "^6.19.4",
32
36
  "@silevis/reactgrid": "^4.1.3",
33
37
  "@stripe/react-stripe-js": "^1.9.0",
34
38
  "@stripe/stripe-js": "^1.32.0",
@@ -43,13 +47,15 @@
43
47
  "next": "^14.1.0",
44
48
  "nookies": "^2.5.2",
45
49
  "query-string": "^7.1.1",
50
+ "react": "^18.2.0",
46
51
  "react-color": "^2.19.3",
47
52
  "react-cool-onclickoutside": "^1.7.0",
48
53
  "react-data-table-component": "^7.5.2",
49
54
  "react-device-detect": "^2.2.3",
50
55
  "react-draft-wysiwyg": "^1.15.0",
51
- "react-hook-form": "^7.44.2",
56
+ "react-hook-form": "^7.50.1",
52
57
  "react-toastify": "^9.1.3",
58
+ "styled-components": "^5.3.6",
53
59
  "use-places-autocomplete": "^4.0.0"
54
60
  }
55
61
  }
@@ -1,86 +1,142 @@
1
- import React, { useEffect, useState, useRef } from 'react';
2
- import CircularProgress from '@mui/material/CircularProgress';
3
- import Backdrop from '@mui/material/Backdrop';
1
+ import React, {useState, useRef} from 'react';
4
2
  import { ToastContainer, toast } from 'react-toastify';
5
3
  import { ThemeProvider } from '@mui/material/styles';
6
- import { Box } from '@mui/material';
7
4
  import Head from "next/head";
8
- import { useSearchParams } from 'next/navigation';
5
+ import { useSearchParams, usePathname } from 'next/navigation';
6
+ import axios from 'axios';
7
+ import querystring from "query-string";
8
+ import { setCookie } from 'nookies'
9
9
 
10
- export function AuthScapeApp({Component, pageProps, muiTheme = {}, enforceLoggedIn = false, enableAuth = true, onAuthenticationLoaded = null, children = null}) {
10
+ export function AuthScapeApp ({Component, layout, pageProps, muiTheme = {}, enforceLoggedIn = false, enableAuth = true}) {
11
11
 
12
- const [isLoading, setIsLoading] = useState(false);
13
- const [loadedUser, setLoadedUser] = useState(false);
14
- const [currentUser, setCurrentUser] = useState(null);
15
- const [loadingLogin, setLoadingLogin] = useState(false);
12
+ const [frontEndLoadedState, setFrontEndLoadedState] = useState(false);
16
13
 
14
+ const loadingAuth = useRef(false);
15
+ const frontEndLoaded = useRef(false);
16
+ const signedInUser = useRef(null);
17
17
 
18
+ const queryCodeUsed = useRef(null);
18
19
 
19
- const validateCode = () => {
20
- if (queryCode != null)
20
+ const searchParams = useSearchParams();
21
+ const queryRef = searchParams.get('ref');
22
+ const queryCode = searchParams.get('code');
23
+
24
+
25
+
26
+ const pathname = usePathname();
27
+
28
+
29
+ const signInValidator = async (queryCode) => {
30
+
31
+ if (queryCodeUsed.current != queryCode)
21
32
  {
22
- setLoadingLogin(true);
23
- signInValidator(queryCode);
33
+ queryCodeUsed.current = queryCode;
24
34
  }
25
35
  else
26
36
  {
27
- if (enforceLoggedIn)
37
+ return;
38
+ }
39
+
40
+ let codeVerifier = window.localStorage.getItem("verifier");
41
+ if (queryCode != null && codeVerifier != null)
28
42
  {
29
- if (currentUser == null)
43
+ const headers = {'Content-Type': 'application/x-www-form-urlencoded'}
44
+
45
+ let queryString = querystring.stringify({
46
+ code: queryCode,
47
+ grant_type: "authorization_code",
48
+ redirect_uri: window.location.origin + "/signin-oidc",
49
+ client_id: process.env.client_id,
50
+ client_secret: process.env.client_secret,
51
+ code_verifier: codeVerifier
52
+ });
53
+
54
+ try
55
+ {
56
+ let response = await axios.post(process.env.authorityUri + '/connect/token', queryString, {
57
+ headers: headers
58
+ });
59
+
60
+ let domainHost = window.location.hostname.split('.').slice(-2).join('.');
61
+ window.localStorage.removeItem("verifier");
62
+
63
+ await setCookie(null, "access_token", response.data.access_token,
64
+ {
65
+ maxAge: 2147483647,
66
+ path: '/',
67
+ domain: domainHost,
68
+ secure: true
69
+ });
70
+
71
+ await setCookie(null, "expires_in", response.data.expires_in,
72
+ {
73
+ maxAge: 2147483647,
74
+ path: '/',
75
+ domain: domainHost,
76
+ secure: true
77
+ });
78
+
79
+ await setCookie(null, "refresh_token", response.data.refresh_token,
80
+ {
81
+ maxAge: 2147483647,
82
+ path: '/',
83
+ domain: domainHost,
84
+ secure: true
85
+ });
86
+
87
+
88
+ let redirectUri = localStorage.getItem("redirectUri")
89
+ localStorage.clear();
90
+ if (redirectUri != null)
91
+ {
92
+ window.location.href = redirectUri;
93
+ }
94
+ else
30
95
  {
31
- authService().login();
96
+ window.location.href = "/";
32
97
  }
33
98
  }
99
+ catch(exp)
100
+ {
101
+ //alert(exp)
102
+ }
34
103
  }
35
104
  }
36
105
 
37
- const searchParams = useSearchParams();
38
- const queryRef = searchParams.get('ref');
39
- const queryCode = searchParams.get('code');
40
- validateCode(queryCode);
41
106
 
42
- // const router = useRouter();
107
+ const validateUserSignedIn = async () => {
43
108
 
109
+ loadingAuth.current = true;
44
110
 
45
- // useEffect(() => {
46
-
47
- // if (loadedUser && router.isReady)
48
- // {
49
- // if (process.env.googleAnalytics4 != null)
50
- // {
51
- // init(process.env.googleAnalytics4);
52
- // }
111
+ if (enableAuth)
112
+ {
113
+ let usr = await apiService().GetCurrentUser();
114
+ if (usr != null)
115
+ {
116
+ signedInUser.current = usr;
117
+ }
118
+ }
53
119
 
54
- // if (queryRef != null)
55
- // {
56
- // localStorage.setItem("ref", queryRef);
57
- // }
58
-
59
- // // sign in validation
60
- // if (queryCode != null)
61
- // {
62
- // setLoadingLogin(true);
63
- // signInValidator(queryCode);
64
- // }
65
- // else
66
- // {
67
- // if (enforceLoggedIn)
68
- // {
69
- // if (currentUser == null)
70
- // {
71
- // authService().login();
72
- // }
73
- // }
74
- // }
75
- // }
76
-
77
- // }, [loadedUser, router.isReady])
120
+ setFrontEndLoadedState(true);
121
+ frontEndLoaded.current = true;
122
+ }
78
123
 
124
+ if (queryCode != null)
125
+ {
126
+ signInValidator(queryCode);
127
+ }
128
+ else
129
+ {
130
+ if (!loadingAuth.current)
131
+ {
132
+ validateUserSignedIn();
133
+ }
134
+ }
79
135
 
80
136
  return (
81
137
  <>
82
138
  <Head>
83
- <meta name="viewport" content="width=device-width, initial-scale=1" />
139
+ <meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"></meta>
84
140
  {(pageProps != null && pageProps.oemCompanyId != null) &&
85
141
  <link
86
142
  href={process.env.apiUri + "/api/WhiteLabel/GetDataFromRecord?oemCompanyId=" + pageProps.oemCompanyId}
@@ -90,43 +146,23 @@ export function AuthScapeApp({Component, pageProps, muiTheme = {}, enforceLogged
90
146
  </Head>
91
147
 
92
148
  <ThemeProvider theme={muiTheme}>
93
-
94
- {loadingLogin &&
95
- <Box>
96
- Please wait. Loading...
97
- </Box>
98
- }
99
-
100
- {!loadingLogin &&
149
+ {frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" &&
101
150
  <>
102
- <AuthorizationComponent setCurrentUser={setCurrentUser} isEnabled={enableAuth} userLoaded={(signedInUser) => {
103
- setLoadedUser(true);
104
-
105
- if (onAuthenticationLoaded != null)
106
- {
107
- onAuthenticationLoaded(signedInUser);
108
- }
109
- }}>
110
- {children == null &&
111
- <Component {...pageProps} currentUser={currentUser} toast={toast} setIsLoading={setIsLoading} loadedUser={loadedUser} logEvent={logEvent} />
112
- }
113
- {children != null &&
114
- <>
115
- {children}
116
- </>
117
- }
118
- </AuthorizationComponent>
119
-
120
- <Backdrop sx={{ color: '#fff', zIndex: 99999 }} open={isLoading}>
121
- <CircularProgress color="inherit" />
122
- </Backdrop>
123
-
124
- <ToastContainer />
151
+ {layout != null && layout({
152
+ children: <Component {...pageProps} currentUser={signedInUser.current} toast={toast} />,
153
+ currentUser: signedInUser.current
154
+ })}
155
+
156
+ {layout == null &&
157
+ <Component {...pageProps} currentUser={signedInUser.current} toast={toast} />
158
+ }
125
159
  </>
126
160
  }
161
+ <ToastContainer />
162
+
127
163
  </ThemeProvider>
128
164
 
129
- {(loadedUser && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production") &&
165
+ {(frontEndLoaded.current && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production") &&
130
166
  <script
131
167
  dangerouslySetInnerHTML={{
132
168
  __html: `
@@ -1,7 +1,6 @@
1
1
  import { Box, Button } from '@mui/material';
2
2
  import React, { useEffect, useState, useRef } from 'react';
3
3
  import { ReactGrid, Column, Row } from "@silevis/reactgrid";
4
- import { apiService } from 'authscape';
5
4
  import {isMacOs} from 'react-device-detect';
6
5
  import * as signalR from '@microsoft/signalr';
7
6
  import Avatar from '@mui/material/Avatar';