authscape 1.0.658 → 1.0.660
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 +123 -119
- package/package.json +1 -1
- package/src/components/AuthScapeApp.js +7 -7
- package/src/services/apiService.js +12 -12
- package/src/services/authService.js +3 -3
- package/src/services/signInValidator.js +7 -7
- package/src/services/util.js +23 -1
package/index.js
CHANGED
|
@@ -12,7 +12,6 @@ var _head = _interopRequireDefault(require("next/head"));
|
|
|
12
12
|
var _navigation = require("next/navigation");
|
|
13
13
|
var _axios = _interopRequireDefault(require("axios"));
|
|
14
14
|
var _queryString = _interopRequireDefault(require("query-string"));
|
|
15
|
-
var _jsCookie = _interopRequireDefault(require("js-cookie"));
|
|
16
15
|
var _router = _interopRequireDefault(require("next/router"));
|
|
17
16
|
var _ga4React = _interopRequireDefault(require("ga-4-react"));
|
|
18
17
|
var _zustand = require("zustand");
|
|
@@ -29,7 +28,7 @@ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructur
|
|
|
29
28
|
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); }
|
|
30
29
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
31
30
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
32
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
31
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // import Cookies from 'js-cookie';
|
|
33
32
|
// comment this out
|
|
34
33
|
// import { authService, apiService, setupOEMProps, OEMStyleSheet } from 'authscape';
|
|
35
34
|
|
|
@@ -109,24 +108,27 @@ function AuthScapeApp(_ref) {
|
|
|
109
108
|
domainHost = window.location.hostname.split('.').slice(-2).join('.');
|
|
110
109
|
window.localStorage.removeItem("verifier");
|
|
111
110
|
_context.next = 17;
|
|
112
|
-
return
|
|
113
|
-
maxAge:
|
|
111
|
+
return setCookie('access_token', response.data.access_token, {
|
|
112
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
113
|
+
// 1 year,
|
|
114
114
|
path: '/',
|
|
115
115
|
domain: domainHost,
|
|
116
116
|
secure: true
|
|
117
117
|
});
|
|
118
118
|
case 17:
|
|
119
119
|
_context.next = 19;
|
|
120
|
-
return
|
|
121
|
-
maxAge:
|
|
120
|
+
return setCookie('expires_in', response.data.expires_in, {
|
|
121
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
122
|
+
// 1 year,
|
|
122
123
|
path: '/',
|
|
123
124
|
domain: domainHost,
|
|
124
125
|
secure: true
|
|
125
126
|
});
|
|
126
127
|
case 19:
|
|
127
128
|
_context.next = 21;
|
|
128
|
-
return
|
|
129
|
-
maxAge:
|
|
129
|
+
return setCookie('refresh_token', response.data.refresh_token, {
|
|
130
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
131
|
+
// 1 year,
|
|
130
132
|
path: '/',
|
|
131
133
|
domain: domainHost,
|
|
132
134
|
secure: true
|
|
@@ -8399,41 +8401,26 @@ var setupDefaultOptions = /*#__PURE__*/function () {
|
|
|
8399
8401
|
case 0:
|
|
8400
8402
|
ctx = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
|
|
8401
8403
|
defaultOptions = {};
|
|
8402
|
-
if (
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
|
|
8409
|
-
|
|
8410
|
-
|
|
8411
|
-
|
|
8412
|
-
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
case 8:
|
|
8416
|
-
accessToken = _context.t0;
|
|
8417
|
-
if (accessToken !== null && accessToken !== undefined && accessToken != "") {
|
|
8418
|
-
defaultOptions = {
|
|
8419
|
-
headers: {
|
|
8420
|
-
Authorization: "Bearer " + accessToken
|
|
8421
|
-
}
|
|
8422
|
-
};
|
|
8404
|
+
if (ctx == null) {
|
|
8405
|
+
accessToken = _jsCookie["default"].get('access_token') || '';
|
|
8406
|
+
if (accessToken !== null && accessToken !== undefined && accessToken != "") {
|
|
8407
|
+
defaultOptions = {
|
|
8408
|
+
headers: {
|
|
8409
|
+
Authorization: "Bearer " + accessToken
|
|
8410
|
+
}
|
|
8411
|
+
};
|
|
8412
|
+
} else {
|
|
8413
|
+
defaultOptions = {
|
|
8414
|
+
headers: {}
|
|
8415
|
+
};
|
|
8416
|
+
}
|
|
8423
8417
|
} else {
|
|
8424
8418
|
defaultOptions = {
|
|
8425
8419
|
headers: {}
|
|
8426
8420
|
};
|
|
8427
8421
|
}
|
|
8428
|
-
_context.next = 13;
|
|
8429
|
-
break;
|
|
8430
|
-
case 12:
|
|
8431
|
-
defaultOptions = {
|
|
8432
|
-
headers: {}
|
|
8433
|
-
};
|
|
8434
|
-
case 13:
|
|
8435
8422
|
return _context.abrupt("return", defaultOptions);
|
|
8436
|
-
case
|
|
8423
|
+
case 4:
|
|
8437
8424
|
case "end":
|
|
8438
8425
|
return _context.stop();
|
|
8439
8426
|
}
|
|
@@ -8449,29 +8436,9 @@ var RefreshToken = /*#__PURE__*/function () {
|
|
|
8449
8436
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
8450
8437
|
while (1) switch (_context2.prev = _context2.next) {
|
|
8451
8438
|
case 0:
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
_context2.t0 = _context2.sent;
|
|
8456
|
-
if (_context2.t0) {
|
|
8457
|
-
_context2.next = 5;
|
|
8458
|
-
break;
|
|
8459
|
-
}
|
|
8460
|
-
_context2.t0 = '';
|
|
8461
|
-
case 5:
|
|
8462
|
-
accessToken = _context2.t0;
|
|
8463
|
-
_context2.next = 8;
|
|
8464
|
-
return _jsCookie["default"].get('refresh_token');
|
|
8465
|
-
case 8:
|
|
8466
|
-
_context2.t1 = _context2.sent;
|
|
8467
|
-
if (_context2.t1) {
|
|
8468
|
-
_context2.next = 11;
|
|
8469
|
-
break;
|
|
8470
|
-
}
|
|
8471
|
-
_context2.t1 = '';
|
|
8472
|
-
case 11:
|
|
8473
|
-
refreshToken = _context2.t1;
|
|
8474
|
-
_context2.next = 14;
|
|
8439
|
+
accessToken = _jsCookie["default"].get('access_token') || '';
|
|
8440
|
+
refreshToken = _jsCookie["default"].get('refresh_token') || '';
|
|
8441
|
+
_context2.next = 4;
|
|
8475
8442
|
return instance.post(process.env.authorityUri + "/connect/token", _queryString["default"].stringify({
|
|
8476
8443
|
grant_type: 'refresh_token',
|
|
8477
8444
|
client_id: process.env.client_id,
|
|
@@ -8483,38 +8450,41 @@ var RefreshToken = /*#__PURE__*/function () {
|
|
|
8483
8450
|
"Authorization": "Bearer " + accessToken
|
|
8484
8451
|
}
|
|
8485
8452
|
});
|
|
8486
|
-
case
|
|
8453
|
+
case 4:
|
|
8487
8454
|
response = _context2.sent;
|
|
8488
8455
|
if (!(response != null && response.status == 200)) {
|
|
8489
|
-
_context2.next =
|
|
8456
|
+
_context2.next = 14;
|
|
8490
8457
|
break;
|
|
8491
8458
|
}
|
|
8492
8459
|
domainHost = window.location.hostname.split('.').slice(-2).join('.');
|
|
8493
8460
|
originalRequest.headers['Authorization'] = 'Bearer ' + response.data.access_token;
|
|
8494
|
-
_context2.next =
|
|
8495
|
-
return
|
|
8496
|
-
maxAge:
|
|
8461
|
+
_context2.next = 10;
|
|
8462
|
+
return setCookie('access_token', response.data.access_token, {
|
|
8463
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
8464
|
+
// 1 year,
|
|
8497
8465
|
path: '/',
|
|
8498
8466
|
domain: domainHost,
|
|
8499
8467
|
secure: true
|
|
8500
8468
|
});
|
|
8501
|
-
case
|
|
8502
|
-
_context2.next =
|
|
8503
|
-
return
|
|
8504
|
-
maxAge:
|
|
8469
|
+
case 10:
|
|
8470
|
+
_context2.next = 12;
|
|
8471
|
+
return setCookie('expires_in', response.data.expires_in, {
|
|
8472
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
8473
|
+
// 1 year,
|
|
8505
8474
|
path: '/',
|
|
8506
8475
|
domain: domainHost,
|
|
8507
8476
|
secure: true
|
|
8508
8477
|
});
|
|
8509
|
-
case
|
|
8510
|
-
_context2.next =
|
|
8511
|
-
return
|
|
8512
|
-
maxAge:
|
|
8478
|
+
case 12:
|
|
8479
|
+
_context2.next = 14;
|
|
8480
|
+
return setCookie('refresh_token', response.data.refresh_token, {
|
|
8481
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
8482
|
+
// 1 year,
|
|
8513
8483
|
path: '/',
|
|
8514
8484
|
domain: domainHost,
|
|
8515
8485
|
secure: true
|
|
8516
8486
|
});
|
|
8517
|
-
case
|
|
8487
|
+
case 14:
|
|
8518
8488
|
case "end":
|
|
8519
8489
|
return _context2.stop();
|
|
8520
8490
|
}
|
|
@@ -8547,7 +8517,7 @@ var apiService = function apiService() {
|
|
|
8547
8517
|
case 0:
|
|
8548
8518
|
originalConfig = error.config;
|
|
8549
8519
|
if (!error.response) {
|
|
8550
|
-
_context3.next =
|
|
8520
|
+
_context3.next = 10;
|
|
8551
8521
|
break;
|
|
8552
8522
|
}
|
|
8553
8523
|
if (!(error.response.status === 401 && !originalConfig._retry)) {
|
|
@@ -8563,36 +8533,50 @@ var apiService = function apiService() {
|
|
|
8563
8533
|
return _context3.abrupt("return", instance.request(originalConfig));
|
|
8564
8534
|
case 7:
|
|
8565
8535
|
if (!(error.response.status === 400)) {
|
|
8566
|
-
_context3.next =
|
|
8567
|
-
break;
|
|
8568
|
-
}
|
|
8569
|
-
if (!error.response.config.url.includes("/connect/token")) {
|
|
8570
|
-
_context3.next = 16;
|
|
8536
|
+
_context3.next = 10;
|
|
8571
8537
|
break;
|
|
8572
8538
|
}
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
8591
|
-
|
|
8539
|
+
// Do something
|
|
8540
|
+
|
|
8541
|
+
if (error.response.config.url.includes("/connect/token"))
|
|
8542
|
+
// remove the access and refresh if invalid
|
|
8543
|
+
{
|
|
8544
|
+
domainHost = window.location.hostname.split('.').slice(-2).join('.');
|
|
8545
|
+
_jsCookie["default"].remove('access_token', {
|
|
8546
|
+
path: '/',
|
|
8547
|
+
domain: domainHost
|
|
8548
|
+
});
|
|
8549
|
+
_jsCookie["default"].remove('refresh_token', {
|
|
8550
|
+
path: '/',
|
|
8551
|
+
domain: domainHost
|
|
8552
|
+
});
|
|
8553
|
+
_jsCookie["default"].remove('expires_in', {
|
|
8554
|
+
path: '/',
|
|
8555
|
+
domain: domainHost
|
|
8556
|
+
});
|
|
8557
|
+
|
|
8558
|
+
// destroyCookie(null, "access_token", {
|
|
8559
|
+
// maxAge: 2147483647,
|
|
8560
|
+
// path: '/',
|
|
8561
|
+
// domain: domainHost
|
|
8562
|
+
// });
|
|
8563
|
+
|
|
8564
|
+
// destroyCookie(null, "refresh_token", {
|
|
8565
|
+
// maxAge: 2147483647,
|
|
8566
|
+
// path: '/',
|
|
8567
|
+
// domain: domainHost
|
|
8568
|
+
// });
|
|
8569
|
+
|
|
8570
|
+
// destroyCookie(null, "expires_in", {
|
|
8571
|
+
// maxAge: 2147483647,
|
|
8572
|
+
// path: '/',
|
|
8573
|
+
// domain: domainHost
|
|
8574
|
+
// });
|
|
8575
|
+
}
|
|
8592
8576
|
return _context3.abrupt("return", Promise.reject(error));
|
|
8593
|
-
case
|
|
8577
|
+
case 10:
|
|
8594
8578
|
return _context3.abrupt("return", Promise.reject(error));
|
|
8595
|
-
case
|
|
8579
|
+
case 11:
|
|
8596
8580
|
case "end":
|
|
8597
8581
|
return _context3.stop();
|
|
8598
8582
|
}
|
|
@@ -9135,24 +9119,19 @@ var authService = function authService() {
|
|
|
9135
9119
|
redirectUri = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : null;
|
|
9136
9120
|
domainHost = window.location.hostname.split('.').slice(-2).join('.');
|
|
9137
9121
|
AuthUri = process.env.authorityUri;
|
|
9138
|
-
|
|
9139
|
-
return _jsCookie["default"].remove('access_token', {
|
|
9122
|
+
_jsCookie["default"].remove('access_token', {
|
|
9140
9123
|
path: '/',
|
|
9141
9124
|
domain: domainHost
|
|
9142
9125
|
});
|
|
9143
|
-
|
|
9144
|
-
_context6.next = 7;
|
|
9145
|
-
return _jsCookie["default"].remove('refresh_token', {
|
|
9126
|
+
_jsCookie["default"].remove('refresh_token', {
|
|
9146
9127
|
path: '/',
|
|
9147
9128
|
domain: domainHost
|
|
9148
9129
|
});
|
|
9149
|
-
|
|
9150
|
-
_context6.next = 9;
|
|
9151
|
-
return _jsCookie["default"].remove('expires_in', {
|
|
9130
|
+
_jsCookie["default"].remove('expires_in', {
|
|
9152
9131
|
path: '/',
|
|
9153
9132
|
domain: domainHost
|
|
9154
9133
|
});
|
|
9155
|
-
|
|
9134
|
+
|
|
9156
9135
|
// destroyCookie({}, "access_token", {
|
|
9157
9136
|
// maxAge: 2147483647,
|
|
9158
9137
|
// path: '/',
|
|
@@ -9178,7 +9157,7 @@ var authService = function authService() {
|
|
|
9178
9157
|
window.location.href = AuthUri + "/connect/logout?redirect=" + redirectUri;
|
|
9179
9158
|
}
|
|
9180
9159
|
}, 500);
|
|
9181
|
-
case
|
|
9160
|
+
case 7:
|
|
9182
9161
|
case "end":
|
|
9183
9162
|
return _context6.stop();
|
|
9184
9163
|
}
|
|
@@ -9274,13 +9253,14 @@ exports.signInValidator = void 0;
|
|
|
9274
9253
|
var _react = _interopRequireWildcard(require("react"));
|
|
9275
9254
|
var _axios = _interopRequireDefault(require("axios"));
|
|
9276
9255
|
var _queryString = _interopRequireDefault(require("query-string"));
|
|
9277
|
-
var _jsCookie = _interopRequireDefault(require("js-cookie"));
|
|
9278
9256
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9279
9257
|
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); }
|
|
9280
9258
|
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; }
|
|
9281
9259
|
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; }
|
|
9282
9260
|
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); } }
|
|
9283
9261
|
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); }); }; }
|
|
9262
|
+
// import Cookies from 'js-cookie';
|
|
9263
|
+
|
|
9284
9264
|
var signInValidator = /*#__PURE__*/function () {
|
|
9285
9265
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(queryCode) {
|
|
9286
9266
|
var codeVerifier, headers, queryString, response, domainHost, redirectUri;
|
|
@@ -9312,24 +9292,27 @@ var signInValidator = /*#__PURE__*/function () {
|
|
|
9312
9292
|
domainHost = window.location.hostname.split('.').slice(-2).join('.');
|
|
9313
9293
|
window.localStorage.removeItem("verifier");
|
|
9314
9294
|
_context.next = 11;
|
|
9315
|
-
return
|
|
9316
|
-
maxAge:
|
|
9295
|
+
return setCookie('access_token', response.data.access_token, {
|
|
9296
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
9297
|
+
// 1 year,
|
|
9317
9298
|
path: '/',
|
|
9318
9299
|
domain: domainHost,
|
|
9319
9300
|
secure: true
|
|
9320
9301
|
});
|
|
9321
9302
|
case 11:
|
|
9322
9303
|
_context.next = 13;
|
|
9323
|
-
return
|
|
9324
|
-
maxAge:
|
|
9304
|
+
return setCookie('expires_in', response.data.expires_in, {
|
|
9305
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
9306
|
+
// 1 year,
|
|
9325
9307
|
path: '/',
|
|
9326
9308
|
domain: domainHost,
|
|
9327
9309
|
secure: true
|
|
9328
9310
|
});
|
|
9329
9311
|
case 13:
|
|
9330
9312
|
_context.next = 15;
|
|
9331
|
-
return
|
|
9332
|
-
maxAge:
|
|
9313
|
+
return setCookie('refresh_token', response.data.refresh_token, {
|
|
9314
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
9315
|
+
// 1 year,
|
|
9333
9316
|
path: '/',
|
|
9334
9317
|
domain: domainHost,
|
|
9335
9318
|
secure: true
|
|
@@ -9427,7 +9410,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
9427
9410
|
Object.defineProperty(exports, "__esModule", {
|
|
9428
9411
|
value: true
|
|
9429
9412
|
});
|
|
9430
|
-
exports.GetBaseUrl = void 0;
|
|
9413
|
+
exports.setCookie = exports.GetBaseUrl = void 0;
|
|
9431
9414
|
var _react = _interopRequireWildcard(require("react"));
|
|
9432
9415
|
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); }
|
|
9433
9416
|
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; }
|
|
@@ -9435,3 +9418,24 @@ var GetBaseUrl = function GetBaseUrl() {
|
|
|
9435
9418
|
return window.location.protocol + "//" + window.location.host;
|
|
9436
9419
|
};
|
|
9437
9420
|
exports.GetBaseUrl = GetBaseUrl;
|
|
9421
|
+
var setCookie = function setCookie(name, value) {
|
|
9422
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
9423
|
+
return new Promise(function (resolve) {
|
|
9424
|
+
var cookieString = "".concat(name, "=").concat(value, ";");
|
|
9425
|
+
if (options.maxAge) {
|
|
9426
|
+
cookieString += "max-age=".concat(options.maxAge, ";");
|
|
9427
|
+
}
|
|
9428
|
+
if (options.path) {
|
|
9429
|
+
cookieString += "path=".concat(options.path, ";");
|
|
9430
|
+
}
|
|
9431
|
+
if (options.domain) {
|
|
9432
|
+
cookieString += "domain=".concat(options.domain, ";");
|
|
9433
|
+
}
|
|
9434
|
+
if (options.secure) {
|
|
9435
|
+
cookieString += "secure;";
|
|
9436
|
+
}
|
|
9437
|
+
document.cookie = cookieString;
|
|
9438
|
+
resolve();
|
|
9439
|
+
});
|
|
9440
|
+
};
|
|
9441
|
+
exports.setCookie = setCookie;
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import Head from "next/head";
|
|
|
5
5
|
import { useSearchParams, usePathname } from 'next/navigation';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import querystring from "query-string";
|
|
8
|
-
import Cookies from 'js-cookie';
|
|
8
|
+
// import Cookies from 'js-cookie';
|
|
9
9
|
import Router from 'next/router';
|
|
10
10
|
import GA4React from 'ga-4-react';
|
|
11
11
|
import { create } from 'zustand'
|
|
@@ -69,22 +69,22 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
|
|
|
69
69
|
let domainHost = window.location.hostname.split('.').slice(-2).join('.');
|
|
70
70
|
window.localStorage.removeItem("verifier");
|
|
71
71
|
|
|
72
|
-
await
|
|
73
|
-
maxAge:
|
|
72
|
+
await setCookie('access_token', response.data.access_token, {
|
|
73
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
74
74
|
path: '/',
|
|
75
75
|
domain: domainHost,
|
|
76
76
|
secure: true
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
await
|
|
80
|
-
maxAge:
|
|
79
|
+
await setCookie('expires_in', response.data.expires_in, {
|
|
80
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
81
81
|
path: '/',
|
|
82
82
|
domain: domainHost,
|
|
83
83
|
secure: true
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
await
|
|
87
|
-
maxAge:
|
|
86
|
+
await setCookie('refresh_token', response.data.refresh_token, {
|
|
87
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
88
88
|
path: '/',
|
|
89
89
|
domain: domainHost,
|
|
90
90
|
secure: true
|
|
@@ -8,7 +8,7 @@ const setupDefaultOptions = async (ctx = null) => {
|
|
|
8
8
|
let defaultOptions = {};
|
|
9
9
|
if (ctx == null)
|
|
10
10
|
{
|
|
11
|
-
let accessToken =
|
|
11
|
+
let accessToken = Cookies.get('access_token') || '';
|
|
12
12
|
|
|
13
13
|
if (accessToken !== null && accessToken !== undefined && accessToken != "") {
|
|
14
14
|
defaultOptions = {
|
|
@@ -37,8 +37,8 @@ const setupDefaultOptions = async (ctx = null) => {
|
|
|
37
37
|
|
|
38
38
|
const RefreshToken = async (originalRequest, instance) => {
|
|
39
39
|
|
|
40
|
-
let accessToken =
|
|
41
|
-
let refreshToken =
|
|
40
|
+
let accessToken = Cookies.get('access_token') || '';
|
|
41
|
+
let refreshToken = Cookies.get('refresh_token') || '';
|
|
42
42
|
|
|
43
43
|
let response = await instance.post(process.env.authorityUri + "/connect/token",
|
|
44
44
|
querystring.stringify({
|
|
@@ -62,22 +62,22 @@ const RefreshToken = async (originalRequest, instance) => {
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
await
|
|
66
|
-
maxAge:
|
|
65
|
+
await setCookie('access_token', response.data.access_token, {
|
|
66
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
67
67
|
path: '/',
|
|
68
68
|
domain: domainHost,
|
|
69
69
|
secure: true
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
await
|
|
73
|
-
maxAge:
|
|
72
|
+
await setCookie('expires_in', response.data.expires_in, {
|
|
73
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
74
74
|
path: '/',
|
|
75
75
|
domain: domainHost,
|
|
76
76
|
secure: true
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
await
|
|
80
|
-
maxAge:
|
|
79
|
+
await setCookie('refresh_token', response.data.refresh_token, {
|
|
80
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
81
81
|
path: '/',
|
|
82
82
|
domain: domainHost,
|
|
83
83
|
secure: true
|
|
@@ -154,9 +154,9 @@ export const apiService = (ctx = null) => {
|
|
|
154
154
|
let domainHost = window.location.hostname.split('.').slice(-2).join('.');
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
Cookies.remove('access_token', { path: '/', domain: domainHost });
|
|
158
|
+
Cookies.remove('refresh_token', { path: '/', domain: domainHost });
|
|
159
|
+
Cookies.remove('expires_in', { path: '/', domain: domainHost });
|
|
160
160
|
|
|
161
161
|
// destroyCookie(null, "access_token", {
|
|
162
162
|
// maxAge: 2147483647,
|
|
@@ -117,9 +117,9 @@ export const authService = () => {
|
|
|
117
117
|
let AuthUri = process.env.authorityUri;
|
|
118
118
|
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
Cookies.remove('access_token', { path: '/', domain: domainHost });
|
|
121
|
+
Cookies.remove('refresh_token', { path: '/', domain: domainHost });
|
|
122
|
+
Cookies.remove('expires_in', { path: '/', domain: domainHost });
|
|
123
123
|
|
|
124
124
|
|
|
125
125
|
// destroyCookie({}, "access_token", {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import querystring from "query-string";
|
|
4
|
-
import Cookies from 'js-cookie';
|
|
4
|
+
// import Cookies from 'js-cookie';
|
|
5
5
|
|
|
6
6
|
export const signInValidator = async (queryCode) => {
|
|
7
7
|
|
|
@@ -28,22 +28,22 @@ export const signInValidator = async (queryCode) => {
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
await
|
|
32
|
-
maxAge:
|
|
31
|
+
await setCookie('access_token', response.data.access_token, {
|
|
32
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
33
33
|
path: '/',
|
|
34
34
|
domain: domainHost,
|
|
35
35
|
secure: true
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
await
|
|
39
|
-
maxAge:
|
|
38
|
+
await setCookie('expires_in', response.data.expires_in, {
|
|
39
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
40
40
|
path: '/',
|
|
41
41
|
domain: domainHost,
|
|
42
42
|
secure: true
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
await
|
|
46
|
-
maxAge:
|
|
45
|
+
await setCookie('refresh_token', response.data.refresh_token, {
|
|
46
|
+
maxAge: 60 * 60 * 24 * 365, // 1 year,
|
|
47
47
|
path: '/',
|
|
48
48
|
domain: domainHost,
|
|
49
49
|
secure: true
|
package/src/services/util.js
CHANGED
|
@@ -2,4 +2,26 @@ import React, { useState, useRef, useEffect } from "react";
|
|
|
2
2
|
|
|
3
3
|
export const GetBaseUrl = () => {
|
|
4
4
|
return window.location.protocol + "//" + window.location.host;
|
|
5
|
-
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const setCookie = (name, value, options = {}) => {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
let cookieString = `${name}=${value};`;
|
|
10
|
+
|
|
11
|
+
if (options.maxAge) {
|
|
12
|
+
cookieString += `max-age=${options.maxAge};`;
|
|
13
|
+
}
|
|
14
|
+
if (options.path) {
|
|
15
|
+
cookieString += `path=${options.path};`;
|
|
16
|
+
}
|
|
17
|
+
if (options.domain) {
|
|
18
|
+
cookieString += `domain=${options.domain};`;
|
|
19
|
+
}
|
|
20
|
+
if (options.secure) {
|
|
21
|
+
cookieString += `secure;`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
document.cookie = cookieString;
|
|
25
|
+
resolve();
|
|
26
|
+
});
|
|
27
|
+
}
|