@opengeoweb/authentication 14.0.1 → 14.2.1
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.esm.js +365 -254
- package/package.json +4 -4
- package/src/index.d.ts +1 -1
- package/src/lib/components/ApiContext/ApiContext.d.ts +2 -2
- package/src/lib/components/ApiContext/index.d.ts +1 -1
- package/src/lib/components/ApiContext/types.d.ts +2 -3
- package/src/lib/components/ApiContext/utils.d.ts +3 -3
- package/src/lib/components/AuthenticationContext/AuthenticationContext.d.ts +4 -1
- package/src/lib/components/AuthenticationContext/AuthenticationRenderTestComponent.d.ts +2 -2
- package/src/lib/components/AuthenticationContext/index.d.ts +2 -2
- package/src/lib/components/AuthenticationContext/types.d.ts +3 -2
- package/src/lib/components/Providers/Providers.d.ts +1 -1
- package/src/lib/components/UserMenuRoles/UserMenuRoles.d.ts +1 -1
- package/src/lib/components/UserMenuRoles/UserMenuRolesConnect.d.ts +1 -1
- package/src/lib/components/apiHooks/useApi.d.ts +1 -1
- package/src/lib/utils/i18n.d.ts +1 -1
package/index.esm.js
CHANGED
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import React__default, { useRef } from 'react';
|
|
4
2
|
import axios from 'axios';
|
|
3
|
+
import React, { useRef, useEffect, useState } from 'react';
|
|
5
4
|
import { Navigate, Link } from 'react-router-dom';
|
|
6
5
|
import { sessionStorageProvider, useIsMounted, SHARED_NAMESPACE, AlertBanner, useDebounce } from '@opengeoweb/shared';
|
|
7
|
-
import { ThemeWrapper } from '@opengeoweb/theme';
|
|
8
6
|
import { useTranslation, Trans } from 'react-i18next';
|
|
7
|
+
import { ThemeWrapper } from '@opengeoweb/theme';
|
|
9
8
|
import 'i18next';
|
|
10
9
|
import { Box, LinearProgress, FormGroup, FormLabel, FormControlLabel, Radio } from '@mui/material';
|
|
11
10
|
import { useDispatch } from 'react-redux';
|
|
12
11
|
import { snackbarTypes, snackbarActions } from '@opengeoweb/snackbar';
|
|
13
12
|
|
|
14
13
|
var en$1 = {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"auth-role-title": "Role",
|
|
18
|
-
"auth-role-message-assigned": "Role {{role}} has been assigned"
|
|
14
|
+
"api-role-title-user": "User",
|
|
15
|
+
"api-role-title-preset-admin": "Preset-admin"
|
|
19
16
|
};
|
|
20
17
|
var fi$1 = {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"auth-role-title": "Rooli",
|
|
24
|
-
"auth-role-message-assigned": "Rooli {{role}} on annettu"
|
|
18
|
+
"api-role-title-user": "Käyttäjä",
|
|
19
|
+
"api-role-title-preset-admin": "Preset-pääkäyttäjä"
|
|
25
20
|
};
|
|
26
21
|
var no$1 = {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"auth-role-title": "Rolle",
|
|
30
|
-
"auth-role-message-assigned": "Rolle {{role}} har blitt tildelt"
|
|
22
|
+
"api-role-title-user": "Bruker",
|
|
23
|
+
"api-role-title-preset-admin": "Preset-admin"
|
|
31
24
|
};
|
|
32
25
|
var nl$1 = {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"auth-role-title": "Rol",
|
|
36
|
-
"auth-role-message-assigned": "Rol {{role}} is geactiveerd"
|
|
26
|
+
"api-role-title-user": "Gebruiker",
|
|
27
|
+
"api-role-title-preset-admin": "Preset-beheerder"
|
|
37
28
|
};
|
|
38
|
-
var
|
|
29
|
+
var apiTranslations = {
|
|
39
30
|
en: en$1,
|
|
40
31
|
fi: fi$1,
|
|
41
32
|
no: no$1,
|
|
@@ -43,22 +34,30 @@ var authTranslations = {
|
|
|
43
34
|
};
|
|
44
35
|
|
|
45
36
|
var en = {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
37
|
+
"auth-logout-go-back-to-home-page": "Go back to the <1>Home Page</1>",
|
|
38
|
+
"auth-logout-you-are-logged-out": "You are logged out.",
|
|
39
|
+
"auth-role-title": "Role",
|
|
40
|
+
"auth-role-message-assigned": "Role {{role}} has been assigned"
|
|
48
41
|
};
|
|
49
42
|
var fi = {
|
|
50
|
-
"
|
|
51
|
-
"
|
|
43
|
+
"auth-logout-go-back-to-home-page": "Palaa takaisin <1>Kotisivulle</1>",
|
|
44
|
+
"auth-logout-you-are-logged-out": "Olet kirjautunut ulos.",
|
|
45
|
+
"auth-role-title": "Rooli",
|
|
46
|
+
"auth-role-message-assigned": "Rooli {{role}} on annettu"
|
|
52
47
|
};
|
|
53
48
|
var no = {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
49
|
+
"auth-logout-go-back-to-home-page": "Gå tilbake til <1>Hjemmesiden</1>",
|
|
50
|
+
"auth-logout-you-are-logged-out": "Du er logget ut",
|
|
51
|
+
"auth-role-title": "Rolle",
|
|
52
|
+
"auth-role-message-assigned": "Rolle {{role}} har blitt tildelt"
|
|
56
53
|
};
|
|
57
54
|
var nl = {
|
|
58
|
-
"
|
|
59
|
-
"
|
|
55
|
+
"auth-logout-go-back-to-home-page": "Ga terug naar de <1>Startpagina</1>",
|
|
56
|
+
"auth-logout-you-are-logged-out": "Je bent uitgelogd.",
|
|
57
|
+
"auth-role-title": "Rol",
|
|
58
|
+
"auth-role-message-assigned": "Rol {{role}} is geactiveerd"
|
|
60
59
|
};
|
|
61
|
-
var
|
|
60
|
+
var authTranslations = {
|
|
62
61
|
en: en,
|
|
63
62
|
fi: fi,
|
|
64
63
|
no: no,
|
|
@@ -346,28 +345,18 @@ function _regeneratorRuntime() {
|
|
|
346
345
|
})();
|
|
347
346
|
}
|
|
348
347
|
|
|
349
|
-
var API_NAMESPACE$1 = 'api';
|
|
350
348
|
var DEFAULT_TIMEOUT = 15000;
|
|
351
349
|
var KEEP_ALIVE_POLLER_IN_SECONDS = 60; // Number of seconds between the checks if the token should be refreshed.
|
|
352
350
|
var REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75; // Refresh token when 75% expired. Set to (10 / 3600) * 100 = 0.2777778% to test with 10 second interval (assuming 1 hour token expiration).
|
|
353
351
|
var DEFAULT_TOKEN_EXPIRES_IN = 3600; // Number of seconds a token expires by default
|
|
354
352
|
var MILLISECOND_TO_SECOND = 1 / 1000;
|
|
355
|
-
var ns$1 = API_NAMESPACE$1;
|
|
356
353
|
var GEOWEB_ROLE_PRESETS_ADMIN = {
|
|
357
354
|
name: 'ROLE_PRESET_ADMIN',
|
|
358
|
-
|
|
359
|
-
return t('api-role-title-preset-admin', {
|
|
360
|
-
ns: ns$1
|
|
361
|
-
});
|
|
362
|
-
}
|
|
355
|
+
title: 'api-role-title-preset-admin'
|
|
363
356
|
};
|
|
364
357
|
var GEOWEB_ROLE_USER = {
|
|
365
358
|
name: 'ROLE_USER',
|
|
366
|
-
|
|
367
|
-
return t('api-role-title-user', {
|
|
368
|
-
ns: ns$1
|
|
369
|
-
});
|
|
370
|
-
}
|
|
359
|
+
title: 'api-role-title-user'
|
|
371
360
|
};
|
|
372
361
|
/**
|
|
373
362
|
* Creates a Credentials object based on the axios response from the token service.
|
|
@@ -378,7 +367,8 @@ var GEOWEB_ROLE_USER = {
|
|
|
378
367
|
* @returns Credentials object.
|
|
379
368
|
*/
|
|
380
369
|
var makeCredentialsFromTokenResponse = function makeCredentialsFromTokenResponse(tokenResponse, authConfig) {
|
|
381
|
-
var
|
|
370
|
+
var _tokenResponse$data$b;
|
|
371
|
+
var token = (_tokenResponse$data$b = tokenResponse.data.body) != null ? _tokenResponse$data$b : tokenResponse.data;
|
|
382
372
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
383
373
|
var access_token = token.access_token,
|
|
384
374
|
refresh_token = token.refresh_token,
|
|
@@ -402,60 +392,67 @@ var makeCredentialsFromTokenResponse = function makeCredentialsFromTokenResponse
|
|
|
402
392
|
username: isAuthCognito ? userInfo['cognito:username'] : userInfo.email,
|
|
403
393
|
roles: groupsToRoles(groups, authConfig),
|
|
404
394
|
token: access_token,
|
|
405
|
-
refresh_token: refresh_token
|
|
395
|
+
refresh_token: refresh_token != null ? refresh_token : '',
|
|
406
396
|
expires_at: epochTimeTokenExpirationInSeconds,
|
|
407
397
|
has_connection_issue: false
|
|
408
398
|
};
|
|
409
399
|
return newAuth;
|
|
410
400
|
};
|
|
411
|
-
var refreshAccessToken = function
|
|
412
|
-
var
|
|
413
|
-
_ref$config
|
|
414
|
-
_ref$config2 = _ref$config === void 0 ? {} : _ref$config,
|
|
415
|
-
authTokenURL = _ref$config2.authTokenURL,
|
|
416
|
-
authClientId = _ref$config2.authClientId,
|
|
417
|
-
appURL = _ref$config2.appURL,
|
|
418
|
-
_ref$timeout = _ref.timeout,
|
|
419
|
-
timeout = _ref$timeout === void 0 ? DEFAULT_TIMEOUT : _ref$timeout;
|
|
420
|
-
// Refresh token request with a new axios instance
|
|
421
|
-
// without request interceptor
|
|
422
|
-
var tokenAxiosInstance = axios.create({
|
|
423
|
-
headers: {},
|
|
424
|
-
timeout: timeout
|
|
425
|
-
});
|
|
426
|
-
var refreshPayload = {
|
|
427
|
-
refresh_token: auth.refresh_token,
|
|
428
|
-
redirect_uri: appURL + "/code",
|
|
429
|
-
grant_type: 'refresh_token',
|
|
430
|
-
client_id: authClientId
|
|
431
|
-
};
|
|
432
|
-
/* Send data in the "application/x-www-form-urlencoded" format.
|
|
433
|
-
If only JSON is supported, use Axios' default content type ("application/x-www-form-urlencoded"). */
|
|
434
|
-
var useDefaultContentType = authTokenURL.includes('amazonaws.com');
|
|
435
|
-
var data = useDefaultContentType ? refreshPayload : new URLSearchParams(refreshPayload);
|
|
436
|
-
var axiosConfig = {
|
|
437
|
-
headers: {
|
|
438
|
-
'Content-Type': useDefaultContentType ? 'application/json' : 'application/x-www-form-urlencoded'
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
return tokenAxiosInstance.post(authTokenURL, data, axiosConfig);
|
|
442
|
-
};
|
|
443
|
-
var refreshAccessTokenAndSetAuthContext = /*#__PURE__*/function () {
|
|
444
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
445
|
-
var auth, onSetAuth, config, _ref2$timeout, timeout, configURLS, onLogin, refreshedToken, newAuth, _e$response, status;
|
|
401
|
+
var refreshAccessToken = /*#__PURE__*/function () {
|
|
402
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
403
|
+
var auth, _ref$config, _ref$config2, authTokenURL, authClientId, appURL, _ref$timeout, timeout, tokenAxiosInstance, refreshPayload, useDefaultContentType, data, axiosConfig;
|
|
446
404
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
447
405
|
while (1) switch (_context.prev = _context.next) {
|
|
448
406
|
case 0:
|
|
449
|
-
auth =
|
|
450
|
-
|
|
451
|
-
|
|
407
|
+
auth = _ref.auth, _ref$config = _ref.config, _ref$config2 = _ref$config === void 0 ? {} : _ref$config, authTokenURL = _ref$config2.authTokenURL, authClientId = _ref$config2.authClientId, appURL = _ref$config2.appURL, _ref$timeout = _ref.timeout, timeout = _ref$timeout === void 0 ? DEFAULT_TIMEOUT : _ref$timeout;
|
|
408
|
+
// Refresh token request with a new axios instance
|
|
409
|
+
// without request interceptor
|
|
410
|
+
tokenAxiosInstance = axios.create({
|
|
411
|
+
headers: {},
|
|
412
|
+
timeout: timeout
|
|
413
|
+
});
|
|
414
|
+
refreshPayload = {
|
|
415
|
+
refresh_token: auth.refresh_token,
|
|
416
|
+
redirect_uri: appURL + "/code",
|
|
417
|
+
grant_type: 'refresh_token',
|
|
418
|
+
client_id: authClientId
|
|
419
|
+
};
|
|
420
|
+
/* Send data in the "application/x-www-form-urlencoded" format.
|
|
421
|
+
If only JSON is supported, use Axios' default content type ("application/x-www-form-urlencoded"). */
|
|
422
|
+
useDefaultContentType = authTokenURL.includes('amazonaws.com');
|
|
423
|
+
data = useDefaultContentType ? refreshPayload : new URLSearchParams(refreshPayload);
|
|
424
|
+
axiosConfig = {
|
|
425
|
+
headers: {
|
|
426
|
+
'Content-Type': useDefaultContentType ? 'application/json' : 'application/x-www-form-urlencoded'
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
return _context.abrupt("return", tokenAxiosInstance.post(authTokenURL, data, axiosConfig));
|
|
430
|
+
case 7:
|
|
431
|
+
case "end":
|
|
432
|
+
return _context.stop();
|
|
433
|
+
}
|
|
434
|
+
}, _callee);
|
|
435
|
+
}));
|
|
436
|
+
return function refreshAccessToken(_x) {
|
|
437
|
+
return _ref2.apply(this, arguments);
|
|
438
|
+
};
|
|
439
|
+
}();
|
|
440
|
+
var refreshAccessTokenAndSetAuthContext = /*#__PURE__*/function () {
|
|
441
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
|
|
442
|
+
var auth, onSetAuth, config, _ref3$timeout, timeout, configURLS, onLogin, refreshedToken, newAuth, _e$response, status;
|
|
443
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
444
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
445
|
+
case 0:
|
|
446
|
+
auth = _ref3.auth, onSetAuth = _ref3.onSetAuth, config = _ref3.config, _ref3$timeout = _ref3.timeout, timeout = _ref3$timeout === void 0 ? DEFAULT_TIMEOUT : _ref3$timeout, configURLS = _ref3.configURLS, onLogin = _ref3.onLogin;
|
|
447
|
+
_context2.prev = 1;
|
|
448
|
+
_context2.next = 4;
|
|
452
449
|
return refreshAccessToken({
|
|
453
450
|
auth: auth,
|
|
454
451
|
config: config,
|
|
455
452
|
timeout: timeout
|
|
456
453
|
});
|
|
457
454
|
case 4:
|
|
458
|
-
refreshedToken =
|
|
455
|
+
refreshedToken = _context2.sent;
|
|
459
456
|
newAuth = makeCredentialsFromTokenResponse(refreshedToken, configURLS); // Cognito does not send a new refresh token, but gitlab does. Set it here into the auth context.
|
|
460
457
|
if (!newAuth.refresh_token || newAuth.refresh_token.length === 0) {
|
|
461
458
|
newAuth.refresh_token = auth.refresh_token;
|
|
@@ -465,12 +462,12 @@ var refreshAccessTokenAndSetAuthContext = /*#__PURE__*/function () {
|
|
|
465
462
|
newAuth.roles = auth.roles;
|
|
466
463
|
}
|
|
467
464
|
onSetAuth(newAuth);
|
|
468
|
-
|
|
465
|
+
_context2.next = 15;
|
|
469
466
|
break;
|
|
470
467
|
case 11:
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
status = (_e$response =
|
|
468
|
+
_context2.prev = 11;
|
|
469
|
+
_context2.t0 = _context2["catch"](1);
|
|
470
|
+
status = (_e$response = _context2.t0.response) == null ? void 0 : _e$response.status;
|
|
474
471
|
if (status === 400) {
|
|
475
472
|
onLogin(false);
|
|
476
473
|
} else {
|
|
@@ -480,21 +477,21 @@ var refreshAccessTokenAndSetAuthContext = /*#__PURE__*/function () {
|
|
|
480
477
|
}
|
|
481
478
|
case 15:
|
|
482
479
|
case "end":
|
|
483
|
-
return
|
|
480
|
+
return _context2.stop();
|
|
484
481
|
}
|
|
485
|
-
},
|
|
482
|
+
}, _callee2, null, [[1, 11]]);
|
|
486
483
|
}));
|
|
487
|
-
return function refreshAccessTokenAndSetAuthContext(
|
|
488
|
-
return
|
|
484
|
+
return function refreshAccessTokenAndSetAuthContext(_x2) {
|
|
485
|
+
return _ref4.apply(this, arguments);
|
|
489
486
|
};
|
|
490
487
|
}();
|
|
491
|
-
var createApiInstance = function createApiInstance(
|
|
492
|
-
var auth =
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
baseURL =
|
|
496
|
-
|
|
497
|
-
timeout =
|
|
488
|
+
var createApiInstance = function createApiInstance(_ref5) {
|
|
489
|
+
var auth = _ref5.auth,
|
|
490
|
+
_ref5$config = _ref5.config,
|
|
491
|
+
_ref5$config2 = _ref5$config === void 0 ? {} : _ref5$config,
|
|
492
|
+
baseURL = _ref5$config2.baseURL,
|
|
493
|
+
_ref5$timeout = _ref5.timeout,
|
|
494
|
+
timeout = _ref5$timeout === void 0 ? DEFAULT_TIMEOUT : _ref5$timeout;
|
|
498
495
|
var axiosInstance = axios.create({
|
|
499
496
|
baseURL: baseURL,
|
|
500
497
|
headers: {},
|
|
@@ -502,10 +499,10 @@ var createApiInstance = function createApiInstance(_ref4) {
|
|
|
502
499
|
});
|
|
503
500
|
// Request interceptor for API calls done BEFORE the request is made.
|
|
504
501
|
axiosInstance.interceptors.request.use(/*#__PURE__*/function () {
|
|
505
|
-
var
|
|
502
|
+
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(axiosConfig) {
|
|
506
503
|
var newConfig;
|
|
507
|
-
return _regeneratorRuntime().wrap(function
|
|
508
|
-
while (1) switch (
|
|
504
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
505
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
509
506
|
case 0:
|
|
510
507
|
// Add the access token to the headers of the request.
|
|
511
508
|
newConfig = Object.assign({}, axiosConfig, {
|
|
@@ -513,47 +510,48 @@ var createApiInstance = function createApiInstance(_ref4) {
|
|
|
513
510
|
'Content-Type': 'application/json',
|
|
514
511
|
Authorization: "Bearer " + auth.token,
|
|
515
512
|
Accept: 'application/json'
|
|
516
|
-
}, axiosConfig.headers)
|
|
513
|
+
}, axiosConfig.headers || {})
|
|
517
514
|
});
|
|
518
|
-
return
|
|
515
|
+
return _context3.abrupt("return", newConfig);
|
|
519
516
|
case 2:
|
|
520
517
|
case "end":
|
|
521
|
-
return
|
|
518
|
+
return _context3.stop();
|
|
522
519
|
}
|
|
523
|
-
},
|
|
520
|
+
}, _callee3);
|
|
524
521
|
}));
|
|
525
|
-
return function (
|
|
526
|
-
return
|
|
522
|
+
return function (_x3) {
|
|
523
|
+
return _ref6.apply(this, arguments);
|
|
527
524
|
};
|
|
528
525
|
}(), /*#__PURE__*/function () {
|
|
529
|
-
var
|
|
530
|
-
return _regeneratorRuntime().wrap(function
|
|
531
|
-
while (1) switch (
|
|
526
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(error) {
|
|
527
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
528
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
532
529
|
case 0:
|
|
533
|
-
|
|
530
|
+
_context4.next = 2;
|
|
534
531
|
return Promise.reject(error);
|
|
535
532
|
case 2:
|
|
536
533
|
case "end":
|
|
537
|
-
return
|
|
534
|
+
return _context4.stop();
|
|
538
535
|
}
|
|
539
|
-
},
|
|
536
|
+
}, _callee4);
|
|
540
537
|
}));
|
|
541
|
-
return function (
|
|
542
|
-
return
|
|
538
|
+
return function (_x4) {
|
|
539
|
+
return _ref7.apply(this, arguments);
|
|
543
540
|
};
|
|
544
541
|
}());
|
|
545
542
|
// Response interceptor for API calls done AFTER the request is made.
|
|
546
543
|
axiosInstance.interceptors.response.use(function (response) {
|
|
547
544
|
return response;
|
|
548
545
|
}, /*#__PURE__*/function () {
|
|
549
|
-
var
|
|
546
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(error) {
|
|
547
|
+
var _error$response;
|
|
550
548
|
var originalRequest, _originalRequest$head;
|
|
551
|
-
return _regeneratorRuntime().wrap(function
|
|
552
|
-
while (1) switch (
|
|
549
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
550
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
553
551
|
case 0:
|
|
554
552
|
originalRequest = error.config; // If request fails with 401, retry the request once.
|
|
555
|
-
if (!(error.response &&
|
|
556
|
-
|
|
553
|
+
if (!((_error$response = error.response) != null && _error$response.status && error.response.status === 401 && !originalRequest.inRetry)) {
|
|
554
|
+
_context5.next = 5;
|
|
557
555
|
break;
|
|
558
556
|
}
|
|
559
557
|
originalRequest.inRetry = true;
|
|
@@ -561,27 +559,27 @@ var createApiInstance = function createApiInstance(_ref4) {
|
|
|
561
559
|
if ((_originalRequest$head = originalRequest.headers) != null && _originalRequest$head.Authorization) {
|
|
562
560
|
originalRequest.headers.Authorization = "Bearer " + (auth == null ? void 0 : auth.token);
|
|
563
561
|
}
|
|
564
|
-
return
|
|
562
|
+
return _context5.abrupt("return", axiosInstance(originalRequest));
|
|
565
563
|
case 5:
|
|
566
|
-
return
|
|
564
|
+
return _context5.abrupt("return", Promise.reject(error));
|
|
567
565
|
case 6:
|
|
568
566
|
case "end":
|
|
569
|
-
return
|
|
567
|
+
return _context5.stop();
|
|
570
568
|
}
|
|
571
|
-
},
|
|
569
|
+
}, _callee5);
|
|
572
570
|
}));
|
|
573
|
-
return function (
|
|
574
|
-
return
|
|
571
|
+
return function (_x5) {
|
|
572
|
+
return _ref8.apply(this, arguments);
|
|
575
573
|
};
|
|
576
574
|
}());
|
|
577
575
|
return axiosInstance;
|
|
578
576
|
};
|
|
579
|
-
var createNonAuthApiInstance = function createNonAuthApiInstance(
|
|
580
|
-
var
|
|
581
|
-
|
|
582
|
-
baseURL =
|
|
583
|
-
|
|
584
|
-
timeout =
|
|
577
|
+
var createNonAuthApiInstance = function createNonAuthApiInstance(_ref9) {
|
|
578
|
+
var _ref9$config = _ref9.config,
|
|
579
|
+
_ref9$config2 = _ref9$config === void 0 ? {} : _ref9$config,
|
|
580
|
+
baseURL = _ref9$config2.baseURL,
|
|
581
|
+
_ref9$timeout = _ref9.timeout,
|
|
582
|
+
timeout = _ref9$timeout === void 0 ? DEFAULT_TIMEOUT : _ref9$timeout;
|
|
585
583
|
var axiosInstance = axios.create({
|
|
586
584
|
baseURL: baseURL,
|
|
587
585
|
headers: {},
|
|
@@ -589,74 +587,157 @@ var createNonAuthApiInstance = function createNonAuthApiInstance(_ref8) {
|
|
|
589
587
|
});
|
|
590
588
|
// Request interceptor for API calls
|
|
591
589
|
axiosInstance.interceptors.request.use(/*#__PURE__*/function () {
|
|
592
|
-
var
|
|
590
|
+
var _ref0 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(config) {
|
|
593
591
|
var newConfig;
|
|
594
|
-
return _regeneratorRuntime().wrap(function
|
|
595
|
-
while (1) switch (
|
|
592
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
593
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
596
594
|
case 0:
|
|
597
595
|
newConfig = Object.assign({}, config, {
|
|
598
596
|
headers: Object.assign({
|
|
599
597
|
'Content-Type': 'application/json',
|
|
600
598
|
Accept: 'application/json'
|
|
601
|
-
}, config.headers)
|
|
599
|
+
}, config.headers || {})
|
|
602
600
|
});
|
|
603
|
-
return
|
|
601
|
+
return _context6.abrupt("return", newConfig);
|
|
604
602
|
case 2:
|
|
605
603
|
case "end":
|
|
606
|
-
return
|
|
604
|
+
return _context6.stop();
|
|
607
605
|
}
|
|
608
|
-
},
|
|
606
|
+
}, _callee6);
|
|
609
607
|
}));
|
|
610
|
-
return function (
|
|
611
|
-
return
|
|
608
|
+
return function (_x6) {
|
|
609
|
+
return _ref0.apply(this, arguments);
|
|
612
610
|
};
|
|
613
611
|
}(), /*#__PURE__*/function () {
|
|
614
|
-
var
|
|
615
|
-
return _regeneratorRuntime().wrap(function
|
|
616
|
-
while (1) switch (
|
|
612
|
+
var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(error) {
|
|
613
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
614
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
617
615
|
case 0:
|
|
618
|
-
|
|
616
|
+
_context7.next = 2;
|
|
619
617
|
return Promise.reject(error);
|
|
620
618
|
case 2:
|
|
621
619
|
case "end":
|
|
622
|
-
return
|
|
620
|
+
return _context7.stop();
|
|
623
621
|
}
|
|
624
|
-
},
|
|
622
|
+
}, _callee7);
|
|
625
623
|
}));
|
|
626
|
-
return function (
|
|
627
|
-
return
|
|
624
|
+
return function (_x7) {
|
|
625
|
+
return _ref1.apply(this, arguments);
|
|
628
626
|
};
|
|
629
627
|
}());
|
|
630
628
|
return axiosInstance;
|
|
631
629
|
};
|
|
632
|
-
var fakeApiRequest = function
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
630
|
+
var fakeApiRequest = /*#__PURE__*/function () {
|
|
631
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(signal) {
|
|
632
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
633
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
634
|
+
case 0:
|
|
635
|
+
return _context8.abrupt("return", new Promise(function (resolve, reject) {
|
|
636
|
+
var timer = setTimeout(function () {
|
|
637
|
+
resolve();
|
|
638
|
+
}, 300);
|
|
639
|
+
signal == null || signal.signal.addEventListener('abort', function () {
|
|
640
|
+
clearTimeout(timer);
|
|
641
|
+
reject(new Error('canceled'));
|
|
642
|
+
});
|
|
643
|
+
}));
|
|
644
|
+
case 1:
|
|
645
|
+
case "end":
|
|
646
|
+
return _context8.stop();
|
|
647
|
+
}
|
|
648
|
+
}, _callee8);
|
|
649
|
+
}));
|
|
650
|
+
return function fakeApiRequest(_x8) {
|
|
651
|
+
return _ref10.apply(this, arguments);
|
|
652
|
+
};
|
|
653
|
+
}();
|
|
643
654
|
var createFakeApiInstance = function createFakeApiInstance() {
|
|
644
655
|
return {
|
|
645
|
-
get: function
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
656
|
+
get: function () {
|
|
657
|
+
var _get = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_url, _params) {
|
|
658
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
659
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
660
|
+
case 0:
|
|
661
|
+
return _context9.abrupt("return", fakeApiRequest());
|
|
662
|
+
case 1:
|
|
663
|
+
case "end":
|
|
664
|
+
return _context9.stop();
|
|
665
|
+
}
|
|
666
|
+
}, _callee9);
|
|
667
|
+
}));
|
|
668
|
+
function get(_x9, _x0) {
|
|
669
|
+
return _get.apply(this, arguments);
|
|
670
|
+
}
|
|
671
|
+
return get;
|
|
672
|
+
}(),
|
|
673
|
+
put: function () {
|
|
674
|
+
var _put = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(_url, _params) {
|
|
675
|
+
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
|
|
676
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
677
|
+
case 0:
|
|
678
|
+
return _context0.abrupt("return", fakeApiRequest());
|
|
679
|
+
case 1:
|
|
680
|
+
case "end":
|
|
681
|
+
return _context0.stop();
|
|
682
|
+
}
|
|
683
|
+
}, _callee0);
|
|
684
|
+
}));
|
|
685
|
+
function put(_x1, _x10) {
|
|
686
|
+
return _put.apply(this, arguments);
|
|
687
|
+
}
|
|
688
|
+
return put;
|
|
689
|
+
}(),
|
|
690
|
+
post: function () {
|
|
691
|
+
var _post = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(_url, _params) {
|
|
692
|
+
return _regeneratorRuntime().wrap(function _callee1$(_context1) {
|
|
693
|
+
while (1) switch (_context1.prev = _context1.next) {
|
|
694
|
+
case 0:
|
|
695
|
+
return _context1.abrupt("return", fakeApiRequest());
|
|
696
|
+
case 1:
|
|
697
|
+
case "end":
|
|
698
|
+
return _context1.stop();
|
|
699
|
+
}
|
|
700
|
+
}, _callee1);
|
|
701
|
+
}));
|
|
702
|
+
function post(_x11, _x12) {
|
|
703
|
+
return _post.apply(this, arguments);
|
|
704
|
+
}
|
|
705
|
+
return post;
|
|
706
|
+
}(),
|
|
707
|
+
"delete": function () {
|
|
708
|
+
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_url, _params) {
|
|
709
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
710
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
711
|
+
case 0:
|
|
712
|
+
return _context10.abrupt("return", fakeApiRequest());
|
|
713
|
+
case 1:
|
|
714
|
+
case "end":
|
|
715
|
+
return _context10.stop();
|
|
716
|
+
}
|
|
717
|
+
}, _callee10);
|
|
718
|
+
}));
|
|
719
|
+
function _delete(_x13, _x14) {
|
|
720
|
+
return _delete2.apply(this, arguments);
|
|
721
|
+
}
|
|
722
|
+
return _delete;
|
|
723
|
+
}(),
|
|
724
|
+
patch: function () {
|
|
725
|
+
var _patch = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_url, _params, _signal) {
|
|
726
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
727
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
728
|
+
case 0:
|
|
729
|
+
return _context11.abrupt("return", fakeApiRequest(_signal));
|
|
730
|
+
case 1:
|
|
731
|
+
case "end":
|
|
732
|
+
return _context11.stop();
|
|
733
|
+
}
|
|
734
|
+
}, _callee11);
|
|
735
|
+
}));
|
|
736
|
+
function patch(_x15, _x16, _x17) {
|
|
737
|
+
return _patch.apply(this, arguments);
|
|
738
|
+
}
|
|
739
|
+
return patch;
|
|
740
|
+
}()
|
|
660
741
|
};
|
|
661
742
|
};
|
|
662
743
|
var getCurrentTimeInSeconds = function getCurrentTimeInSeconds() {
|
|
@@ -742,7 +823,7 @@ var getAuthConfig = function getAuthConfig(_configUrls) {
|
|
|
742
823
|
GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN: GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN
|
|
743
824
|
};
|
|
744
825
|
};
|
|
745
|
-
var AuthenticationContext = /*#__PURE__*/
|
|
826
|
+
var AuthenticationContext = /*#__PURE__*/React.createContext({
|
|
746
827
|
isLoggedIn: null,
|
|
747
828
|
onLogin: null,
|
|
748
829
|
auth: null,
|
|
@@ -751,11 +832,16 @@ var AuthenticationContext = /*#__PURE__*/React__default.createContext({
|
|
|
751
832
|
sessionStorageProvider: null,
|
|
752
833
|
currentRole: null
|
|
753
834
|
});
|
|
835
|
+
var authChangeListener = null;
|
|
836
|
+
var setAuthChangeListener = function setAuthChangeListener(listener) {
|
|
837
|
+
authChangeListener = listener;
|
|
838
|
+
};
|
|
754
839
|
var useAuthenticationDefaultProps = function useAuthenticationDefaultProps() {
|
|
755
|
-
var
|
|
840
|
+
var _auth$roles$, _auth$roles;
|
|
841
|
+
var _React$useState = React.useState(false),
|
|
756
842
|
isLoggedIn = _React$useState[0],
|
|
757
|
-
|
|
758
|
-
var _React$useState2 =
|
|
843
|
+
setIsLoggedIn = _React$useState[1];
|
|
844
|
+
var _React$useState2 = React.useState(false),
|
|
759
845
|
hasConnectionIssue = _React$useState2[0],
|
|
760
846
|
setHasConnectionIssue = _React$useState2[1];
|
|
761
847
|
var emptyCredentials = {
|
|
@@ -766,28 +852,38 @@ var useAuthenticationDefaultProps = function useAuthenticationDefaultProps() {
|
|
|
766
852
|
expires_at: 0,
|
|
767
853
|
has_connection_issue: false
|
|
768
854
|
};
|
|
769
|
-
var
|
|
770
|
-
|
|
855
|
+
var _React$useState3 = React.useState(Object.assign({}, emptyCredentials)),
|
|
856
|
+
auth = _React$useState3[0],
|
|
857
|
+
setAuth = _React$useState3[1];
|
|
858
|
+
// TODO clean this up.
|
|
859
|
+
// hotfix revert to ref. There are parts of the state down the tree that rely on ref to work.
|
|
860
|
+
var authRef = React.useRef(auth).current;
|
|
861
|
+
var onSetAuth = React.useCallback(function (newAuth) {
|
|
771
862
|
if (newAuth) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
setHasConnectionIssue(auth.has_connection_issue === true);
|
|
863
|
+
setAuth(function (prevAuth) {
|
|
864
|
+
return Object.assign({}, prevAuth, newAuth);
|
|
865
|
+
});
|
|
866
|
+
Object.assign(authRef, newAuth);
|
|
867
|
+
if (newAuth.has_connection_issue !== undefined && hasConnectionIssue !== newAuth.has_connection_issue) {
|
|
868
|
+
setHasConnectionIssue(newAuth.has_connection_issue);
|
|
779
869
|
}
|
|
780
870
|
} else {
|
|
781
|
-
Object.assign(
|
|
871
|
+
setAuth(Object.assign({}, emptyCredentials));
|
|
872
|
+
Object.assign(authRef, Object.assign({}, emptyCredentials));
|
|
782
873
|
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
874
|
+
},
|
|
875
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
876
|
+
[hasConnectionIssue]);
|
|
877
|
+
var _React$useState4 = React.useState((_auth$roles$ = (_auth$roles = auth.roles) == null ? void 0 : _auth$roles[0]) != null ? _auth$roles$ : GEOWEB_ROLE_USER),
|
|
878
|
+
currentRole = _React$useState4[0],
|
|
879
|
+
setCurrentRole = _React$useState4[1];
|
|
880
|
+
useEffect(function () {
|
|
881
|
+
authChangeListener == null || authChangeListener(isLoggedIn, auth);
|
|
882
|
+
}, [isLoggedIn, auth]);
|
|
787
883
|
return {
|
|
788
884
|
isLoggedIn: isLoggedIn,
|
|
789
|
-
onLogin:
|
|
790
|
-
auth: isLoggedIn ?
|
|
885
|
+
onLogin: setIsLoggedIn,
|
|
886
|
+
auth: isLoggedIn ? authRef : null,
|
|
791
887
|
onSetAuth: onSetAuth,
|
|
792
888
|
sessionStorageProvider: sessionStorageProvider,
|
|
793
889
|
currentRole: currentRole,
|
|
@@ -800,7 +896,7 @@ var AuthenticationProvider = function AuthenticationProvider(_ref2) {
|
|
|
800
896
|
_ref2$configURLS = _ref2.configURLS,
|
|
801
897
|
configURLS = _ref2$configURLS === void 0 ? authConfigKeys : _ref2$configURLS;
|
|
802
898
|
var defaultValues = useAuthenticationDefaultProps();
|
|
803
|
-
var _ref3 = value
|
|
899
|
+
var _ref3 = value != null ? value : defaultValues,
|
|
804
900
|
isLoggedIn = _ref3.isLoggedIn,
|
|
805
901
|
onLogin = _ref3.onLogin,
|
|
806
902
|
auth = _ref3.auth,
|
|
@@ -811,7 +907,7 @@ var AuthenticationProvider = function AuthenticationProvider(_ref2) {
|
|
|
811
907
|
var authConfig = configURLS;
|
|
812
908
|
// Checks the token expiration time regularly and renews it before it expires.
|
|
813
909
|
var interval = useRef();
|
|
814
|
-
|
|
910
|
+
React.useEffect(function () {
|
|
815
911
|
interval.current = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
816
912
|
var currentTime, timeInSecondsLeftBeforeExpiration;
|
|
817
913
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
@@ -823,7 +919,7 @@ var AuthenticationProvider = function AuthenticationProvider(_ref2) {
|
|
|
823
919
|
}
|
|
824
920
|
currentTime = getCurrentTimeInSeconds();
|
|
825
921
|
timeInSecondsLeftBeforeExpiration = auth.expires_at ? auth.expires_at - currentTime : 0;
|
|
826
|
-
if (!(timeInSecondsLeftBeforeExpiration <
|
|
922
|
+
if (!(timeInSecondsLeftBeforeExpiration < 60)) {
|
|
827
923
|
_context2.next = 6;
|
|
828
924
|
break;
|
|
829
925
|
}
|
|
@@ -850,7 +946,7 @@ var AuthenticationProvider = function AuthenticationProvider(_ref2) {
|
|
|
850
946
|
clearInterval(interval.current);
|
|
851
947
|
};
|
|
852
948
|
}, [auth, configURLS.GW_APP_URL, configURLS.GW_AUTH_CLIENT_ID, configURLS.GW_AUTH_TOKEN_URL, onSetAuth, configURLS, onLogin]);
|
|
853
|
-
var contextValue =
|
|
949
|
+
var contextValue = React.useMemo(function () {
|
|
854
950
|
return {
|
|
855
951
|
isLoggedIn: isLoggedIn,
|
|
856
952
|
onLogin: onLogin,
|
|
@@ -868,7 +964,7 @@ var AuthenticationProvider = function AuthenticationProvider(_ref2) {
|
|
|
868
964
|
});
|
|
869
965
|
};
|
|
870
966
|
var useAuthenticationContext = function useAuthenticationContext() {
|
|
871
|
-
return
|
|
967
|
+
return React.useContext(AuthenticationContext);
|
|
872
968
|
};
|
|
873
969
|
|
|
874
970
|
var axiosInstance = axios.create({
|
|
@@ -881,13 +977,13 @@ var HandleOAuth2Code = function HandleOAuth2Code() {
|
|
|
881
977
|
isLoggedIn = _useAuthenticationCon.isLoggedIn,
|
|
882
978
|
onLogin = _useAuthenticationCon.onLogin,
|
|
883
979
|
sessionStorageProvider = _useAuthenticationCon.sessionStorageProvider;
|
|
884
|
-
var _React$useState =
|
|
980
|
+
var _React$useState = React.useState(null),
|
|
885
981
|
error = _React$useState[0],
|
|
886
982
|
setError = _React$useState[1];
|
|
887
983
|
var _useIsMounted = useIsMounted(),
|
|
888
984
|
isMounted = _useIsMounted.isMounted;
|
|
889
|
-
var loginInProgress =
|
|
890
|
-
var authenticate =
|
|
985
|
+
var loginInProgress = React.useRef(false);
|
|
986
|
+
var authenticate = React.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
891
987
|
var _Object$fromEntries, code, state, isStateRequired, isPkceRequired, payload, useDefaultContentType, data, config, res, newAuth;
|
|
892
988
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
893
989
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -969,9 +1065,10 @@ var HandleOAuth2Code = function HandleOAuth2Code() {
|
|
|
969
1065
|
if (isMounted.current) {
|
|
970
1066
|
if (_context.t0 instanceof Error) {
|
|
971
1067
|
setError(function () {
|
|
1068
|
+
var _error$stack;
|
|
972
1069
|
return {
|
|
973
1070
|
message: _context.t0.message,
|
|
974
|
-
stack: _context.t0.stack
|
|
1071
|
+
stack: (_error$stack = _context.t0.stack) != null ? _error$stack : 'Error in HandleOAuth2Code'
|
|
975
1072
|
};
|
|
976
1073
|
});
|
|
977
1074
|
}
|
|
@@ -988,7 +1085,7 @@ var HandleOAuth2Code = function HandleOAuth2Code() {
|
|
|
988
1085
|
}
|
|
989
1086
|
}, _callee, null, [[15, 23]]);
|
|
990
1087
|
})), [authConfig, isMounted, onLogin, onSetAuth, sessionStorageProvider]);
|
|
991
|
-
|
|
1088
|
+
React.useEffect(function () {
|
|
992
1089
|
var authenticateWithLock = /*#__PURE__*/function () {
|
|
993
1090
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
994
1091
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
@@ -1019,17 +1116,17 @@ var HandleOAuth2Code = function HandleOAuth2Code() {
|
|
|
1019
1116
|
}, [authenticate, isLoggedIn]);
|
|
1020
1117
|
return jsxs(Fragment, {
|
|
1021
1118
|
children: [error ? jsx(Navigate, {
|
|
1022
|
-
|
|
1119
|
+
replace: true,
|
|
1023
1120
|
state: {
|
|
1024
1121
|
error: {
|
|
1025
1122
|
message: error.message,
|
|
1026
1123
|
stack: error.stack
|
|
1027
1124
|
}
|
|
1028
1125
|
},
|
|
1029
|
-
|
|
1126
|
+
to: "/error"
|
|
1030
1127
|
}) : null, isLoggedIn ? jsx(Navigate, {
|
|
1031
|
-
|
|
1032
|
-
|
|
1128
|
+
replace: true,
|
|
1129
|
+
to: sessionStorageProvider.getCallbackUrl()
|
|
1033
1130
|
}) : null]
|
|
1034
1131
|
});
|
|
1035
1132
|
};
|
|
@@ -1075,7 +1172,7 @@ var getCurrentUrlLocation = function getCurrentUrlLocation(url, appUrl) {
|
|
|
1075
1172
|
var OAuth2Login = function OAuth2Login() {
|
|
1076
1173
|
var _useAuthenticationCon = useAuthenticationContext(),
|
|
1077
1174
|
authConfig = _useAuthenticationCon.authConfig;
|
|
1078
|
-
|
|
1175
|
+
React.useEffect(function () {
|
|
1079
1176
|
var callbackUrl = getCurrentUrlLocation(sessionStorageProvider.getCallbackUrl(), authConfig.GW_APP_URL);
|
|
1080
1177
|
sessionStorageProvider.setCallbackUrl(callbackUrl);
|
|
1081
1178
|
window.location.assign(authConfig.GW_AUTH_LOGIN_URL);
|
|
@@ -1114,12 +1211,12 @@ var OAuth2Logout = function OAuth2Logout() {
|
|
|
1114
1211
|
isLoggedIn = _useAuthenticationCon.isLoggedIn,
|
|
1115
1212
|
onLogin = _useAuthenticationCon.onLogin,
|
|
1116
1213
|
sessionStorageProvider = _useAuthenticationCon.sessionStorageProvider;
|
|
1117
|
-
var _React$useState =
|
|
1214
|
+
var _React$useState = React.useState(true),
|
|
1118
1215
|
showAlert = _React$useState[0],
|
|
1119
1216
|
setShowAlert = _React$useState[1];
|
|
1120
1217
|
var _useAuthenticationTra = useAuthenticationTranslation(),
|
|
1121
1218
|
t = _useAuthenticationTra.t;
|
|
1122
|
-
|
|
1219
|
+
React.useEffect(function () {
|
|
1123
1220
|
if (isLoggedIn) {
|
|
1124
1221
|
setShowAlert(false);
|
|
1125
1222
|
onSetAuth(null);
|
|
@@ -1130,8 +1227,6 @@ var OAuth2Logout = function OAuth2Logout() {
|
|
|
1130
1227
|
}, [isLoggedIn, onSetAuth, onLogin, sessionStorageProvider, authConfig.GW_AUTH_LOGOUT_URL]);
|
|
1131
1228
|
return showAlert ? jsx(ThemeWrapper, {
|
|
1132
1229
|
children: jsx(AlertBanner, {
|
|
1133
|
-
severity: "info",
|
|
1134
|
-
title: t('auth-logout-you-are-logged-out'),
|
|
1135
1230
|
info: jsx("p", {
|
|
1136
1231
|
children: jsxs(Trans, {
|
|
1137
1232
|
i18nKey: "auth-logout-go-back-to-home-page",
|
|
@@ -1141,7 +1236,9 @@ var OAuth2Logout = function OAuth2Logout() {
|
|
|
1141
1236
|
children: "Home Page"
|
|
1142
1237
|
})]
|
|
1143
1238
|
})
|
|
1144
|
-
})
|
|
1239
|
+
}),
|
|
1240
|
+
severity: "info",
|
|
1241
|
+
title: t('auth-logout-you-are-logged-out')
|
|
1145
1242
|
})
|
|
1146
1243
|
}) : null;
|
|
1147
1244
|
};
|
|
@@ -1155,7 +1252,7 @@ var UserMenuRoles = function UserMenuRoles(_ref) {
|
|
|
1155
1252
|
var _useAuthenticationTra = useAuthenticationTranslation(),
|
|
1156
1253
|
t = _useAuthenticationTra.t;
|
|
1157
1254
|
return jsxs(Fragment, {
|
|
1158
|
-
children: [isLoading
|
|
1255
|
+
children: [isLoading ? jsx(Box, {
|
|
1159
1256
|
sx: {
|
|
1160
1257
|
position: 'absolute',
|
|
1161
1258
|
top: 0,
|
|
@@ -1163,10 +1260,10 @@ var UserMenuRoles = function UserMenuRoles(_ref) {
|
|
|
1163
1260
|
right: 0
|
|
1164
1261
|
},
|
|
1165
1262
|
children: jsx(LinearProgress, {
|
|
1166
|
-
|
|
1167
|
-
|
|
1263
|
+
color: "secondary",
|
|
1264
|
+
"data-testid": "loading-bar"
|
|
1168
1265
|
})
|
|
1169
|
-
}), jsxs(FormGroup, {
|
|
1266
|
+
}) : null, jsxs(FormGroup, {
|
|
1170
1267
|
children: [jsx(FormLabel, {
|
|
1171
1268
|
component: "legend",
|
|
1172
1269
|
sx: {
|
|
@@ -1176,13 +1273,13 @@ var UserMenuRoles = function UserMenuRoles(_ref) {
|
|
|
1176
1273
|
opacity: 1
|
|
1177
1274
|
},
|
|
1178
1275
|
children: t('auth-role-title')
|
|
1179
|
-
}), roles
|
|
1276
|
+
}), roles == null ? void 0 : roles.map(function (role) {
|
|
1180
1277
|
return jsx(FormControlLabel, {
|
|
1181
1278
|
control: jsx(Radio, {
|
|
1182
|
-
|
|
1183
|
-
|
|
1279
|
+
checked: currentRole === role.name,
|
|
1280
|
+
disabled: isLoading
|
|
1184
1281
|
}),
|
|
1185
|
-
label: role.
|
|
1282
|
+
label: t(role.title),
|
|
1186
1283
|
onChange: function onChange() {
|
|
1187
1284
|
return onChangeRole(role);
|
|
1188
1285
|
}
|
|
@@ -1199,22 +1296,35 @@ var UserMenuRolesConnect = function UserMenuRolesConnect(_ref) {
|
|
|
1199
1296
|
_ref$isAdmin = _ref.isAdmin,
|
|
1200
1297
|
isAdmin = _ref$isAdmin === void 0 ? false : _ref$isAdmin;
|
|
1201
1298
|
var defaultRole = isAdmin ? GEOWEB_ROLE_PRESETS_ADMIN.name : GEOWEB_ROLE_USER.name;
|
|
1202
|
-
var _React$useState =
|
|
1299
|
+
var _React$useState = React.useState(false),
|
|
1203
1300
|
isLoading = _React$useState[0],
|
|
1204
1301
|
setIsLoading = _React$useState[1];
|
|
1205
|
-
var _React$useState2 =
|
|
1302
|
+
var _React$useState2 = React.useState(defaultRole),
|
|
1206
1303
|
currentRole = _React$useState2[0],
|
|
1207
1304
|
setCurrentRole = _React$useState2[1];
|
|
1208
1305
|
var dispatch = useDispatch();
|
|
1209
1306
|
var _useAuthenticationTra = useAuthenticationTranslation(),
|
|
1210
1307
|
t = _useAuthenticationTra.t;
|
|
1211
|
-
var onFakeRequest = function
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1308
|
+
var onFakeRequest = /*#__PURE__*/function () {
|
|
1309
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1310
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1311
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1312
|
+
case 0:
|
|
1313
|
+
return _context.abrupt("return", new Promise(function (resolve) {
|
|
1314
|
+
setTimeout(function () {
|
|
1315
|
+
resolve();
|
|
1316
|
+
}, 300);
|
|
1317
|
+
}));
|
|
1318
|
+
case 1:
|
|
1319
|
+
case "end":
|
|
1320
|
+
return _context.stop();
|
|
1321
|
+
}
|
|
1322
|
+
}, _callee);
|
|
1323
|
+
}));
|
|
1324
|
+
return function onFakeRequest() {
|
|
1325
|
+
return _ref2.apply(this, arguments);
|
|
1326
|
+
};
|
|
1327
|
+
}();
|
|
1218
1328
|
var onChangeRole = function onChangeRole(role) {
|
|
1219
1329
|
setIsLoading(true);
|
|
1220
1330
|
onFakeRequest().then(function () {
|
|
@@ -1224,7 +1334,7 @@ var UserMenuRolesConnect = function UserMenuRolesConnect(_ref) {
|
|
|
1224
1334
|
type: snackbarTypes.SnackbarMessageType.TRANSLATABLE_MESSAGE,
|
|
1225
1335
|
key: 'auth-role-message-assigned',
|
|
1226
1336
|
params: {
|
|
1227
|
-
role: role.
|
|
1337
|
+
role: t(role.title)
|
|
1228
1338
|
}
|
|
1229
1339
|
};
|
|
1230
1340
|
dispatch(snackbarActions.openSnackbar(message));
|
|
@@ -1233,10 +1343,10 @@ var UserMenuRolesConnect = function UserMenuRolesConnect(_ref) {
|
|
|
1233
1343
|
});
|
|
1234
1344
|
};
|
|
1235
1345
|
return jsx(UserMenuRoles, {
|
|
1236
|
-
onChangeRole: onChangeRole,
|
|
1237
|
-
roles: roles,
|
|
1238
1346
|
currentRole: currentRole,
|
|
1239
|
-
isLoading: isLoading
|
|
1347
|
+
isLoading: isLoading,
|
|
1348
|
+
onChangeRole: onChangeRole,
|
|
1349
|
+
roles: roles
|
|
1240
1350
|
});
|
|
1241
1351
|
};
|
|
1242
1352
|
|
|
@@ -1257,7 +1367,7 @@ var ApiProvider = function ApiProvider(_ref) {
|
|
|
1257
1367
|
name = _ref.name,
|
|
1258
1368
|
apiModuleProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1259
1369
|
var handleNewApi = React.useCallback(function () {
|
|
1260
|
-
var newApi = createApi
|
|
1370
|
+
var newApi = createApi(apiModuleProps);
|
|
1261
1371
|
if (name) {
|
|
1262
1372
|
registerApi(name, newApi);
|
|
1263
1373
|
}
|
|
@@ -1292,24 +1402,25 @@ var generateRandomId = function generateRandomId() {
|
|
|
1292
1402
|
var useApi = function useApi(
|
|
1293
1403
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1294
1404
|
apiCall,
|
|
1295
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1405
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
1296
1406
|
params, callbacks) {
|
|
1297
1407
|
var _useIsMounted = useIsMounted(),
|
|
1298
1408
|
isMounted = _useIsMounted.isMounted;
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1409
|
+
// eslint-disable-next-line react/hook-use-state
|
|
1410
|
+
var _useState = useState(generateRandomId()),
|
|
1411
|
+
id = _useState[0];
|
|
1412
|
+
var _useState2 = useState(true),
|
|
1413
|
+
isLoading = _useState2[0],
|
|
1414
|
+
setIsLoading = _useState2[1];
|
|
1415
|
+
var _useState3 = useState(null),
|
|
1416
|
+
error = _useState3[0],
|
|
1417
|
+
setError = _useState3[1];
|
|
1418
|
+
var _useState4 = useState(null),
|
|
1419
|
+
result = _useState4[0],
|
|
1420
|
+
setResult = _useState4[1];
|
|
1310
1421
|
var debouncedParams = useDebounce(JSON.stringify(params), 300);
|
|
1311
1422
|
// trick so that we don't have to include this in the useEffect dependency array (as it is likely that callbacks changes on every render)
|
|
1312
|
-
var callbacksRef =
|
|
1423
|
+
var callbacksRef = useRef();
|
|
1313
1424
|
callbacksRef.current = callbacks;
|
|
1314
1425
|
var handleError = function handleError(newError) {
|
|
1315
1426
|
if (isMounted.current) {
|
|
@@ -1326,7 +1437,7 @@ params, callbacks) {
|
|
|
1326
1437
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1327
1438
|
while (1) switch (_context.prev = _context.next) {
|
|
1328
1439
|
case 0:
|
|
1329
|
-
|
|
1440
|
+
setIsLoading(true);
|
|
1330
1441
|
setError(null);
|
|
1331
1442
|
_context.prev = 2;
|
|
1332
1443
|
_context.next = 5;
|
|
@@ -1350,7 +1461,7 @@ params, callbacks) {
|
|
|
1350
1461
|
}
|
|
1351
1462
|
case 12:
|
|
1352
1463
|
_context.prev = 12;
|
|
1353
|
-
|
|
1464
|
+
setIsLoading(false);
|
|
1354
1465
|
return _context.finish(12);
|
|
1355
1466
|
case 15:
|
|
1356
1467
|
case "end":
|
|
@@ -1362,7 +1473,7 @@ params, callbacks) {
|
|
|
1362
1473
|
return _ref.apply(this, arguments);
|
|
1363
1474
|
};
|
|
1364
1475
|
}();
|
|
1365
|
-
|
|
1476
|
+
useEffect(function () {
|
|
1366
1477
|
fetchApiData(params)["catch"](function (newError) {
|
|
1367
1478
|
handleError(newError);
|
|
1368
1479
|
});
|
|
@@ -1370,7 +1481,7 @@ params, callbacks) {
|
|
|
1370
1481
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1371
1482
|
[debouncedParams]);
|
|
1372
1483
|
var clearResults = function clearResults() {
|
|
1373
|
-
|
|
1484
|
+
setIsLoading(true);
|
|
1374
1485
|
setResult(null);
|
|
1375
1486
|
};
|
|
1376
1487
|
return {
|
|
@@ -1382,4 +1493,4 @@ params, callbacks) {
|
|
|
1382
1493
|
};
|
|
1383
1494
|
};
|
|
1384
1495
|
|
|
1385
|
-
export { AUTH_NAMESPACE, ApiProvider, AuthenticationContext, AuthenticationProvider, HandleOAuth2Code as Code, GEOWEB_ROLE_PRESETS_ADMIN, GEOWEB_ROLE_USER, KEEP_ALIVE_POLLER_IN_SECONDS, OAuth2Login as Login, OAuth2Logout as Logout, MILLISECOND_TO_SECOND, REFRESH_TOKEN_WHEN_PCT_EXPIRED, UserMenuRoles, UserMenuRolesConnect, apiTranslations, authTranslations, createApiInstance, createFakeApiInstance, createNonAuthApiInstance, fakeApiRequest, getApi, getAuthConfig, getCodeChallenge, getCurrentTimeInSeconds, getCurrentUrlLocation, getRandomString, groupsToRoles, makeCredentialsFromTokenResponse, refreshAccessToken, refreshAccessTokenAndSetAuthContext, useApi, useApiContext, useAuthenticationContext, useAuthenticationDefaultProps };
|
|
1496
|
+
export { AUTH_NAMESPACE, ApiProvider, AuthenticationContext, AuthenticationProvider, HandleOAuth2Code as Code, GEOWEB_ROLE_PRESETS_ADMIN, GEOWEB_ROLE_USER, KEEP_ALIVE_POLLER_IN_SECONDS, OAuth2Login as Login, OAuth2Logout as Logout, MILLISECOND_TO_SECOND, REFRESH_TOKEN_WHEN_PCT_EXPIRED, UserMenuRoles, UserMenuRolesConnect, apiTranslations, authTranslations, createApiInstance, createFakeApiInstance, createNonAuthApiInstance, fakeApiRequest, getApi, getAuthConfig, getCodeChallenge, getCurrentTimeInSeconds, getCurrentUrlLocation, getRandomString, groupsToRoles, makeCredentialsFromTokenResponse, refreshAccessToken, refreshAccessTokenAndSetAuthContext, setAuthChangeListener, useApi, useApiContext, useAuthenticationContext, useAuthenticationDefaultProps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/authentication",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.2.1",
|
|
4
4
|
"description": "GeoWeb authentication library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"axios": "^1.7.7",
|
|
12
12
|
"react-router-dom": "^6.23.1",
|
|
13
|
-
"@opengeoweb/shared": "14.
|
|
14
|
-
"@opengeoweb/theme": "14.
|
|
13
|
+
"@opengeoweb/shared": "14.2.1",
|
|
14
|
+
"@opengeoweb/theme": "14.2.1",
|
|
15
15
|
"i18next": "^25.0.1",
|
|
16
16
|
"react-i18next": "^15.1.1",
|
|
17
|
-
"@opengeoweb/snackbar": "14.
|
|
17
|
+
"@opengeoweb/snackbar": "14.2.1",
|
|
18
18
|
"react-redux": "^9.2.0",
|
|
19
19
|
"@reduxjs/toolkit": "^2.6.1",
|
|
20
20
|
"@mui/material": "^7.0.1"
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import authTranslations from '../locales/authentication.json';
|
|
2
1
|
import apiTranslations from '../locales/api.json';
|
|
2
|
+
import authTranslations from '../locales/authentication.json';
|
|
3
3
|
export { default as Code } from './lib/components/pages/Code';
|
|
4
4
|
export { default as Login } from './lib/components/pages/Login';
|
|
5
5
|
export { default as Logout } from './lib/components/pages/Logout';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TFunction } from 'i18next';
|
|
2
1
|
export interface GeoWebJWT {
|
|
3
2
|
access_token: string;
|
|
4
3
|
refresh_token?: string;
|
|
@@ -29,8 +28,8 @@ export interface ApiModule {
|
|
|
29
28
|
export interface CreateApiProps extends ApiModule {
|
|
30
29
|
timeout?: number;
|
|
31
30
|
}
|
|
32
|
-
export type CreateApiFn = (props: CreateApiProps) =>
|
|
31
|
+
export type CreateApiFn = (props: CreateApiProps) => unknown;
|
|
33
32
|
export interface Role {
|
|
34
33
|
name: string;
|
|
35
|
-
|
|
34
|
+
title: string;
|
|
36
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
-
import { ConfigType } from '@opengeoweb/shared';
|
|
3
|
-
import { CreateApiProps, Credentials, Role } from './types';
|
|
1
|
+
import type { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
import type { ConfigType } from '@opengeoweb/shared';
|
|
3
|
+
import type { CreateApiProps, Credentials, Role } from './types';
|
|
4
4
|
export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 60;
|
|
5
5
|
export declare const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75;
|
|
6
6
|
export declare const MILLISECOND_TO_SECOND: number;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AuthenticationConfig, AuthenticationContextProps, AuthenticationDefaultStateProps } from './types';
|
|
2
|
+
import type { AuthenticationConfig, AuthenticationContextProps, AuthenticationDefaultStateProps } from './types';
|
|
3
|
+
import type { Credentials } from '../ApiContext/types';
|
|
3
4
|
export declare const getRandomString: () => string;
|
|
4
5
|
export declare const getCodeChallenge: (codeVerifier: string) => Promise<string>;
|
|
5
6
|
export declare const replaceTemplateKeys: (url: string, clientId: string, appUrl: string, oauthState?: string, codeChallenge?: string) => string;
|
|
6
7
|
export declare const getAuthConfig: (_configUrls: AuthenticationConfig) => AuthenticationConfig;
|
|
7
8
|
export declare const AuthenticationContext: React.Context<AuthenticationContextProps>;
|
|
9
|
+
type OnAuthChange = (isLoggedIn: boolean, auth: Credentials | null) => void;
|
|
10
|
+
export declare const setAuthChangeListener: (listener: OnAuthChange) => void;
|
|
8
11
|
export declare const useAuthenticationDefaultProps: () => AuthenticationDefaultStateProps;
|
|
9
12
|
interface AuthenticationProviderProps {
|
|
10
13
|
children: React.ReactNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Credentials } from '../ApiContext/types';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Credentials } from '../ApiContext/types';
|
|
3
3
|
interface AuthenticationRenderTestComponentProps {
|
|
4
4
|
auth: Credentials | null;
|
|
5
5
|
newAuth: Credentials;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { useAuthenticationContext, AuthenticationProvider, useAuthenticationDefaultProps, AuthenticationContext, getAuthConfig, getRandomString, getCodeChallenge, } from './AuthenticationContext';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export { useAuthenticationContext, AuthenticationProvider, useAuthenticationDefaultProps, AuthenticationContext, getAuthConfig, getRandomString, getCodeChallenge, setAuthChangeListener, } from './AuthenticationContext';
|
|
2
|
+
export type * from './types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SessionStorageProvider } from '@opengeoweb/shared';
|
|
2
|
-
import { Credentials, Role } from '../ApiContext/types';
|
|
1
|
+
import type { SessionStorageProvider } from '@opengeoweb/shared';
|
|
2
|
+
import type { Credentials, Role } from '../ApiContext/types';
|
|
3
3
|
export interface AuthenticationConfig {
|
|
4
4
|
GW_AUTH_LOGIN_URL: string;
|
|
5
5
|
GW_AUTH_LOGOUT_URL: string;
|
|
@@ -22,3 +22,4 @@ export interface AuthenticationDefaultStateProps {
|
|
|
22
22
|
export interface AuthenticationContextProps extends AuthenticationDefaultStateProps {
|
|
23
23
|
authConfig: AuthenticationConfig;
|
|
24
24
|
}
|
|
25
|
+
export type AuthChangeListener = (isLoggedIn: boolean, auth: Credentials | null) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigType } from '@opengeoweb/shared';
|
|
1
|
+
import type { ConfigType } from '@opengeoweb/shared';
|
|
2
2
|
export type ApiParams = string | ConfigType | Record<string, string | undefined> | null;
|
|
3
3
|
interface BaseApiHookProps {
|
|
4
4
|
fetchApiData?: (params: ApiParams) => Promise<void>;
|
package/src/lib/utils/i18n.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import i18n from 'i18next';
|
|
2
|
-
import { UseTranslationResponse } from 'react-i18next';
|
|
2
|
+
import type { UseTranslationResponse } from 'react-i18next';
|
|
3
3
|
export declare const AUTH_NAMESPACE = "auth";
|
|
4
4
|
export declare const initAuthTestI18n: () => void;
|
|
5
5
|
export declare const useAuthenticationTranslation: () => UseTranslationResponse<typeof AUTH_NAMESPACE, typeof i18n>;
|