authscape 1.0.86 → 1.0.92
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 +31 -53
- package/package.json +4 -7
- package/src/services/apiService.js +23 -21
- package/src/services/signInValidator.js +1 -1
- package/src/services/helper.js +0 -11
package/index.js
CHANGED
|
@@ -318,12 +318,10 @@ exports.apiService = void 0;
|
|
|
318
318
|
|
|
319
319
|
var _axios = _interopRequireDefault(require("axios"));
|
|
320
320
|
|
|
321
|
-
var
|
|
321
|
+
var _queryString = _interopRequireDefault(require("query-string"));
|
|
322
322
|
|
|
323
323
|
var _jsFileDownload = _interopRequireDefault(require("js-file-download"));
|
|
324
324
|
|
|
325
|
-
var _nextCookies = _interopRequireDefault(require("next-cookies"));
|
|
326
|
-
|
|
327
325
|
var _nookies = require("nookies");
|
|
328
326
|
|
|
329
327
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -340,7 +338,6 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
340
338
|
|
|
341
339
|
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); }); }; }
|
|
342
340
|
|
|
343
|
-
// import Helper from "./helper";
|
|
344
341
|
var setupDefaultOptions = /*#__PURE__*/function () {
|
|
345
342
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
346
343
|
var ctx,
|
|
@@ -351,11 +348,11 @@ var setupDefaultOptions = /*#__PURE__*/function () {
|
|
|
351
348
|
while (1) {
|
|
352
349
|
switch (_context.prev = _context.next) {
|
|
353
350
|
case 0:
|
|
354
|
-
ctx = _args.length > 0 && _args[0] !== undefined ? _args[0] :
|
|
351
|
+
ctx = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
|
|
355
352
|
defaultOptions = {};
|
|
356
353
|
|
|
357
|
-
if (
|
|
358
|
-
accessToken = (0,
|
|
354
|
+
if (ctx == null) {
|
|
355
|
+
accessToken = (0, _nookies.parseCookies)().access_token || '';
|
|
359
356
|
|
|
360
357
|
if (accessToken !== null && accessToken !== undefined && accessToken != "") {
|
|
361
358
|
defaultOptions = {
|
|
@@ -391,15 +388,15 @@ var setupDefaultOptions = /*#__PURE__*/function () {
|
|
|
391
388
|
|
|
392
389
|
var RefreshToken = /*#__PURE__*/function () {
|
|
393
390
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(originalRequest, instance) {
|
|
394
|
-
var accessToken, refreshToken, response
|
|
391
|
+
var accessToken, refreshToken, response;
|
|
395
392
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
396
393
|
while (1) {
|
|
397
394
|
switch (_context2.prev = _context2.next) {
|
|
398
395
|
case 0:
|
|
399
|
-
accessToken = (0,
|
|
400
|
-
refreshToken = (0,
|
|
396
|
+
accessToken = (0, _nookies.parseCookies)().access_token || '';
|
|
397
|
+
refreshToken = (0, _nookies.parseCookies)().refresh_token || '';
|
|
401
398
|
_context2.next = 4;
|
|
402
|
-
return instance.post(process.env.AUTHORITYURI + "/connect/token",
|
|
399
|
+
return instance.post(process.env.AUTHORITYURI + "/connect/token", _queryString["default"].stringify({
|
|
403
400
|
grant_type: 'refresh_token',
|
|
404
401
|
client_id: process.env.client_id,
|
|
405
402
|
client_secret: process.env.client_secret,
|
|
@@ -415,39 +412,38 @@ var RefreshToken = /*#__PURE__*/function () {
|
|
|
415
412
|
response = _context2.sent;
|
|
416
413
|
|
|
417
414
|
if (!(response != null && response.status == 200)) {
|
|
418
|
-
_context2.next =
|
|
415
|
+
_context2.next = 13;
|
|
419
416
|
break;
|
|
420
417
|
}
|
|
421
418
|
|
|
422
419
|
originalRequest.headers['Authorization'] = 'Bearer ' + response.data.access_token;
|
|
423
|
-
|
|
424
|
-
_context2.next = 10;
|
|
420
|
+
_context2.next = 9;
|
|
425
421
|
return (0, _nookies.setCookie)(null, "access_token", response.data.access_token, {
|
|
426
422
|
maxAge: 2147483647,
|
|
427
423
|
path: '/',
|
|
428
|
-
domain:
|
|
424
|
+
domain: process.env.cookieDomain,
|
|
429
425
|
secure: true
|
|
430
426
|
});
|
|
431
427
|
|
|
432
|
-
case
|
|
433
|
-
_context2.next =
|
|
428
|
+
case 9:
|
|
429
|
+
_context2.next = 11;
|
|
434
430
|
return (0, _nookies.setCookie)(null, "expires_in", response.data.expires_in, {
|
|
435
431
|
maxAge: 2147483647,
|
|
436
432
|
path: '/',
|
|
437
|
-
domain:
|
|
433
|
+
domain: process.env.cookieDomain,
|
|
438
434
|
secure: true
|
|
439
435
|
});
|
|
440
436
|
|
|
441
|
-
case
|
|
442
|
-
_context2.next =
|
|
437
|
+
case 11:
|
|
438
|
+
_context2.next = 13;
|
|
443
439
|
return (0, _nookies.setCookie)(null, "refresh_token", response.data.refresh_token, {
|
|
444
440
|
maxAge: 2147483647,
|
|
445
441
|
path: '/',
|
|
446
|
-
domain:
|
|
442
|
+
domain: process.env.cookieDomain,
|
|
447
443
|
secure: true
|
|
448
444
|
});
|
|
449
445
|
|
|
450
|
-
case
|
|
446
|
+
case 13:
|
|
451
447
|
case "end":
|
|
452
448
|
return _context2.stop();
|
|
453
449
|
}
|
|
@@ -461,7 +457,7 @@ var RefreshToken = /*#__PURE__*/function () {
|
|
|
461
457
|
}();
|
|
462
458
|
|
|
463
459
|
var apiService = function apiService() {
|
|
464
|
-
var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
460
|
+
var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
465
461
|
var env = process.env.STAGE;
|
|
466
462
|
|
|
467
463
|
if (env == "development") {
|
|
@@ -515,17 +511,17 @@ var apiService = function apiService() {
|
|
|
515
511
|
// Do something
|
|
516
512
|
if (error.response.config.url.includes("/connect/token")) // remove the access and refresh if invalid
|
|
517
513
|
{
|
|
518
|
-
(0, _nookies.destroyCookie)(
|
|
514
|
+
(0, _nookies.destroyCookie)(null, "access_token", {
|
|
519
515
|
maxAge: 2147483647,
|
|
520
516
|
path: '/',
|
|
521
517
|
domain: process.env.cookieDomain
|
|
522
518
|
});
|
|
523
|
-
(0, _nookies.destroyCookie)(
|
|
519
|
+
(0, _nookies.destroyCookie)(null, "refresh_token", {
|
|
524
520
|
maxAge: 2147483647,
|
|
525
521
|
path: '/',
|
|
526
522
|
domain: process.env.cookieDomain
|
|
527
523
|
});
|
|
528
|
-
(0, _nookies.destroyCookie)(
|
|
524
|
+
(0, _nookies.destroyCookie)(null, "expires_in", {
|
|
529
525
|
maxAge: 2147483647,
|
|
530
526
|
path: '/',
|
|
531
527
|
domain: process.env.cookieDomain
|
|
@@ -722,7 +718,7 @@ var apiService = function apiService() {
|
|
|
722
718
|
switch (_context8.prev = _context8.next) {
|
|
723
719
|
case 0:
|
|
724
720
|
_context8.prev = 0;
|
|
725
|
-
accessToken = (0,
|
|
721
|
+
accessToken = (0, _nookies.parseCookies)().access_token || null;
|
|
726
722
|
|
|
727
723
|
if (!accessToken) {
|
|
728
724
|
_context8.next = 11;
|
|
@@ -730,7 +726,7 @@ var apiService = function apiService() {
|
|
|
730
726
|
}
|
|
731
727
|
|
|
732
728
|
_context8.next = 5;
|
|
733
|
-
return setupDefaultOptions(
|
|
729
|
+
return setupDefaultOptions(null);
|
|
734
730
|
|
|
735
731
|
case 5:
|
|
736
732
|
defaultOptions = _context8.sent;
|
|
@@ -748,17 +744,19 @@ var apiService = function apiService() {
|
|
|
748
744
|
return _context8.abrupt("return", response.data);
|
|
749
745
|
|
|
750
746
|
case 11:
|
|
751
|
-
_context8.next =
|
|
747
|
+
_context8.next = 16;
|
|
752
748
|
break;
|
|
753
749
|
|
|
754
750
|
case 13:
|
|
755
751
|
_context8.prev = 13;
|
|
756
752
|
_context8.t0 = _context8["catch"](0);
|
|
753
|
+
//return -1;
|
|
754
|
+
console.log(_context8.t0.message);
|
|
757
755
|
|
|
758
|
-
case
|
|
756
|
+
case 16:
|
|
759
757
|
return _context8.abrupt("return", null);
|
|
760
758
|
|
|
761
|
-
case
|
|
759
|
+
case 17:
|
|
762
760
|
case "end":
|
|
763
761
|
return _context8.stop();
|
|
764
762
|
}
|
|
@@ -1109,26 +1107,6 @@ var authService = function authService() {
|
|
|
1109
1107
|
exports.authService = authService;
|
|
1110
1108
|
"use strict";
|
|
1111
1109
|
|
|
1112
|
-
Object.defineProperty(exports, "__esModule", {
|
|
1113
|
-
value: true
|
|
1114
|
-
});
|
|
1115
|
-
exports.Helper = void 0;
|
|
1116
|
-
|
|
1117
|
-
var _react = _interopRequireDefault(require("react"));
|
|
1118
|
-
|
|
1119
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
1120
|
-
|
|
1121
|
-
var Helper = function Helper() {
|
|
1122
|
-
return {
|
|
1123
|
-
isObjectEmpty: function isObjectEmpty(obj) {
|
|
1124
|
-
return Object.keys(obj).length == 0;
|
|
1125
|
-
}
|
|
1126
|
-
};
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
exports.Helper = Helper;
|
|
1130
|
-
"use strict";
|
|
1131
|
-
|
|
1132
1110
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1133
1111
|
|
|
1134
1112
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -1140,7 +1118,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
1140
1118
|
|
|
1141
1119
|
var _axios = _interopRequireDefault(require("axios"));
|
|
1142
1120
|
|
|
1143
|
-
var
|
|
1121
|
+
var _queryString = _interopRequireDefault(require("query-string"));
|
|
1144
1122
|
|
|
1145
1123
|
var _nookies = require("nookies");
|
|
1146
1124
|
|
|
@@ -1173,7 +1151,7 @@ var signInValidator = /*#__PURE__*/function () {
|
|
|
1173
1151
|
headers = {
|
|
1174
1152
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
1175
1153
|
};
|
|
1176
|
-
queryString =
|
|
1154
|
+
queryString = _queryString["default"].stringify({
|
|
1177
1155
|
code: queryCode,
|
|
1178
1156
|
grant_type: "authorization_code",
|
|
1179
1157
|
redirect_uri: window.location.origin + "/signin-oidc",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "authscape",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.92",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,12 +13,10 @@
|
|
|
13
13
|
"axios": "^0.27.2",
|
|
14
14
|
"js-file-download": "^0.4.12",
|
|
15
15
|
"next": "^12.2.0",
|
|
16
|
-
"next-cookies": "^2.0.3",
|
|
17
16
|
"nookies": "^2.5.2",
|
|
18
|
-
"querystring": "^0.2.1",
|
|
19
17
|
"react": "^17.0.2",
|
|
20
|
-
"react-
|
|
21
|
-
"react-
|
|
18
|
+
"react-data-table-component": "^7.5.2",
|
|
19
|
+
"react-dom": "^17.0.2"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
22
|
"@babel/cli": "^7.1.5",
|
|
@@ -32,9 +30,8 @@
|
|
|
32
30
|
"axios": "^0.27.2",
|
|
33
31
|
"js-file-download": "^0.4.12",
|
|
34
32
|
"next": "^12.2.0",
|
|
35
|
-
"next-cookies": "^2.0.3",
|
|
36
33
|
"nookies": "^2.5.2",
|
|
37
|
-
"
|
|
34
|
+
"query-string": "^7.1.1",
|
|
38
35
|
"react-data-table-component": "^7.5.2"
|
|
39
36
|
}
|
|
40
37
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
-
import querystring from '
|
|
2
|
+
import querystring from 'query-string';
|
|
3
3
|
import fileDownload from 'js-file-download';
|
|
4
|
-
import
|
|
5
|
-
import { setCookie, destroyCookie } from 'nookies';
|
|
6
|
-
// import Helper from "./helper";
|
|
4
|
+
import { parseCookies, setCookie, destroyCookie } from 'nookies';
|
|
7
5
|
|
|
8
|
-
const setupDefaultOptions = async (ctx =
|
|
6
|
+
const setupDefaultOptions = async (ctx = null) => {
|
|
9
7
|
|
|
10
8
|
let defaultOptions = {};
|
|
11
|
-
if (
|
|
9
|
+
if (ctx == null)
|
|
12
10
|
{
|
|
13
|
-
let accessToken =
|
|
11
|
+
let accessToken = parseCookies().access_token || '';
|
|
14
12
|
|
|
15
13
|
if (accessToken !== null && accessToken !== undefined && accessToken != "") {
|
|
16
14
|
defaultOptions = {
|
|
@@ -39,8 +37,8 @@ const setupDefaultOptions = async (ctx = {}) => {
|
|
|
39
37
|
|
|
40
38
|
const RefreshToken = async (originalRequest, instance) => {
|
|
41
39
|
|
|
42
|
-
let accessToken =
|
|
43
|
-
let refreshToken =
|
|
40
|
+
let accessToken = parseCookies().access_token || '';
|
|
41
|
+
let refreshToken = parseCookies().refresh_token || '';
|
|
44
42
|
|
|
45
43
|
let response = await instance.post(process.env.AUTHORITYURI + "/connect/token",
|
|
46
44
|
querystring.stringify({
|
|
@@ -59,13 +57,11 @@ const RefreshToken = async (originalRequest, instance) => {
|
|
|
59
57
|
{
|
|
60
58
|
originalRequest.headers['Authorization'] = 'Bearer ' + response.data.access_token;
|
|
61
59
|
|
|
62
|
-
let domain = getCookieDomain();
|
|
63
|
-
|
|
64
60
|
await setCookie(null, "access_token", response.data.access_token,
|
|
65
61
|
{
|
|
66
62
|
maxAge: 2147483647,
|
|
67
63
|
path: '/',
|
|
68
|
-
domain:
|
|
64
|
+
domain: process.env.cookieDomain,
|
|
69
65
|
secure: true
|
|
70
66
|
});
|
|
71
67
|
|
|
@@ -73,7 +69,7 @@ const RefreshToken = async (originalRequest, instance) => {
|
|
|
73
69
|
{
|
|
74
70
|
maxAge: 2147483647,
|
|
75
71
|
path: '/',
|
|
76
|
-
domain:
|
|
72
|
+
domain: process.env.cookieDomain,
|
|
77
73
|
secure: true
|
|
78
74
|
});
|
|
79
75
|
|
|
@@ -81,13 +77,13 @@ const RefreshToken = async (originalRequest, instance) => {
|
|
|
81
77
|
{
|
|
82
78
|
maxAge: 2147483647,
|
|
83
79
|
path: '/',
|
|
84
|
-
domain:
|
|
80
|
+
domain: process.env.cookieDomain,
|
|
85
81
|
secure: true
|
|
86
82
|
});
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
85
|
|
|
90
|
-
export const apiService = (ctx =
|
|
86
|
+
export const apiService = (ctx = null) => {
|
|
91
87
|
|
|
92
88
|
let env = process.env.STAGE;
|
|
93
89
|
if (env == "development")
|
|
@@ -114,7 +110,7 @@ export const apiService = (ctx = {}) => {
|
|
|
114
110
|
|
|
115
111
|
if (error.response.status === 401 && !originalConfig._retry) {
|
|
116
112
|
originalConfig._retry = true;
|
|
117
|
-
|
|
113
|
+
|
|
118
114
|
// Do something, call refreshToken() request for example;
|
|
119
115
|
await RefreshToken(originalConfig, instance);
|
|
120
116
|
|
|
@@ -127,19 +123,19 @@ export const apiService = (ctx = {}) => {
|
|
|
127
123
|
|
|
128
124
|
if (error.response.config.url.includes("/connect/token")) // remove the access and refresh if invalid
|
|
129
125
|
{
|
|
130
|
-
destroyCookie(
|
|
126
|
+
destroyCookie(null, "access_token", {
|
|
131
127
|
maxAge: 2147483647,
|
|
132
128
|
path: '/',
|
|
133
129
|
domain: process.env.cookieDomain
|
|
134
130
|
});
|
|
135
131
|
|
|
136
|
-
destroyCookie(
|
|
132
|
+
destroyCookie(null, "refresh_token", {
|
|
137
133
|
maxAge: 2147483647,
|
|
138
134
|
path: '/',
|
|
139
135
|
domain: process.env.cookieDomain
|
|
140
136
|
});
|
|
141
137
|
|
|
142
|
-
destroyCookie(
|
|
138
|
+
destroyCookie(null, "expires_in", {
|
|
143
139
|
maxAge: 2147483647,
|
|
144
140
|
path: '/',
|
|
145
141
|
domain: process.env.cookieDomain
|
|
@@ -208,19 +204,25 @@ export const apiService = (ctx = {}) => {
|
|
|
208
204
|
|
|
209
205
|
try
|
|
210
206
|
{
|
|
211
|
-
let accessToken =
|
|
207
|
+
let accessToken = parseCookies().access_token || null;
|
|
208
|
+
|
|
212
209
|
if (accessToken)
|
|
213
210
|
{
|
|
214
|
-
let defaultOptions = await setupDefaultOptions(
|
|
211
|
+
let defaultOptions = await setupDefaultOptions(null);
|
|
215
212
|
const response = await instance.get('/UserManagement', defaultOptions);
|
|
216
213
|
if (response != null && response.status == 200)
|
|
217
214
|
{
|
|
218
215
|
return response.data;
|
|
219
216
|
}
|
|
217
|
+
// else if (response != null && response.status == 401)
|
|
218
|
+
// {
|
|
219
|
+
// // call the login window maybe?
|
|
220
|
+
// }
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
} catch(exp) {
|
|
223
224
|
//return -1;
|
|
225
|
+
console.log(exp.message);
|
|
224
226
|
}
|
|
225
227
|
return null;
|
|
226
228
|
},
|