@opengeoweb/authentication 15.1.0 → 15.3.0
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 +33 -161
- package/package.json +3 -6
- package/src/lib/components/ApiContext/index.d.ts +0 -1
- package/src/lib/components/Providers/Providers.d.ts +0 -4
- package/src/lib/components/UserMenuRoles/UserMenuRoles.d.ts +2 -3
- package/src/lib/components/UserMenuRoles/index.d.ts +0 -1
- package/src/lib/components/ApiContext/ApiContext.d.ts +0 -16
- package/src/lib/components/ApiContext/ApiContext.spec.d.ts +0 -1
- package/src/lib/components/UserMenuRoles/UserMenuRolesConnect.d.ts +0 -7
- package/src/lib/components/UserMenuRoles/UserMenuRolesConnect.spec.d.ts +0 -1
- package/src/lib/components/UserMenuRoles/UserMenuRolesConnect.stories.d.ts +0 -8
package/index.esm.js
CHANGED
|
@@ -6,9 +6,7 @@ import { sessionStorageProvider, useIsMounted, SHARED_NAMESPACE, AlertBanner, us
|
|
|
6
6
|
import { useTranslation, Trans } from 'react-i18next';
|
|
7
7
|
import { ThemeWrapper } from '@opengeoweb/theme';
|
|
8
8
|
import 'i18next';
|
|
9
|
-
import {
|
|
10
|
-
import { useDispatch } from 'react-redux';
|
|
11
|
-
import { snackbarTypes, snackbarActions } from '@opengeoweb/snackbar';
|
|
9
|
+
import { FormControl, FormLabel, RadioGroup, FormControlLabel, Radio } from '@mui/material';
|
|
12
10
|
|
|
13
11
|
var en$1 = {
|
|
14
12
|
"api-role-title-user": "User",
|
|
@@ -36,26 +34,22 @@ var apiTranslations = {
|
|
|
36
34
|
var en = {
|
|
37
35
|
"auth-logout-go-back-to-home-page": "Go back to the <1>Home Page</1>",
|
|
38
36
|
"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"
|
|
37
|
+
"auth-role-title": "Role"
|
|
41
38
|
};
|
|
42
39
|
var fi = {
|
|
43
40
|
"auth-logout-go-back-to-home-page": "Palaa takaisin <1>Kotisivulle</1>",
|
|
44
41
|
"auth-logout-you-are-logged-out": "Olet kirjautunut ulos.",
|
|
45
|
-
"auth-role-title": "Rooli"
|
|
46
|
-
"auth-role-message-assigned": "Rooli {{role}} on annettu"
|
|
42
|
+
"auth-role-title": "Rooli"
|
|
47
43
|
};
|
|
48
44
|
var no = {
|
|
49
45
|
"auth-logout-go-back-to-home-page": "Gå tilbake til <1>Hjemmesiden</1>",
|
|
50
46
|
"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"
|
|
47
|
+
"auth-role-title": "Rolle"
|
|
53
48
|
};
|
|
54
49
|
var nl = {
|
|
55
50
|
"auth-logout-go-back-to-home-page": "Ga terug naar de <1>Startpagina</1>",
|
|
56
51
|
"auth-logout-you-are-logged-out": "Je bent uitgelogd.",
|
|
57
|
-
"auth-role-title": "Rol"
|
|
58
|
-
"auth-role-message-assigned": "Rol {{role}} is geactiveerd"
|
|
52
|
+
"auth-role-title": "Rol"
|
|
59
53
|
};
|
|
60
54
|
var authTranslations = {
|
|
61
55
|
en: en,
|
|
@@ -92,15 +86,6 @@ function _asyncToGenerator(n) {
|
|
|
92
86
|
});
|
|
93
87
|
};
|
|
94
88
|
}
|
|
95
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
96
|
-
if (null == r) return {};
|
|
97
|
-
var t = {};
|
|
98
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
99
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
100
|
-
t[n] = r[n];
|
|
101
|
-
}
|
|
102
|
-
return t;
|
|
103
|
-
}
|
|
104
89
|
function _regenerator() {
|
|
105
90
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
106
91
|
var e,
|
|
@@ -1244,158 +1229,45 @@ var OAuth2Logout = function OAuth2Logout() {
|
|
|
1244
1229
|
};
|
|
1245
1230
|
|
|
1246
1231
|
var UserMenuRoles = function UserMenuRoles(_ref) {
|
|
1247
|
-
var
|
|
1232
|
+
var currentRole = _ref.currentRole,
|
|
1248
1233
|
onChangeRole = _ref.onChangeRole,
|
|
1249
|
-
|
|
1250
|
-
_ref$currentRole = _ref.currentRole,
|
|
1251
|
-
currentRole = _ref$currentRole === void 0 ? '' : _ref$currentRole;
|
|
1234
|
+
roles = _ref.roles;
|
|
1252
1235
|
var _useAuthenticationTra = useAuthenticationTranslation(),
|
|
1253
1236
|
t = _useAuthenticationTra.t;
|
|
1254
|
-
|
|
1255
|
-
|
|
1237
|
+
var handleChangeRole = function handleChangeRole(event) {
|
|
1238
|
+
var selectedRole = roles == null ? void 0 : roles.find(function (role) {
|
|
1239
|
+
return role.name === event.target.value;
|
|
1240
|
+
});
|
|
1241
|
+
if (selectedRole) {
|
|
1242
|
+
onChangeRole == null || onChangeRole(selectedRole);
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
return jsxs(FormControl, {
|
|
1246
|
+
children: [jsx(FormLabel, {
|
|
1247
|
+
component: "legend",
|
|
1256
1248
|
sx: {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1249
|
+
fontSize: 14,
|
|
1250
|
+
fontWeight: 400,
|
|
1251
|
+
color: 'geowebColors.typographyAndIcons.text',
|
|
1252
|
+
opacity: 1
|
|
1261
1253
|
},
|
|
1262
|
-
children:
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
sx: {
|
|
1270
|
-
fontSize: 14,
|
|
1271
|
-
fontWeight: 400,
|
|
1272
|
-
color: 'geowebColors.typographyAndIcons.text',
|
|
1273
|
-
opacity: 1
|
|
1274
|
-
},
|
|
1275
|
-
children: t('auth-role-title')
|
|
1276
|
-
}), roles == null ? void 0 : roles.map(function (role) {
|
|
1254
|
+
children: t('auth-role-title')
|
|
1255
|
+
}), jsx(RadioGroup, {
|
|
1256
|
+
"aria-labelledby": "user-menu-roles",
|
|
1257
|
+
name: "user-menu-roles",
|
|
1258
|
+
onChange: handleChangeRole,
|
|
1259
|
+
value: currentRole == null ? void 0 : currentRole.name,
|
|
1260
|
+
children: roles == null ? void 0 : roles.map(function (role) {
|
|
1277
1261
|
return jsx(FormControlLabel, {
|
|
1278
|
-
control: jsx(Radio, {
|
|
1279
|
-
checked: currentRole === role.name,
|
|
1280
|
-
disabled: isLoading
|
|
1281
|
-
}),
|
|
1262
|
+
control: jsx(Radio, {}),
|
|
1282
1263
|
label: t(role.title),
|
|
1283
|
-
|
|
1284
|
-
return onChangeRole(role);
|
|
1285
|
-
}
|
|
1264
|
+
value: role.name
|
|
1286
1265
|
}, role.name);
|
|
1287
|
-
})
|
|
1266
|
+
})
|
|
1288
1267
|
})]
|
|
1289
1268
|
});
|
|
1290
1269
|
};
|
|
1291
1270
|
|
|
1292
|
-
var UserMenuRolesConnect = function UserMenuRolesConnect(_ref) {
|
|
1293
|
-
var _ref$temporaryOnChang = _ref.temporaryOnChangeRoleForDemo,
|
|
1294
|
-
temporaryOnChangeRoleForDemo = _ref$temporaryOnChang === void 0 ? function () {} : _ref$temporaryOnChang,
|
|
1295
|
-
roles = _ref.roles,
|
|
1296
|
-
_ref$isAdmin = _ref.isAdmin,
|
|
1297
|
-
isAdmin = _ref$isAdmin === void 0 ? false : _ref$isAdmin;
|
|
1298
|
-
var defaultRole = isAdmin ? GEOWEB_ROLE_PRESETS_ADMIN.name : GEOWEB_ROLE_USER.name;
|
|
1299
|
-
var _React$useState = React.useState(false),
|
|
1300
|
-
isLoading = _React$useState[0],
|
|
1301
|
-
setIsLoading = _React$useState[1];
|
|
1302
|
-
var _React$useState2 = React.useState(defaultRole),
|
|
1303
|
-
currentRole = _React$useState2[0],
|
|
1304
|
-
setCurrentRole = _React$useState2[1];
|
|
1305
|
-
var dispatch = useDispatch();
|
|
1306
|
-
var _useAuthenticationTra = useAuthenticationTranslation(),
|
|
1307
|
-
t = _useAuthenticationTra.t;
|
|
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
|
-
}();
|
|
1328
|
-
var onChangeRole = function onChangeRole(role) {
|
|
1329
|
-
setIsLoading(true);
|
|
1330
|
-
onFakeRequest().then(function () {
|
|
1331
|
-
setCurrentRole(role.name);
|
|
1332
|
-
temporaryOnChangeRoleForDemo(role);
|
|
1333
|
-
var message = {
|
|
1334
|
-
type: snackbarTypes.SnackbarMessageType.TRANSLATABLE_MESSAGE,
|
|
1335
|
-
key: 'auth-role-message-assigned',
|
|
1336
|
-
params: {
|
|
1337
|
-
role: t(role.title)
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
dispatch(snackbarActions.openSnackbar(message));
|
|
1341
|
-
})["catch"](function () {})["finally"](function () {
|
|
1342
|
-
setIsLoading(false);
|
|
1343
|
-
});
|
|
1344
|
-
};
|
|
1345
|
-
return jsx(UserMenuRoles, {
|
|
1346
|
-
currentRole: currentRole,
|
|
1347
|
-
isLoading: isLoading,
|
|
1348
|
-
onChangeRole: onChangeRole,
|
|
1349
|
-
roles: roles
|
|
1350
|
-
});
|
|
1351
|
-
};
|
|
1352
|
-
|
|
1353
|
-
var _excluded = ["children", "createApi", "name"];
|
|
1354
|
-
var ApiContext = /*#__PURE__*/React.createContext({
|
|
1355
|
-
api: null
|
|
1356
|
-
});
|
|
1357
|
-
var registeredApis = new Map();
|
|
1358
|
-
function registerApi(name, api) {
|
|
1359
|
-
registeredApis.set(name, api);
|
|
1360
|
-
}
|
|
1361
|
-
function getApi(name) {
|
|
1362
|
-
return registeredApis.get(name);
|
|
1363
|
-
}
|
|
1364
|
-
var ApiProvider = function ApiProvider(_ref) {
|
|
1365
|
-
var children = _ref.children,
|
|
1366
|
-
createApi = _ref.createApi,
|
|
1367
|
-
name = _ref.name,
|
|
1368
|
-
apiModuleProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1369
|
-
var handleNewApi = React.useCallback(function () {
|
|
1370
|
-
var newApi = createApi(apiModuleProps);
|
|
1371
|
-
if (name) {
|
|
1372
|
-
registerApi(name, newApi);
|
|
1373
|
-
}
|
|
1374
|
-
return newApi;
|
|
1375
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1376
|
-
}, [createApi, name]);
|
|
1377
|
-
var _React$useState = React.useState(handleNewApi),
|
|
1378
|
-
api = _React$useState[0],
|
|
1379
|
-
setApi = _React$useState[1];
|
|
1380
|
-
React.useEffect(function () {
|
|
1381
|
-
setApi(handleNewApi);
|
|
1382
|
-
return function () {
|
|
1383
|
-
};
|
|
1384
|
-
}, [handleNewApi, name]);
|
|
1385
|
-
var contextValue = React.useMemo(function () {
|
|
1386
|
-
return {
|
|
1387
|
-
api: api
|
|
1388
|
-
};
|
|
1389
|
-
}, [api]);
|
|
1390
|
-
return jsx(ApiContext.Provider, {
|
|
1391
|
-
value: contextValue,
|
|
1392
|
-
children: children
|
|
1393
|
-
});
|
|
1394
|
-
};
|
|
1395
|
-
function useApiContext() {
|
|
1396
|
-
return React.useContext(ApiContext);
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
1271
|
var generateRandomId = function generateRandomId() {
|
|
1400
1272
|
return "-" + Math.random().toString(36).substring(2, 11);
|
|
1401
1273
|
};
|
|
@@ -1493,4 +1365,4 @@ params, callbacks) {
|
|
|
1493
1365
|
};
|
|
1494
1366
|
};
|
|
1495
1367
|
|
|
1496
|
-
export { AUTH_NAMESPACE,
|
|
1368
|
+
export { AUTH_NAMESPACE, 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, apiTranslations, authTranslations, createApiInstance, createFakeApiInstance, createNonAuthApiInstance, fakeApiRequest, getAuthConfig, getCodeChallenge, getCurrentTimeInSeconds, getCurrentUrlLocation, getRandomString, groupsToRoles, makeCredentialsFromTokenResponse, refreshAccessToken, refreshAccessTokenAndSetAuthContext, setAuthChangeListener, useApi, useAuthenticationContext, useAuthenticationDefaultProps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/authentication",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.3.0",
|
|
4
4
|
"description": "GeoWeb authentication library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -10,13 +10,10 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"axios": "^1.7.7",
|
|
12
12
|
"react-router-dom": "^6.23.1",
|
|
13
|
-
"@opengeoweb/shared": "15.
|
|
14
|
-
"@opengeoweb/theme": "15.
|
|
13
|
+
"@opengeoweb/shared": "15.3.0",
|
|
14
|
+
"@opengeoweb/theme": "15.3.0",
|
|
15
15
|
"i18next": "^25.0.1",
|
|
16
16
|
"react-i18next": "^15.1.1",
|
|
17
|
-
"@opengeoweb/snackbar": "15.1.0",
|
|
18
|
-
"react-redux": "^9.2.0",
|
|
19
|
-
"@reduxjs/toolkit": "^2.6.1",
|
|
20
17
|
"@mui/material": "^7.0.1"
|
|
21
18
|
},
|
|
22
19
|
"peerDependencies": {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { Store } from '@reduxjs/toolkit';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
interface AuthTranslationWrapperProps {
|
|
4
3
|
children?: React.ReactNode;
|
|
5
4
|
}
|
|
6
5
|
export declare const AuthI18nProvider: React.FC<AuthTranslationWrapperProps>;
|
|
7
6
|
export declare const DemoWrapper: React.FC<AuthTranslationWrapperProps>;
|
|
8
|
-
export declare const DemoWrapperConnect: React.FC<AuthTranslationWrapperProps & {
|
|
9
|
-
store: Store;
|
|
10
|
-
}>;
|
|
11
7
|
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Role } from '../ApiContext/types';
|
|
3
3
|
export declare const UserMenuRoles: React.FC<{
|
|
4
|
+
currentRole?: Role;
|
|
5
|
+
onChangeRole?: (role: Role) => void;
|
|
4
6
|
roles?: Role[];
|
|
5
|
-
currentRole?: string;
|
|
6
|
-
onChangeRole: (role: Role) => void;
|
|
7
|
-
isLoading: boolean;
|
|
8
7
|
}>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { ApiModule, CreateApiFn } from './types';
|
|
3
|
-
interface ApiContextState<ApiType> {
|
|
4
|
-
api: ApiType;
|
|
5
|
-
}
|
|
6
|
-
declare const ApiContext: React.Context<{
|
|
7
|
-
api: never;
|
|
8
|
-
}>;
|
|
9
|
-
interface ApiProviderProps extends ApiModule {
|
|
10
|
-
children: React.ReactNode;
|
|
11
|
-
createApi: CreateApiFn;
|
|
12
|
-
}
|
|
13
|
-
export declare function getApi<Type>(name: string): Type;
|
|
14
|
-
export declare const ApiProvider: React.FC<ApiProviderProps>;
|
|
15
|
-
export declare function useApiContext<ApiType>(): ApiContextState<ApiType>;
|
|
16
|
-
export default ApiContext;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { StoryObj } from '@storybook/react-webpack5';
|
|
2
|
-
import { UserMenuRolesConnect } from './UserMenuRolesConnect';
|
|
3
|
-
type Story = StoryObj<typeof UserMenuRolesConnect>;
|
|
4
|
-
declare const _default: {
|
|
5
|
-
title: string;
|
|
6
|
-
};
|
|
7
|
-
export default _default;
|
|
8
|
-
export declare const AuthenticationDemo: Story;
|