@opengeoweb/authentication 9.26.0 → 9.27.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 CHANGED
@@ -6951,7 +6951,8 @@ const refreshAccessTokenAndSetAuthContext = ({
6951
6951
  auth,
6952
6952
  onSetAuth,
6953
6953
  config,
6954
- timeout: _timeout2 = DEFAULT_TIMEOUT
6954
+ timeout: _timeout2 = DEFAULT_TIMEOUT,
6955
+ configURLS
6955
6956
  }) => __awaiter(void 0, void 0, void 0, function* () {
6956
6957
  try {
6957
6958
  const refreshedToken = yield refreshAccessToken({
@@ -6959,11 +6960,15 @@ const refreshAccessTokenAndSetAuthContext = ({
6959
6960
  config,
6960
6961
  timeout: _timeout2
6961
6962
  });
6962
- const newAuth = makeCredentialsFromTokenResponse(refreshedToken);
6963
+ const newAuth = makeCredentialsFromTokenResponse(refreshedToken, configURLS);
6963
6964
  // Cognito does not send a new refresh token, but gitlab does. Set it here into the auth context.
6964
6965
  if (!newAuth.refresh_token || newAuth.refresh_token.length === 0) {
6965
6966
  newAuth.refresh_token = auth.refresh_token;
6966
6967
  }
6968
+ // If the prop for the role config is not set, keep the roles of the current auth context.
6969
+ if (!configURLS) {
6970
+ newAuth.roles = auth.roles;
6971
+ }
6967
6972
  onSetAuth(newAuth);
6968
6973
  } catch (e) {
6969
6974
  onSetAuth(Object.assign(Object.assign({}, auth), {
@@ -7158,7 +7163,8 @@ const AuthenticationContext = /*#__PURE__*/React__default.createContext({
7158
7163
  auth: null,
7159
7164
  onSetAuth: null,
7160
7165
  authConfig: null,
7161
- sessionStorageProvider: null
7166
+ sessionStorageProvider: null,
7167
+ currentRole: null
7162
7168
  });
7163
7169
  const useAuthenticationDefaultProps = () => {
7164
7170
  const [isLoggedIn, onLogin] = React__default.useState(false);
@@ -7188,12 +7194,15 @@ const useAuthenticationDefaultProps = () => {
7188
7194
  }
7189
7195
  };
7190
7196
  const sessionStorageProvider = getSessionStorageProvider();
7197
+ const [currentRole, setCurrentRole] = React__default.useState(auth.roles && auth.roles[0] || GEOWEB_ROLE_USER);
7191
7198
  return {
7192
7199
  isLoggedIn,
7193
7200
  onLogin,
7194
7201
  auth: isLoggedIn ? auth : null,
7195
7202
  onSetAuth,
7196
- sessionStorageProvider
7203
+ sessionStorageProvider,
7204
+ currentRole,
7205
+ setCurrentRole
7197
7206
  };
7198
7207
  };
7199
7208
  const AuthenticationProvider = ({
@@ -7207,7 +7216,9 @@ const AuthenticationProvider = ({
7207
7216
  onLogin,
7208
7217
  auth,
7209
7218
  onSetAuth,
7210
- sessionStorageProvider
7219
+ sessionStorageProvider,
7220
+ currentRole,
7221
+ setCurrentRole
7211
7222
  } = value || defaultValues;
7212
7223
  const authConfig = _configURLS;
7213
7224
  const interval = useRef();
@@ -7224,7 +7235,8 @@ const AuthenticationProvider = ({
7224
7235
  authTokenURL: _configURLS.GW_AUTH_TOKEN_URL,
7225
7236
  appURL: _configURLS.GW_APP_URL,
7226
7237
  authClientId: _configURLS.GW_AUTH_CLIENT_ID
7227
- }
7238
+ },
7239
+ configURLS: _configURLS
7228
7240
  });
7229
7241
  }
7230
7242
  }
@@ -7232,15 +7244,17 @@ const AuthenticationProvider = ({
7232
7244
  return () => {
7233
7245
  clearInterval(interval.current);
7234
7246
  };
7235
- }, [auth, _configURLS.GW_APP_URL, _configURLS.GW_AUTH_CLIENT_ID, _configURLS.GW_AUTH_TOKEN_URL, onSetAuth]);
7247
+ }, [auth, _configURLS.GW_APP_URL, _configURLS.GW_AUTH_CLIENT_ID, _configURLS.GW_AUTH_TOKEN_URL, onSetAuth, _configURLS]);
7236
7248
  const contextValue = React__default.useMemo(() => ({
7237
7249
  isLoggedIn,
7238
7250
  onLogin,
7239
7251
  auth,
7240
7252
  onSetAuth,
7241
7253
  authConfig,
7242
- sessionStorageProvider
7243
- }), [isLoggedIn, onLogin, auth, onSetAuth, authConfig, sessionStorageProvider]);
7254
+ sessionStorageProvider,
7255
+ currentRole,
7256
+ setCurrentRole
7257
+ }), [isLoggedIn, onLogin, auth, onSetAuth, authConfig, sessionStorageProvider, currentRole, setCurrentRole]);
7244
7258
  return jsx(AuthenticationContext.Provider, Object.assign({
7245
7259
  value: contextValue
7246
7260
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/authentication",
3
- "version": "9.26.0",
3
+ "version": "9.27.0",
4
4
  "description": "GeoWeb authentication library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -14,13 +14,15 @@
14
14
  "@opengeoweb/theme": "*",
15
15
  "i18next": "^23.11.5",
16
16
  "react-i18next": "^14.1.2",
17
- "@opengeoweb/snackbar": "9.26.0",
17
+ "@opengeoweb/snackbar": "9.27.0",
18
18
  "react-redux": "^8.1.3",
19
19
  "@reduxjs/toolkit": "^1.9.7",
20
20
  "@mui/material": "^5.16.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "react": "18"
23
+ "react": "18",
24
+ "@emotion/react": "*",
25
+ "@emotion/styled": "*"
24
26
  },
25
27
  "module": "./index.esm.js",
26
28
  "type": "module",
@@ -17,7 +17,9 @@ export declare const GEOWEB_ROLE_USER: Role;
17
17
  */
18
18
  export declare const makeCredentialsFromTokenResponse: (tokenResponse: AxiosResponse, authConfig?: ConfigType) => Credentials;
19
19
  export declare const refreshAccessToken: ({ auth, config: { authTokenURL, authClientId, appURL }, timeout, }: CreateApiProps) => Promise<AxiosResponse>;
20
- export declare const refreshAccessTokenAndSetAuthContext: ({ auth, onSetAuth, config, timeout, }: CreateApiProps) => Promise<void>;
20
+ export declare const refreshAccessTokenAndSetAuthContext: ({ auth, onSetAuth, config, timeout, configURLS, }: CreateApiProps & {
21
+ configURLS?: ConfigType | undefined;
22
+ }) => Promise<void>;
21
23
  export declare const createApiInstance: ({ auth, onSetAuth, config: { baseURL, authTokenURL, authClientId, appURL }, timeout, }: CreateApiProps) => AxiosInstance;
22
24
  export declare const createNonAuthApiInstance: ({ config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
23
25
  export declare const fakeApiRequest: (signal?: AbortController) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { SessionStorageProvider } from '../../utils/session';
2
- import { Credentials } from '../ApiContext/types';
2
+ import { Credentials, Role } from '../ApiContext/types';
3
3
  export interface AuthenticationConfig {
4
4
  GW_AUTH_LOGIN_URL: string;
5
5
  GW_AUTH_LOGOUT_URL: string;
@@ -16,6 +16,8 @@ export interface AuthenticationDefaultStateProps {
16
16
  auth: Credentials | null;
17
17
  onSetAuth: (auth: Credentials) => void;
18
18
  sessionStorageProvider: SessionStorageProvider;
19
+ currentRole?: Role;
20
+ setCurrentRole?: (newRole: Role) => void;
19
21
  }
20
22
  export interface AuthenticationContextProps extends AuthenticationDefaultStateProps {
21
23
  authConfig: AuthenticationConfig;