login-authorization-v2 2.0.0-beta.3 → 2.0.0-beta.6
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/dist/index.esm.js +377 -499
- package/dist/index.umd.js +396 -537
- package/package.json +27 -26
package/dist/index.esm.js
CHANGED
|
@@ -1,500 +1,378 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import Cookie from 'js-cookie';
|
|
2
|
+
import { Base64 } from 'js-base64';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
const NO_ACCESS_TOKEN = 'Access token not found';
|
|
6
|
+
const INVALID_ACCESS_TOKEN = 'Invalid access token';
|
|
7
|
+
const INVALID_REFRESH_TOKEN = 'Invalid refresh token';
|
|
8
|
+
const NO_REFRESH_TOKEN = 'Refresh token not found';
|
|
9
|
+
const NO_MODULE_BASE_URL = 'Module base URL is required';
|
|
10
|
+
const INVALID_TENANT_ID = 'Invalid tenant ID';
|
|
11
|
+
const INVALID_BRAND = 'Invalid brand';
|
|
12
|
+
|
|
13
|
+
const makeSetCookieFn = (key, options) => {
|
|
14
|
+
const index = window.location.hostname.indexOf('.');
|
|
15
|
+
const domain = index === -1
|
|
16
|
+
? window.location.hostname
|
|
17
|
+
: window.location.hostname.slice(index);
|
|
18
|
+
return (value) => {
|
|
19
|
+
if (value === null) {
|
|
20
|
+
return Cookie.remove(key, { domain, ...options });
|
|
21
|
+
}
|
|
22
|
+
Cookie.set(key, value, {
|
|
23
|
+
domain,
|
|
24
|
+
expires: 30,
|
|
25
|
+
...options
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const setIdTokenFront = makeSetCookieFn('idTokenFront');
|
|
30
|
+
const setIdTokenBack = makeSetCookieFn('idTokenBack');
|
|
31
|
+
const setRefreshTokenFront = makeSetCookieFn('refreshTokenFront');
|
|
32
|
+
const setRefreshTokenBack = makeSetCookieFn('refreshTokenBack');
|
|
33
|
+
const setRefreshToken = (token) => {
|
|
34
|
+
if (!token) {
|
|
35
|
+
setIdTokenBack(null);
|
|
36
|
+
setIdTokenFront(null);
|
|
37
|
+
makeSetCookieFn('refresh_token')(null);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const splits = token.split('.');
|
|
41
|
+
if (splits.length < 5)
|
|
42
|
+
throw new Error(INVALID_REFRESH_TOKEN);
|
|
43
|
+
const refreshTokenFront = splits[0] + '.' + splits[1];
|
|
44
|
+
const refreshTokenBack = splits[2] + '.' + splits[3] + '.' + splits[4];
|
|
45
|
+
setRefreshTokenFront(refreshTokenFront);
|
|
46
|
+
setRefreshTokenBack(refreshTokenBack);
|
|
47
|
+
makeSetCookieFn('refresh_token')(token);
|
|
48
|
+
};
|
|
49
|
+
const setAccessToken = (token) => {
|
|
50
|
+
if (!token) {
|
|
51
|
+
setIdTokenBack(null);
|
|
52
|
+
setIdTokenFront(null);
|
|
53
|
+
makeSetCookieFn('access_token')(null);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const splits = token.split('.');
|
|
57
|
+
if (splits.length < 3)
|
|
58
|
+
throw new Error(INVALID_ACCESS_TOKEN);
|
|
59
|
+
const idTokenFront = splits[0] + '.' + splits[1];
|
|
60
|
+
const idTokenBack = splits[2] || '';
|
|
61
|
+
setIdTokenFront(idTokenFront);
|
|
62
|
+
setIdTokenBack(idTokenBack);
|
|
63
|
+
makeSetCookieFn('access_token')(token);
|
|
64
|
+
};
|
|
65
|
+
const getAccessToken = () => Cookie.get('access_token');
|
|
66
|
+
const getRefreshToken = () => Cookie.get('refresh_token');
|
|
67
|
+
const setSystemType = makeSetCookieFn('currentSystemType');
|
|
68
|
+
const getSystemType = () => Cookie.get('currentSystemType');
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 这个文件是写一些兼容的方法,避免各个项目做出大量调整
|
|
8
72
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
316
|
-
|
|
317
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"setIdToken\": () => (/* binding */ setIdToken),\n/* harmony export */ \"getIdToken\": () => (/* binding */ getIdToken),\n/* harmony export */ \"setCookie\": () => (/* binding */ setCookie),\n/* harmony export */ \"clearLoginCookie\": () => (/* binding */ clearLoginCookie),\n/* harmony export */ \"getCookie\": () => (/* binding */ getCookie),\n/* harmony export */ \"getUrlParam\": () => (/* binding */ getUrlParam)\n/* harmony export */ });\n/* harmony import */ var _cookie__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./cookie */ \"./src/cookie.ts\");\n/* harmony import */ var js_cookie__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! js-cookie */ \"./node_modules/js-cookie/dist/js.cookie.mjs\");\n/**\n * 这个文件是写一些兼容的方法,避免各个项目做出大量调整\n */\n\n\nconst setIdToken = _cookie__WEBPACK_IMPORTED_MODULE_0__.setAccessToken;\nconst getIdToken = _cookie__WEBPACK_IMPORTED_MODULE_0__.getAccessToken;\nconst setCookie = (name, value, domain, path = '/', time = 30 * 24 * 60 * 60 * 1000) => {\n if (value === null || value === undefined) {\n return js_cookie__WEBPACK_IMPORTED_MODULE_1__[\"default\"].remove(name);\n }\n js_cookie__WEBPACK_IMPORTED_MODULE_1__[\"default\"].set(name, value, {\n domain,\n path,\n expires: time / (24 * 60 * 60 * 1000)\n });\n};\nconst clearLoginCookie = () => {\n (0,_cookie__WEBPACK_IMPORTED_MODULE_0__.setAccessToken)(null);\n (0,_cookie__WEBPACK_IMPORTED_MODULE_0__.setRefreshToken)(null);\n};\nconst getCookie = (c_name) => {\n if (!c_name)\n return null;\n const reg = new RegExp('(?:^|; )' + encodeURIComponent(c_name) + '=([^;]*)');\n const result = reg.exec(document.cookie);\n return result ? decodeURIComponent(result[1] || '') : null;\n};\nconst getUrlParam = (key, href) => {\n const search = '?' + ((href || window.location.href).split('?')[1] || '');\n const searchParams = new URLSearchParams(search);\n return searchParams.get(key);\n};\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/compatible.ts?");
|
|
318
|
-
|
|
319
|
-
/***/ }),
|
|
320
|
-
|
|
321
|
-
/***/ "./src/constance.ts":
|
|
322
|
-
/*!**************************!*\
|
|
323
|
-
!*** ./src/constance.ts ***!
|
|
324
|
-
\**************************/
|
|
325
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
326
|
-
|
|
327
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"NO_ACCESS_TOKEN\": () => (/* binding */ NO_ACCESS_TOKEN),\n/* harmony export */ \"INVALID_ACCESS_TOKEN\": () => (/* binding */ INVALID_ACCESS_TOKEN),\n/* harmony export */ \"INVALID_REFRESH_TOKEN\": () => (/* binding */ INVALID_REFRESH_TOKEN),\n/* harmony export */ \"NO_REFRESH_TOKEN\": () => (/* binding */ NO_REFRESH_TOKEN),\n/* harmony export */ \"NO_MODULE_BASE_URL\": () => (/* binding */ NO_MODULE_BASE_URL),\n/* harmony export */ \"INVALID_TENANT_ID\": () => (/* binding */ INVALID_TENANT_ID),\n/* harmony export */ \"INVALID_BRAND\": () => (/* binding */ INVALID_BRAND)\n/* harmony export */ });\nconst NO_ACCESS_TOKEN = 'Access token not found';\nconst INVALID_ACCESS_TOKEN = 'Invalid access token';\nconst INVALID_REFRESH_TOKEN = 'Invalid refresh token';\nconst NO_REFRESH_TOKEN = 'Refresh token not found';\nconst NO_MODULE_BASE_URL = 'Module base URL is required';\nconst INVALID_TENANT_ID = 'Invalid tenant ID';\nconst INVALID_BRAND = 'Invalid brand';\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/constance.ts?");
|
|
328
|
-
|
|
329
|
-
/***/ }),
|
|
330
|
-
|
|
331
|
-
/***/ "./src/cookie.ts":
|
|
332
|
-
/*!***********************!*\
|
|
333
|
-
!*** ./src/cookie.ts ***!
|
|
334
|
-
\***********************/
|
|
335
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
336
|
-
|
|
337
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"setRefreshToken\": () => (/* binding */ setRefreshToken),\n/* harmony export */ \"setAccessToken\": () => (/* binding */ setAccessToken),\n/* harmony export */ \"getAccessToken\": () => (/* binding */ getAccessToken),\n/* harmony export */ \"getRefreshToken\": () => (/* binding */ getRefreshToken),\n/* harmony export */ \"setSystemType\": () => (/* binding */ setSystemType),\n/* harmony export */ \"getSystemType\": () => (/* binding */ getSystemType)\n/* harmony export */ });\n/* harmony import */ var js_cookie__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! js-cookie */ \"./node_modules/js-cookie/dist/js.cookie.mjs\");\n/* harmony import */ var _constance__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constance */ \"./src/constance.ts\");\n\n\nconst makeSetCookieFn = (key, options) => {\n const index = window.location.hostname.indexOf('.');\n const domain = index === -1\n ? window.location.hostname\n : window.location.hostname.slice(index);\n return (value) => {\n if (value === null) {\n return js_cookie__WEBPACK_IMPORTED_MODULE_0__[\"default\"].remove(key, { domain, ...options });\n }\n js_cookie__WEBPACK_IMPORTED_MODULE_0__[\"default\"].set(key, value, {\n domain,\n expires: 30,\n ...options\n });\n };\n};\nconst setIdTokenFront = makeSetCookieFn('idTokenFront');\nconst setIdTokenBack = makeSetCookieFn('idTokenBack');\nconst setRefreshTokenFront = makeSetCookieFn('refreshTokenFront');\nconst setRefreshTokenBack = makeSetCookieFn('refreshTokenBack');\nconst setRefreshToken = (token) => {\n if (!token) {\n setIdTokenBack(null);\n setIdTokenFront(null);\n makeSetCookieFn('refresh_token')(null);\n return;\n }\n const splits = token.split('.');\n if (splits.length < 5)\n throw new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.INVALID_REFRESH_TOKEN);\n const refreshTokenFront = splits[0] + '.' + splits[1];\n const refreshTokenBack = splits[2] + '.' + splits[3] + '.' + splits[4];\n setRefreshTokenFront(refreshTokenFront);\n setRefreshTokenBack(refreshTokenBack);\n makeSetCookieFn('refresh_token')(token);\n};\nconst setAccessToken = (token) => {\n if (!token) {\n setIdTokenBack(null);\n setIdTokenFront(null);\n makeSetCookieFn('access_token')(null);\n return;\n }\n const splits = token.split('.');\n if (splits.length < 3)\n throw new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.INVALID_ACCESS_TOKEN);\n const idTokenFront = splits[0] + '.' + splits[1];\n const idTokenBack = splits[2] || '';\n setIdTokenFront(idTokenFront);\n setIdTokenBack(idTokenBack);\n makeSetCookieFn('access_token')(token);\n};\nconst getAccessToken = () => js_cookie__WEBPACK_IMPORTED_MODULE_0__[\"default\"].get('access_token');\nconst getRefreshToken = () => js_cookie__WEBPACK_IMPORTED_MODULE_0__[\"default\"].get('refresh_token');\nconst setSystemType = makeSetCookieFn('currentSystemType');\nconst getSystemType = () => js_cookie__WEBPACK_IMPORTED_MODULE_0__[\"default\"].get('currentSystemType');\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/cookie.ts?");
|
|
338
|
-
|
|
339
|
-
/***/ }),
|
|
340
|
-
|
|
341
|
-
/***/ "./src/dom.ts":
|
|
342
|
-
/*!********************!*\
|
|
343
|
-
!*** ./src/dom.ts ***!
|
|
344
|
-
\********************/
|
|
345
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
346
|
-
|
|
347
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"closeDialog\": () => (/* binding */ closeDialog),\n/* harmony export */ \"openDialog\": () => (/* binding */ openDialog)\n/* harmony export */ });\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ \"./src/utils.ts\");\n/* harmony import */ var _shares__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./shares */ \"./src/shares.ts\");\n\n\nconst createPcDialog = () => {\n return `<div id=\"confirm-container\" style=\"box-sizing:border-box;position:fixed;width:615px;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left: 35%;padding:20px 20px;top:10px;font-size: 16px;\">\n <div id=\"href\" style=\"color: rgb(32,33,36);\"></div>\n <div style=\"margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;\">You do not have access to the system.</div>\n <div style=\"display: flex;justify-content: flex-end;\">\n <button id=\"cancel\" style=\"padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;\">Cancel</button>\n <button id=\"confirm\" style=\"padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;\">Sign in to another ZERO account</button>\n </div>\n </div>`;\n};\nconst createMobileDialog = () => {\n return `<div id=\"confirm-container\" style=\"box-sizing:border-box;position:fixed;width:97.6vw;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left:0px;padding:20px 20px;top:4px;margin:0 4px;font-size: 16px;\">\n <div id=\"href\" style=\"color: rgb(32,33,36);\"></div>\n <div style=\"margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;\">You do not have access to the system.</div>\n <div style=\"display: flex;justify-content: flex-end;\">\n <div style=\"display: flex;justify-content: flex-end;\">\n <button id=\"cancel\" style=\"padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;\">Cancel</button>\n <button id=\"confirm\" style=\"padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;\">Sign in to another ZERO account</button>\n </div>\n </div>\n </div>`;\n};\nconst onConfirmHandler = (evt) => {\n closeDialog();\n window.location.href = _shares__WEBPACK_IMPORTED_MODULE_1__.loginPageUrl;\n};\nconst onCancelHandler = () => {\n closeDialog();\n window.location.href = 'about:blank';\n};\nconst closeDialog = () => {\n const container = document.getElementById('confirm-container');\n if (!container || !container.parentNode)\n return;\n document.body.removeChild(container.parentNode);\n};\nconst openDialog = () => {\n const container = document.createElement('div');\n (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isMobile)()\n ? container.innerHTML = createMobileDialog()\n : container.innerHTML = createPcDialog();\n const confirmButton = container.querySelector('#confirm');\n const cancelButton = container.querySelector('#cancel');\n confirmButton?.addEventListener('click', onConfirmHandler);\n cancelButton?.addEventListener('click', onCancelHandler);\n document.body.appendChild(container);\n};\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/dom.ts?");
|
|
348
|
-
|
|
349
|
-
/***/ }),
|
|
350
|
-
|
|
351
|
-
/***/ "./src/request.ts":
|
|
352
|
-
/*!************************!*\
|
|
353
|
-
!*** ./src/request.ts ***!
|
|
354
|
-
\************************/
|
|
355
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
356
|
-
|
|
357
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"initInstance\": () => (/* binding */ initInstance),\n/* harmony export */ \"fetchRefreshTokenHTTP\": () => (/* binding */ fetchRefreshTokenHTTP),\n/* harmony export */ \"fetchLogoutHTTP\": () => (/* binding */ fetchLogoutHTTP),\n/* harmony export */ \"fetchServerListHTTP\": () => (/* binding */ fetchServerListHTTP)\n/* harmony export */ });\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _shares__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./shares */ \"./src/shares.ts\");\n/* harmony import */ var _cookie__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./cookie */ \"./src/cookie.ts\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils */ \"./src/utils.ts\");\n\n\n\n\nlet instance;\n/**\n * 没找到更好的方式,只能这样做了\n */\nconst initInstance = async () => {\n let userInfo = null;\n try {\n userInfo = await (0,_utils__WEBPACK_IMPORTED_MODULE_3__.getUserInfo)();\n }\n catch (error) {\n console.warn('initInstance getUserInfo error:', error);\n }\n instance = axios__WEBPACK_IMPORTED_MODULE_0___default().create({\n baseURL: _shares__WEBPACK_IMPORTED_MODULE_1__.moduleBaseUrl,\n timeout: 1.5e4,\n headers: {\n 'X-tenant-id': userInfo ? userInfo['custom:tenant_id'].toString() : _shares__WEBPACK_IMPORTED_MODULE_1__.tenantId.toString(),\n 'X-brand': _shares__WEBPACK_IMPORTED_MODULE_1__.brand.toString(),\n 'Authorization': `Bearer ${(0,_cookie__WEBPACK_IMPORTED_MODULE_2__.getAccessToken)()}`,\n }\n });\n instance.interceptors.request.use((config) => {\n return config;\n }, (error) => {\n return Promise.reject(error);\n });\n instance.interceptors.response.use((response) => {\n if (response.data.code !== 200) {\n return Promise.reject(response.data.msg);\n }\n return response;\n }, (error) => {\n return Promise.reject(error);\n });\n};\nconst fetchRefreshTokenHTTP = (refreshToken) => {\n return instance({\n method: 'post',\n url: '/user-profile/refresh-token/refresh',\n data: {\n refreshToken\n }\n });\n};\nconst fetchLogoutHTTP = () => {\n return instance({\n method: 'get',\n url: '/user-profile/logout'\n });\n};\nconst fetchServerListHTTP = () => {\n return instance({\n method: 'get',\n url: '/session/current/servers'\n });\n};\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/request.ts?");
|
|
358
|
-
|
|
359
|
-
/***/ }),
|
|
360
|
-
|
|
361
|
-
/***/ "./src/shares.ts":
|
|
362
|
-
/*!***********************!*\
|
|
363
|
-
!*** ./src/shares.ts ***!
|
|
364
|
-
\***********************/
|
|
365
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
366
|
-
|
|
367
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"tenantId\": () => (/* binding */ tenantId),\n/* harmony export */ \"brand\": () => (/* binding */ brand),\n/* harmony export */ \"moduleBaseUrl\": () => (/* binding */ moduleBaseUrl),\n/* harmony export */ \"loginPageUrl\": () => (/* binding */ loginPageUrl),\n/* harmony export */ \"setTenantId\": () => (/* binding */ setTenantId),\n/* harmony export */ \"setBrand\": () => (/* binding */ setBrand),\n/* harmony export */ \"setModuleBaseUrl\": () => (/* binding */ setModuleBaseUrl),\n/* harmony export */ \"setLoginPageUrl\": () => (/* binding */ setLoginPageUrl)\n/* harmony export */ });\n/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./types */ \"./src/types.ts\");\n/* harmony import */ var _constance__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constance */ \"./src/constance.ts\");\n\n\nlet tenantId;\nlet brand;\nlet moduleBaseUrl = '';\nlet loginPageUrl = '';\nconst setTenantId = (id) => {\n if (!Object.values(_types__WEBPACK_IMPORTED_MODULE_0__.Tenant).includes(id)) {\n throw new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.INVALID_TENANT_ID);\n }\n tenantId = id;\n};\nconst setBrand = (id) => {\n if (!Object.values(_types__WEBPACK_IMPORTED_MODULE_0__.Brand).includes(id)) {\n throw new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.INVALID_BRAND);\n }\n brand = id;\n};\nconst setModuleBaseUrl = (url) => {\n moduleBaseUrl = url;\n};\nconst setLoginPageUrl = (url) => {\n loginPageUrl = url;\n};\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/shares.ts?");
|
|
368
|
-
|
|
369
|
-
/***/ }),
|
|
370
|
-
|
|
371
|
-
/***/ "./src/types.ts":
|
|
372
|
-
/*!**********************!*\
|
|
373
|
-
!*** ./src/types.ts ***!
|
|
374
|
-
\**********************/
|
|
375
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
376
|
-
|
|
377
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Brand\": () => (/* binding */ Brand),\n/* harmony export */ \"Tenant\": () => (/* binding */ Tenant),\n/* harmony export */ \"SystemType\": () => (/* binding */ SystemType)\n/* harmony export */ });\nconst modules = [\n {\n href: '',\n name: 'commonLogin'\n },\n {\n href: '',\n name: 'App'\n },\n {\n href: '',\n name: 'Portal'\n },\n {\n href: '',\n name: 'AgentPortal'\n },\n {\n href: '',\n name: 'AdminPortal'\n },\n {\n href: '',\n name: 'CRM'\n },\n {\n href: '',\n name: 'Finance'\n },\n {\n href: '',\n name: 'FundingAdmin'\n },\n {\n href: '',\n name: 'MessageTemplate'\n },\n {\n href: '',\n name: 'Translate'\n },\n {\n href: '',\n name: 'TradeConfig'\n },\n {\n href: '',\n name: 'Ticket'\n },\n {\n href: '',\n name: 'IBPortalAdmin'\n },\n {\n href: '',\n name: 'OPPortal'\n },\n {\n href: '',\n name: 'ClientInfoHub'\n },\n {\n href: '',\n name: 'Promotion'\n }\n];\nvar Brand;\n(function (Brand) {\n Brand[Brand[\"ZERO\"] = 1] = \"ZERO\";\n Brand[Brand[\"HEDGEHOOD\"] = 2] = \"HEDGEHOOD\";\n Brand[Brand[\"NISE\"] = 3] = \"NISE\";\n})(Brand || (Brand = {}));\nvar Tenant;\n(function (Tenant) {\n Tenant[Tenant[\"ZERO_INT\"] = 1] = \"ZERO_INT\";\n Tenant[Tenant[\"HEDGEHOOD\"] = 2] = \"HEDGEHOOD\";\n Tenant[Tenant[\"ZERO_NZ\"] = 3] = \"ZERO_NZ\";\n Tenant[Tenant[\"ZERO_LA\"] = 4] = \"ZERO_LA\";\n Tenant[Tenant[\"ZERO_BR\"] = 4] = \"ZERO_BR\";\n Tenant[Tenant[\"NISE_EU\"] = 5] = \"NISE_EU\";\n})(Tenant || (Tenant = {}));\nvar SystemType;\n(function (SystemType) {\n SystemType[\"Staff\"] = \"staff\";\n SystemType[\"Client\"] = \"client\";\n})(SystemType || (SystemType = {}));\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/types.ts?");
|
|
378
|
-
|
|
379
|
-
/***/ }),
|
|
380
|
-
|
|
381
|
-
/***/ "./src/utils.ts":
|
|
382
|
-
/*!**********************!*\
|
|
383
|
-
!*** ./src/utils.ts ***!
|
|
384
|
-
\**********************/
|
|
385
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
386
|
-
|
|
387
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"isMobile\": () => (/* binding */ isMobile),\n/* harmony export */ \"getUserInfo\": () => (/* binding */ getUserInfo)\n/* harmony export */ });\n/* harmony import */ var _cookie__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./cookie */ \"./src/cookie.ts\");\n/* harmony import */ var _constance__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constance */ \"./src/constance.ts\");\n/* harmony import */ var js_base64__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! js-base64 */ \"./node_modules/js-base64/base64.mjs\");\n\n\n\nconst isMobile = () => {\n const ua = navigator.userAgent;\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);\n};\nconst getUserInfo = () => {\n return new Promise((resolve, reject) => {\n const token = (0,_cookie__WEBPACK_IMPORTED_MODULE_0__.getAccessToken)();\n if (!token)\n return reject(new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.NO_ACCESS_TOKEN));\n const splits = token.split('.');\n if (splits.length < 3)\n return reject(new Error(_constance__WEBPACK_IMPORTED_MODULE_1__.NO_ACCESS_TOKEN));\n resolve(JSON.parse(js_base64__WEBPACK_IMPORTED_MODULE_2__.Base64.decode(splits[1])));\n });\n};\n\n\n//# sourceURL=webpack://login-authorization-v2/./src/utils.ts?");
|
|
388
|
-
|
|
389
|
-
/***/ }),
|
|
390
|
-
|
|
391
|
-
/***/ "./node_modules/js-base64/base64.mjs":
|
|
392
|
-
/*!*******************************************!*\
|
|
393
|
-
!*** ./node_modules/js-base64/base64.mjs ***!
|
|
394
|
-
\*******************************************/
|
|
395
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
396
|
-
|
|
397
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"version\": () => (/* binding */ version),\n/* harmony export */ \"VERSION\": () => (/* binding */ VERSION),\n/* harmony export */ \"atob\": () => (/* binding */ _atob),\n/* harmony export */ \"atobPolyfill\": () => (/* binding */ atobPolyfill),\n/* harmony export */ \"btoa\": () => (/* binding */ _btoa),\n/* harmony export */ \"btoaPolyfill\": () => (/* binding */ btoaPolyfill),\n/* harmony export */ \"fromBase64\": () => (/* binding */ decode),\n/* harmony export */ \"toBase64\": () => (/* binding */ encode),\n/* harmony export */ \"utob\": () => (/* binding */ utob),\n/* harmony export */ \"encode\": () => (/* binding */ encode),\n/* harmony export */ \"encodeURI\": () => (/* binding */ encodeURI),\n/* harmony export */ \"encodeURL\": () => (/* binding */ encodeURI),\n/* harmony export */ \"btou\": () => (/* binding */ btou),\n/* harmony export */ \"decode\": () => (/* binding */ decode),\n/* harmony export */ \"isValid\": () => (/* binding */ isValid),\n/* harmony export */ \"fromUint8Array\": () => (/* binding */ fromUint8Array),\n/* harmony export */ \"toUint8Array\": () => (/* binding */ toUint8Array),\n/* harmony export */ \"extendString\": () => (/* binding */ extendString),\n/* harmony export */ \"extendUint8Array\": () => (/* binding */ extendUint8Array),\n/* harmony export */ \"extendBuiltins\": () => (/* binding */ extendBuiltins),\n/* harmony export */ \"Base64\": () => (/* binding */ gBase64)\n/* harmony export */ });\n/**\n * base64.ts\n *\n * Licensed under the BSD 3-Clause License.\n * http://opensource.org/licenses/BSD-3-Clause\n *\n * References:\n * http://en.wikipedia.org/wiki/Base64\n *\n * @author Dan Kogai (https://github.com/dankogai)\n */\nconst version = '3.7.7';\n/**\n * @deprecated use lowercase `version`.\n */\nconst VERSION = version;\nconst _hasBuffer = typeof Buffer === 'function';\nconst _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;\nconst _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;\nconst b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\nconst b64chs = Array.prototype.slice.call(b64ch);\nconst b64tab = ((a) => {\n let tab = {};\n a.forEach((c, i) => tab[c] = i);\n return tab;\n})(b64chs);\nconst b64re = /^(?:[A-Za-z\\d+\\/]{4})*?(?:[A-Za-z\\d+\\/]{2}(?:==)?|[A-Za-z\\d+\\/]{3}=?)?$/;\nconst _fromCC = String.fromCharCode.bind(String);\nconst _U8Afrom = typeof Uint8Array.from === 'function'\n ? Uint8Array.from.bind(Uint8Array)\n : (it) => new Uint8Array(Array.prototype.slice.call(it, 0));\nconst _mkUriSafe = (src) => src\n .replace(/=/g, '').replace(/[+\\/]/g, (m0) => m0 == '+' ? '-' : '_');\nconst _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\\+\\/]/g, '');\n/**\n * polyfill version of `btoa`\n */\nconst btoaPolyfill = (bin) => {\n // console.log('polyfilled');\n let u32, c0, c1, c2, asc = '';\n const pad = bin.length % 3;\n for (let i = 0; i < bin.length;) {\n if ((c0 = bin.charCodeAt(i++)) > 255 ||\n (c1 = bin.charCodeAt(i++)) > 255 ||\n (c2 = bin.charCodeAt(i++)) > 255)\n throw new TypeError('invalid character found');\n u32 = (c0 << 16) | (c1 << 8) | c2;\n asc += b64chs[u32 >> 18 & 63]\n + b64chs[u32 >> 12 & 63]\n + b64chs[u32 >> 6 & 63]\n + b64chs[u32 & 63];\n }\n return pad ? asc.slice(0, pad - 3) + \"===\".substring(pad) : asc;\n};\n/**\n * does what `window.btoa` of web browsers do.\n * @param {String} bin binary string\n * @returns {string} Base64-encoded string\n */\nconst _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)\n : _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')\n : btoaPolyfill;\nconst _fromUint8Array = _hasBuffer\n ? (u8a) => Buffer.from(u8a).toString('base64')\n : (u8a) => {\n // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326\n const maxargs = 0x1000;\n let strs = [];\n for (let i = 0, l = u8a.length; i < l; i += maxargs) {\n strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));\n }\n return _btoa(strs.join(''));\n };\n/**\n * converts a Uint8Array to a Base64 string.\n * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5\n * @returns {string} Base64 string\n */\nconst fromUint8Array = (u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);\n// This trick is found broken https://github.com/dankogai/js-base64/issues/130\n// const utob = (src: string) => unescape(encodeURIComponent(src));\n// reverting good old fationed regexp\nconst cb_utob = (c) => {\n if (c.length < 2) {\n var cc = c.charCodeAt(0);\n return cc < 0x80 ? c\n : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))\n + _fromCC(0x80 | (cc & 0x3f)))\n : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))\n + _fromCC(0x80 | ((cc >>> 6) & 0x3f))\n + _fromCC(0x80 | (cc & 0x3f)));\n }\n else {\n var cc = 0x10000\n + (c.charCodeAt(0) - 0xD800) * 0x400\n + (c.charCodeAt(1) - 0xDC00);\n return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))\n + _fromCC(0x80 | ((cc >>> 12) & 0x3f))\n + _fromCC(0x80 | ((cc >>> 6) & 0x3f))\n + _fromCC(0x80 | (cc & 0x3f)));\n }\n};\nconst re_utob = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFFF]|[^\\x00-\\x7F]/g;\n/**\n * @deprecated should have been internal use only.\n * @param {string} src UTF-8 string\n * @returns {string} UTF-16 string\n */\nconst utob = (u) => u.replace(re_utob, cb_utob);\n//\nconst _encode = _hasBuffer\n ? (s) => Buffer.from(s, 'utf8').toString('base64')\n : _TE\n ? (s) => _fromUint8Array(_TE.encode(s))\n : (s) => _btoa(utob(s));\n/**\n * converts a UTF-8-encoded string to a Base64 string.\n * @param {boolean} [urlsafe] if `true` make the result URL-safe\n * @returns {string} Base64 string\n */\nconst encode = (src, urlsafe = false) => urlsafe\n ? _mkUriSafe(_encode(src))\n : _encode(src);\n/**\n * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.\n * @returns {string} Base64 string\n */\nconst encodeURI = (src) => encode(src, true);\n// This trick is found broken https://github.com/dankogai/js-base64/issues/130\n// const btou = (src: string) => decodeURIComponent(escape(src));\n// reverting good old fationed regexp\nconst re_btou = /[\\xC0-\\xDF][\\x80-\\xBF]|[\\xE0-\\xEF][\\x80-\\xBF]{2}|[\\xF0-\\xF7][\\x80-\\xBF]{3}/g;\nconst cb_btou = (cccc) => {\n switch (cccc.length) {\n case 4:\n var cp = ((0x07 & cccc.charCodeAt(0)) << 18)\n | ((0x3f & cccc.charCodeAt(1)) << 12)\n | ((0x3f & cccc.charCodeAt(2)) << 6)\n | (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;\n return (_fromCC((offset >>> 10) + 0xD800)\n + _fromCC((offset & 0x3FF) + 0xDC00));\n case 3:\n return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)\n | ((0x3f & cccc.charCodeAt(1)) << 6)\n | (0x3f & cccc.charCodeAt(2)));\n default:\n return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)\n | (0x3f & cccc.charCodeAt(1)));\n }\n};\n/**\n * @deprecated should have been internal use only.\n * @param {string} src UTF-16 string\n * @returns {string} UTF-8 string\n */\nconst btou = (b) => b.replace(re_btou, cb_btou);\n/**\n * polyfill version of `atob`\n */\nconst atobPolyfill = (asc) => {\n // console.log('polyfilled');\n asc = asc.replace(/\\s+/g, '');\n if (!b64re.test(asc))\n throw new TypeError('malformed base64.');\n asc += '=='.slice(2 - (asc.length & 3));\n let u24, bin = '', r1, r2;\n for (let i = 0; i < asc.length;) {\n u24 = b64tab[asc.charAt(i++)] << 18\n | b64tab[asc.charAt(i++)] << 12\n | (r1 = b64tab[asc.charAt(i++)]) << 6\n | (r2 = b64tab[asc.charAt(i++)]);\n bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)\n : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)\n : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);\n }\n return bin;\n};\n/**\n * does what `window.atob` of web browsers do.\n * @param {String} asc Base64-encoded string\n * @returns {string} binary string\n */\nconst _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))\n : _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')\n : atobPolyfill;\n//\nconst _toUint8Array = _hasBuffer\n ? (a) => _U8Afrom(Buffer.from(a, 'base64'))\n : (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));\n/**\n * converts a Base64 string to a Uint8Array.\n */\nconst toUint8Array = (a) => _toUint8Array(_unURI(a));\n//\nconst _decode = _hasBuffer\n ? (a) => Buffer.from(a, 'base64').toString('utf8')\n : _TD\n ? (a) => _TD.decode(_toUint8Array(a))\n : (a) => btou(_atob(a));\nconst _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));\n/**\n * converts a Base64 string to a UTF-8 string.\n * @param {String} src Base64 string. Both normal and URL-safe are supported\n * @returns {string} UTF-8 string\n */\nconst decode = (src) => _decode(_unURI(src));\n/**\n * check if a value is a valid Base64 string\n * @param {String} src a value to check\n */\nconst isValid = (src) => {\n if (typeof src !== 'string')\n return false;\n const s = src.replace(/\\s+/g, '').replace(/={0,2}$/, '');\n return !/[^\\s0-9a-zA-Z\\+/]/.test(s) || !/[^\\s0-9a-zA-Z\\-_]/.test(s);\n};\n//\nconst _noEnum = (v) => {\n return {\n value: v, enumerable: false, writable: true, configurable: true\n };\n};\n/**\n * extend String.prototype with relevant methods\n */\nconst extendString = function () {\n const _add = (name, body) => Object.defineProperty(String.prototype, name, _noEnum(body));\n _add('fromBase64', function () { return decode(this); });\n _add('toBase64', function (urlsafe) { return encode(this, urlsafe); });\n _add('toBase64URI', function () { return encode(this, true); });\n _add('toBase64URL', function () { return encode(this, true); });\n _add('toUint8Array', function () { return toUint8Array(this); });\n};\n/**\n * extend Uint8Array.prototype with relevant methods\n */\nconst extendUint8Array = function () {\n const _add = (name, body) => Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));\n _add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });\n _add('toBase64URI', function () { return fromUint8Array(this, true); });\n _add('toBase64URL', function () { return fromUint8Array(this, true); });\n};\n/**\n * extend Builtin prototypes with relevant methods\n */\nconst extendBuiltins = () => {\n extendString();\n extendUint8Array();\n};\nconst gBase64 = {\n version: version,\n VERSION: VERSION,\n atob: _atob,\n atobPolyfill: atobPolyfill,\n btoa: _btoa,\n btoaPolyfill: btoaPolyfill,\n fromBase64: decode,\n toBase64: encode,\n encode: encode,\n encodeURI: encodeURI,\n encodeURL: encodeURI,\n utob: utob,\n btou: btou,\n decode: decode,\n isValid: isValid,\n fromUint8Array: fromUint8Array,\n toUint8Array: toUint8Array,\n extendString: extendString,\n extendUint8Array: extendUint8Array,\n extendBuiltins: extendBuiltins\n};\n// makecjs:CUT //\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n// and finally,\n\n\n\n//# sourceURL=webpack://login-authorization-v2/./node_modules/js-base64/base64.mjs?");
|
|
398
|
-
|
|
399
|
-
/***/ }),
|
|
400
|
-
|
|
401
|
-
/***/ "./node_modules/js-cookie/dist/js.cookie.mjs":
|
|
402
|
-
/*!***************************************************!*\
|
|
403
|
-
!*** ./node_modules/js-cookie/dist/js.cookie.mjs ***!
|
|
404
|
-
\***************************************************/
|
|
405
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
406
|
-
|
|
407
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ api)\n/* harmony export */ });\n/*! js-cookie v3.0.5 | MIT */\n/* eslint-disable no-var */\nfunction assign (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n for (var key in source) {\n target[key] = source[key];\n }\n }\n return target\n}\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\nvar defaultConverter = {\n read: function (value) {\n if (value[0] === '\"') {\n value = value.slice(1, -1);\n }\n return value.replace(/(%[\\dA-F]{2})+/gi, decodeURIComponent)\n },\n write: function (value) {\n return encodeURIComponent(value).replace(\n /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,\n decodeURIComponent\n )\n }\n};\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\n\nfunction init (converter, defaultAttributes) {\n function set (name, value, attributes) {\n if (typeof document === 'undefined') {\n return\n }\n\n attributes = assign({}, defaultAttributes, attributes);\n\n if (typeof attributes.expires === 'number') {\n attributes.expires = new Date(Date.now() + attributes.expires * 864e5);\n }\n if (attributes.expires) {\n attributes.expires = attributes.expires.toUTCString();\n }\n\n name = encodeURIComponent(name)\n .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)\n .replace(/[()]/g, escape);\n\n var stringifiedAttributes = '';\n for (var attributeName in attributes) {\n if (!attributes[attributeName]) {\n continue\n }\n\n stringifiedAttributes += '; ' + attributeName;\n\n if (attributes[attributeName] === true) {\n continue\n }\n\n // Considers RFC 6265 section 5.2:\n // ...\n // 3. If the remaining unparsed-attributes contains a %x3B (\";\")\n // character:\n // Consume the characters of the unparsed-attributes up to,\n // not including, the first %x3B (\";\") character.\n // ...\n stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];\n }\n\n return (document.cookie =\n name + '=' + converter.write(value, name) + stringifiedAttributes)\n }\n\n function get (name) {\n if (typeof document === 'undefined' || (arguments.length && !name)) {\n return\n }\n\n // To prevent the for loop in the first place assign an empty array\n // in case there are no cookies at all.\n var cookies = document.cookie ? document.cookie.split('; ') : [];\n var jar = {};\n for (var i = 0; i < cookies.length; i++) {\n var parts = cookies[i].split('=');\n var value = parts.slice(1).join('=');\n\n try {\n var found = decodeURIComponent(parts[0]);\n jar[found] = converter.read(value, found);\n\n if (name === found) {\n break\n }\n } catch (e) {}\n }\n\n return name ? jar[name] : jar\n }\n\n return Object.create(\n {\n set,\n get,\n remove: function (name, attributes) {\n set(\n name,\n '',\n assign({}, attributes, {\n expires: -1\n })\n );\n },\n withAttributes: function (attributes) {\n return init(this.converter, assign({}, this.attributes, attributes))\n },\n withConverter: function (converter) {\n return init(assign({}, this.converter, converter), this.attributes)\n }\n },\n {\n attributes: { value: Object.freeze(defaultAttributes) },\n converter: { value: Object.freeze(converter) }\n }\n )\n}\n\nvar api = init(defaultConverter, { path: '/' });\n/* eslint-enable no-var */\n\n\n\n\n//# sourceURL=webpack://login-authorization-v2/./node_modules/js-cookie/dist/js.cookie.mjs?");
|
|
408
|
-
|
|
409
|
-
/***/ })
|
|
410
|
-
|
|
411
|
-
/******/ });
|
|
412
|
-
/************************************************************************/
|
|
413
|
-
/******/ // The module cache
|
|
414
|
-
/******/ var __webpack_module_cache__ = {};
|
|
415
|
-
/******/
|
|
416
|
-
/******/ // The require function
|
|
417
|
-
/******/ function __webpack_require__(moduleId) {
|
|
418
|
-
/******/ // Check if module is in cache
|
|
419
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
420
|
-
/******/ if (cachedModule !== undefined) {
|
|
421
|
-
/******/ return cachedModule.exports;
|
|
422
|
-
/******/ }
|
|
423
|
-
/******/ // Create a new module (and put it into the cache)
|
|
424
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
425
|
-
/******/ // no module.id needed
|
|
426
|
-
/******/ // no module.loaded needed
|
|
427
|
-
/******/ exports: {}
|
|
428
|
-
/******/ };
|
|
429
|
-
/******/
|
|
430
|
-
/******/ // Execute the module function
|
|
431
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
432
|
-
/******/
|
|
433
|
-
/******/ // Return the exports of the module
|
|
434
|
-
/******/ return module.exports;
|
|
435
|
-
/******/ }
|
|
436
|
-
/******/
|
|
437
|
-
/************************************************************************/
|
|
438
|
-
/******/ /* webpack/runtime/compat get default export */
|
|
439
|
-
/******/ (() => {
|
|
440
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
441
|
-
/******/ __webpack_require__.n = (module) => {
|
|
442
|
-
/******/ var getter = module && module.__esModule ?
|
|
443
|
-
/******/ () => (module['default']) :
|
|
444
|
-
/******/ () => (module);
|
|
445
|
-
/******/ __webpack_require__.d(getter, { a: getter });
|
|
446
|
-
/******/ return getter;
|
|
447
|
-
/******/ };
|
|
448
|
-
/******/ })();
|
|
449
|
-
/******/
|
|
450
|
-
/******/ /* webpack/runtime/define property getters */
|
|
451
|
-
/******/ (() => {
|
|
452
|
-
/******/ // define getter functions for harmony exports
|
|
453
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
454
|
-
/******/ for(var key in definition) {
|
|
455
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
456
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
457
|
-
/******/ }
|
|
458
|
-
/******/ }
|
|
459
|
-
/******/ };
|
|
460
|
-
/******/ })();
|
|
461
|
-
/******/
|
|
462
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
463
|
-
/******/ (() => {
|
|
464
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
465
|
-
/******/ })();
|
|
466
|
-
/******/
|
|
467
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
468
|
-
/******/ (() => {
|
|
469
|
-
/******/ // define __esModule on exports
|
|
470
|
-
/******/ __webpack_require__.r = (exports) => {
|
|
471
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
472
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
473
|
-
/******/ }
|
|
474
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
475
|
-
/******/ };
|
|
476
|
-
/******/ })();
|
|
477
|
-
/******/
|
|
478
|
-
/************************************************************************/
|
|
479
|
-
/******/
|
|
480
|
-
/******/ // startup
|
|
481
|
-
/******/ // Load entry module and return exports
|
|
482
|
-
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
483
|
-
/******/ var __webpack_exports__ = __webpack_require__("./index.ts");
|
|
484
|
-
/******/ var __webpack_exports__clearLoginCookie = __webpack_exports__.clearLoginCookie;
|
|
485
|
-
/******/ var __webpack_exports__getAccessToken = __webpack_exports__.getAccessToken;
|
|
486
|
-
/******/ var __webpack_exports__getCookie = __webpack_exports__.getCookie;
|
|
487
|
-
/******/ var __webpack_exports__getIdToken = __webpack_exports__.getIdToken;
|
|
488
|
-
/******/ var __webpack_exports__getRefreshToken = __webpack_exports__.getRefreshToken;
|
|
489
|
-
/******/ var __webpack_exports__getSystemType = __webpack_exports__.getSystemType;
|
|
490
|
-
/******/ var __webpack_exports__getUrlParam = __webpack_exports__.getUrlParam;
|
|
491
|
-
/******/ var __webpack_exports__getUserInfo = __webpack_exports__.getUserInfo;
|
|
492
|
-
/******/ var __webpack_exports__isMobile = __webpack_exports__.isMobile;
|
|
493
|
-
/******/ var __webpack_exports__make = __webpack_exports__.make;
|
|
494
|
-
/******/ var __webpack_exports__setAccessToken = __webpack_exports__.setAccessToken;
|
|
495
|
-
/******/ var __webpack_exports__setCookie = __webpack_exports__.setCookie;
|
|
496
|
-
/******/ var __webpack_exports__setIdToken = __webpack_exports__.setIdToken;
|
|
497
|
-
/******/ var __webpack_exports__setRefreshToken = __webpack_exports__.setRefreshToken;
|
|
498
|
-
/******/ var __webpack_exports__setSystemType = __webpack_exports__.setSystemType;
|
|
499
|
-
/******/ export { __webpack_exports__clearLoginCookie as clearLoginCookie, __webpack_exports__getAccessToken as getAccessToken, __webpack_exports__getCookie as getCookie, __webpack_exports__getIdToken as getIdToken, __webpack_exports__getRefreshToken as getRefreshToken, __webpack_exports__getSystemType as getSystemType, __webpack_exports__getUrlParam as getUrlParam, __webpack_exports__getUserInfo as getUserInfo, __webpack_exports__isMobile as isMobile, __webpack_exports__make as make, __webpack_exports__setAccessToken as setAccessToken, __webpack_exports__setCookie as setCookie, __webpack_exports__setIdToken as setIdToken, __webpack_exports__setRefreshToken as setRefreshToken, __webpack_exports__setSystemType as setSystemType };
|
|
500
|
-
/******/
|
|
73
|
+
const setIdToken = setAccessToken;
|
|
74
|
+
const getIdToken = getAccessToken;
|
|
75
|
+
const setCookie = (name, value, domain, path = '/', time = 30 * 24 * 60 * 60 * 1000) => {
|
|
76
|
+
if (value === null || value === undefined) {
|
|
77
|
+
return Cookie.remove(name);
|
|
78
|
+
}
|
|
79
|
+
Cookie.set(name, value, {
|
|
80
|
+
domain,
|
|
81
|
+
path,
|
|
82
|
+
expires: time / (24 * 60 * 60 * 1000)
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const clearLoginCookie = () => {
|
|
86
|
+
setAccessToken(null);
|
|
87
|
+
setRefreshToken(null);
|
|
88
|
+
};
|
|
89
|
+
const getCookie = (c_name) => {
|
|
90
|
+
if (!c_name)
|
|
91
|
+
return null;
|
|
92
|
+
const reg = new RegExp('(?:^|; )' + encodeURIComponent(c_name) + '=([^;]*)');
|
|
93
|
+
const result = reg.exec(document.cookie);
|
|
94
|
+
return result ? decodeURIComponent(result[1] || '') : null;
|
|
95
|
+
};
|
|
96
|
+
const getUrlParam = (key, href) => {
|
|
97
|
+
const search = '?' + ((href || window.location.href).split('?')[1] || '');
|
|
98
|
+
const searchParams = new URLSearchParams(search);
|
|
99
|
+
return searchParams.get(key);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const isMobile = () => {
|
|
103
|
+
const ua = navigator.userAgent;
|
|
104
|
+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
|
|
105
|
+
};
|
|
106
|
+
const getUserInfo = () => {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
const token = getAccessToken();
|
|
109
|
+
if (!token)
|
|
110
|
+
return reject(new Error(NO_ACCESS_TOKEN));
|
|
111
|
+
const splits = token.split('.');
|
|
112
|
+
if (splits.length < 3)
|
|
113
|
+
return reject(new Error(NO_ACCESS_TOKEN));
|
|
114
|
+
resolve(JSON.parse(Base64.decode(splits[1])));
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
var Brand;
|
|
119
|
+
(function (Brand) {
|
|
120
|
+
Brand[Brand["ZERO"] = 1] = "ZERO";
|
|
121
|
+
Brand[Brand["HEDGEHOOD"] = 2] = "HEDGEHOOD";
|
|
122
|
+
Brand[Brand["NISE"] = 3] = "NISE";
|
|
123
|
+
})(Brand || (Brand = {}));
|
|
124
|
+
var Tenant;
|
|
125
|
+
(function (Tenant) {
|
|
126
|
+
Tenant[Tenant["ZERO_INT"] = 1] = "ZERO_INT";
|
|
127
|
+
Tenant[Tenant["HEDGEHOOD"] = 2] = "HEDGEHOOD";
|
|
128
|
+
Tenant[Tenant["ZERO_NZ"] = 3] = "ZERO_NZ";
|
|
129
|
+
Tenant[Tenant["ZERO_LA"] = 4] = "ZERO_LA";
|
|
130
|
+
Tenant[Tenant["ZERO_BR"] = 4] = "ZERO_BR";
|
|
131
|
+
Tenant[Tenant["NISE_EU"] = 5] = "NISE_EU";
|
|
132
|
+
})(Tenant || (Tenant = {}));
|
|
133
|
+
var SystemType;
|
|
134
|
+
(function (SystemType) {
|
|
135
|
+
SystemType["Staff"] = "staff";
|
|
136
|
+
SystemType["Client"] = "client";
|
|
137
|
+
})(SystemType || (SystemType = {}));
|
|
138
|
+
|
|
139
|
+
let tenantId;
|
|
140
|
+
let brand;
|
|
141
|
+
let moduleBaseUrl = '';
|
|
142
|
+
let loginPageUrl = '';
|
|
143
|
+
const setTenantId = (id) => {
|
|
144
|
+
if (!Object.values(Tenant).includes(id)) {
|
|
145
|
+
throw new Error(INVALID_TENANT_ID);
|
|
146
|
+
}
|
|
147
|
+
tenantId = id;
|
|
148
|
+
};
|
|
149
|
+
const setBrand = (id) => {
|
|
150
|
+
if (!Object.values(Brand).includes(id)) {
|
|
151
|
+
throw new Error(INVALID_BRAND);
|
|
152
|
+
}
|
|
153
|
+
brand = id;
|
|
154
|
+
};
|
|
155
|
+
const setModuleBaseUrl = (url) => {
|
|
156
|
+
moduleBaseUrl = url;
|
|
157
|
+
};
|
|
158
|
+
const setLoginPageUrl = (url) => {
|
|
159
|
+
loginPageUrl = url;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const createPcDialog = () => {
|
|
163
|
+
return `<div id="confirm-container" style="box-sizing:border-box;position:fixed;width:615px;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left: 35%;padding:20px 20px;top:10px;font-size: 16px;">
|
|
164
|
+
<div id="href" style="color: rgb(32,33,36);"></div>
|
|
165
|
+
<div style="margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;">You do not have access to the system.</div>
|
|
166
|
+
<div style="display: flex;justify-content: flex-end;">
|
|
167
|
+
<button id="cancel" style="padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;">Cancel</button>
|
|
168
|
+
<button id="confirm" style="padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;">Sign in to another ZERO account</button>
|
|
169
|
+
</div>
|
|
170
|
+
</div>`;
|
|
171
|
+
};
|
|
172
|
+
const createMobileDialog = () => {
|
|
173
|
+
return `<div id="confirm-container" style="box-sizing:border-box;position:fixed;width:97.6vw;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left:0px;padding:20px 20px;top:4px;margin:0 4px;font-size: 16px;">
|
|
174
|
+
<div id="href" style="color: rgb(32,33,36);"></div>
|
|
175
|
+
<div style="margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;">You do not have access to the system.</div>
|
|
176
|
+
<div style="display: flex;justify-content: flex-end;">
|
|
177
|
+
<div style="display: flex;justify-content: flex-end;">
|
|
178
|
+
<button id="cancel" style="padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;">Cancel</button>
|
|
179
|
+
<button id="confirm" style="padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;">Sign in to another ZERO account</button>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</div>`;
|
|
183
|
+
};
|
|
184
|
+
const onConfirmHandler = (evt) => {
|
|
185
|
+
closeDialog();
|
|
186
|
+
window.location.href = loginPageUrl;
|
|
187
|
+
};
|
|
188
|
+
const onCancelHandler = () => {
|
|
189
|
+
closeDialog();
|
|
190
|
+
window.location.href = 'about:blank';
|
|
191
|
+
};
|
|
192
|
+
const closeDialog = () => {
|
|
193
|
+
const container = document.getElementById('confirm-container');
|
|
194
|
+
if (!container || !container.parentNode)
|
|
195
|
+
return;
|
|
196
|
+
document.body.removeChild(container.parentNode);
|
|
197
|
+
};
|
|
198
|
+
const openDialog = () => {
|
|
199
|
+
const container = document.createElement('div');
|
|
200
|
+
isMobile()
|
|
201
|
+
? container.innerHTML = createMobileDialog()
|
|
202
|
+
: container.innerHTML = createPcDialog();
|
|
203
|
+
const confirmButton = container.querySelector('#confirm');
|
|
204
|
+
const cancelButton = container.querySelector('#cancel');
|
|
205
|
+
confirmButton?.addEventListener('click', onConfirmHandler);
|
|
206
|
+
cancelButton?.addEventListener('click', onCancelHandler);
|
|
207
|
+
document.body.appendChild(container);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
let instance;
|
|
211
|
+
/**
|
|
212
|
+
* 没找到更好的方式,只能这样做了
|
|
213
|
+
*/
|
|
214
|
+
const initInstance = async () => {
|
|
215
|
+
let userInfo = null;
|
|
216
|
+
try {
|
|
217
|
+
userInfo = await getUserInfo();
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
console.warn('initInstance getUserInfo error:', error);
|
|
221
|
+
}
|
|
222
|
+
instance = axios.create({
|
|
223
|
+
baseURL: moduleBaseUrl,
|
|
224
|
+
timeout: 1.5e4,
|
|
225
|
+
headers: {
|
|
226
|
+
'X-tenant-id': userInfo ? userInfo['custom:tenant_id'].toString() : tenantId.toString(),
|
|
227
|
+
'X-brand': brand.toString(),
|
|
228
|
+
'Authorization': `Bearer ${getAccessToken()}`,
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
instance.interceptors.request.use((config) => {
|
|
232
|
+
return config;
|
|
233
|
+
}, (error) => {
|
|
234
|
+
return Promise.reject(error);
|
|
235
|
+
});
|
|
236
|
+
instance.interceptors.response.use((response) => {
|
|
237
|
+
if (response.data.code !== 200) {
|
|
238
|
+
return Promise.reject(response.data.msg);
|
|
239
|
+
}
|
|
240
|
+
return response;
|
|
241
|
+
}, (error) => {
|
|
242
|
+
return Promise.reject(error);
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
const fetchRefreshTokenHTTP = (refreshToken) => {
|
|
246
|
+
return instance({
|
|
247
|
+
method: 'post',
|
|
248
|
+
url: '/user-profile/refresh-token/refresh',
|
|
249
|
+
data: {
|
|
250
|
+
refreshToken
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
const fetchLogoutHTTP = () => {
|
|
255
|
+
return instance({
|
|
256
|
+
method: 'get',
|
|
257
|
+
url: '/user-profile/logout'
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
const fetchServerListHTTP = () => {
|
|
261
|
+
return instance({
|
|
262
|
+
method: 'get',
|
|
263
|
+
url: '/session/current/servers'
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const make = (config) => {
|
|
268
|
+
if (!config.moduleBaseUrl) {
|
|
269
|
+
throw new Error(NO_MODULE_BASE_URL);
|
|
270
|
+
}
|
|
271
|
+
let timer = undefined;
|
|
272
|
+
setModuleBaseUrl(config.moduleBaseUrl);
|
|
273
|
+
setLoginPageUrl(config.loginPageUrl);
|
|
274
|
+
setTenantId(config.tenantId);
|
|
275
|
+
setBrand(config.brand);
|
|
276
|
+
initInstance();
|
|
277
|
+
const init = () => {
|
|
278
|
+
const token = getAccessToken();
|
|
279
|
+
const refreshToken = getRefreshToken();
|
|
280
|
+
if (!token) {
|
|
281
|
+
setAccessToken(null);
|
|
282
|
+
setRefreshToken(null);
|
|
283
|
+
return Promise.reject(new Error(NO_ACCESS_TOKEN));
|
|
284
|
+
}
|
|
285
|
+
if (!refreshToken) {
|
|
286
|
+
setAccessToken(null);
|
|
287
|
+
setRefreshToken(null);
|
|
288
|
+
return Promise.reject(new Error(NO_REFRESH_TOKEN));
|
|
289
|
+
}
|
|
290
|
+
return getUserInfo()
|
|
291
|
+
.then(async (userInfo) => {
|
|
292
|
+
const valid = detectUserInfoGroupAuth(userInfo);
|
|
293
|
+
if (!valid) {
|
|
294
|
+
return Promise.reject();
|
|
295
|
+
}
|
|
296
|
+
return fetchServerListHTTP();
|
|
297
|
+
})
|
|
298
|
+
.catch(error => {
|
|
299
|
+
openDialog();
|
|
300
|
+
throw error;
|
|
301
|
+
})
|
|
302
|
+
.then(resp => {
|
|
303
|
+
const menus = resp.data.content || [];
|
|
304
|
+
if (menus.length <= 0)
|
|
305
|
+
return Promise.reject();
|
|
306
|
+
const group = menus.find(menu => menu.groupName === config.moduleName);
|
|
307
|
+
if (group) {
|
|
308
|
+
setSystemType(group.staffEndpoint ? SystemType.Staff : SystemType.Client);
|
|
309
|
+
}
|
|
310
|
+
setupRefreshTokenTimer();
|
|
311
|
+
return Promise.resolve(menus);
|
|
312
|
+
})
|
|
313
|
+
.catch(async (error) => {
|
|
314
|
+
clearRefreshTokenTimer();
|
|
315
|
+
setAccessToken(null);
|
|
316
|
+
setRefreshToken(null);
|
|
317
|
+
await logout();
|
|
318
|
+
throw error;
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
const detectUserInfoGroupAuth = (userInfo) => {
|
|
322
|
+
const groups = userInfo['cognito:groups'] || [];
|
|
323
|
+
if (!groups.includes(config.moduleName)
|
|
324
|
+
&& config.moduleName !== 'commonLogin'
|
|
325
|
+
&& config.moduleName !== 'App') {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
return true;
|
|
329
|
+
};
|
|
330
|
+
const setupRefreshTokenTimer = () => {
|
|
331
|
+
const refreshToken = getRefreshToken();
|
|
332
|
+
if (!refreshToken)
|
|
333
|
+
return;
|
|
334
|
+
if (timer) {
|
|
335
|
+
clearInterval(timer);
|
|
336
|
+
}
|
|
337
|
+
timer = setInterval(() => {
|
|
338
|
+
fetchRefreshTokenHTTP(refreshToken)
|
|
339
|
+
.then(resp => {
|
|
340
|
+
const { content: { idToken } } = resp.data;
|
|
341
|
+
setAccessToken(idToken);
|
|
342
|
+
return getUserInfo();
|
|
343
|
+
})
|
|
344
|
+
.then(userInfo => {
|
|
345
|
+
const valid = detectUserInfoGroupAuth(userInfo);
|
|
346
|
+
if (!valid) {
|
|
347
|
+
clearRefreshTokenTimer();
|
|
348
|
+
openDialog();
|
|
349
|
+
return logout();
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
.catch(error => {
|
|
353
|
+
clearRefreshTokenTimer();
|
|
354
|
+
throw error;
|
|
355
|
+
});
|
|
356
|
+
}, 1e3 * 60 * 3); // 3 minutes
|
|
357
|
+
};
|
|
358
|
+
const logout = () => {
|
|
359
|
+
return fetchLogoutHTTP()
|
|
360
|
+
.finally(() => {
|
|
361
|
+
clearRefreshTokenTimer();
|
|
362
|
+
setAccessToken(null);
|
|
363
|
+
setRefreshToken(null);
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
const clearRefreshTokenTimer = () => {
|
|
367
|
+
if (!timer)
|
|
368
|
+
return;
|
|
369
|
+
clearInterval(timer);
|
|
370
|
+
timer = null;
|
|
371
|
+
};
|
|
372
|
+
return {
|
|
373
|
+
init,
|
|
374
|
+
logout
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
export { clearLoginCookie, getAccessToken, getCookie, getIdToken, getRefreshToken, getSystemType, getUrlParam, getUserInfo, isMobile, make, setAccessToken, setCookie, setIdToken, setRefreshToken, setSystemType };
|