@opengeoweb/authentication 9.28.1 → 9.29.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.
Files changed (41) hide show
  1. package/index.esm.js +88 -80
  2. package/package.json +2 -2
  3. package/src/index.d.ts +14 -14
  4. package/src/lib/components/ApiContext/ApiContext.d.ts +16 -16
  5. package/src/lib/components/ApiContext/ApiContext.spec.d.ts +1 -1
  6. package/src/lib/components/ApiContext/index.d.ts +3 -3
  7. package/src/lib/components/ApiContext/types.d.ts +36 -35
  8. package/src/lib/components/ApiContext/utils.d.ts +27 -27
  9. package/src/lib/components/ApiContext/utils.spec.d.ts +1 -1
  10. package/src/lib/components/AuthenticationContext/AuthenticationContext.d.ts +16 -16
  11. package/src/lib/components/AuthenticationContext/AuthenticationContext.spec.d.ts +1 -1
  12. package/src/lib/components/AuthenticationContext/AuthenticationRenderTestComponent.d.ts +10 -10
  13. package/src/lib/components/AuthenticationContext/AuthenticationRenderTestComponent.spec.d.ts +1 -1
  14. package/src/lib/components/AuthenticationContext/index.d.ts +2 -2
  15. package/src/lib/components/AuthenticationContext/types.d.ts +24 -24
  16. package/src/lib/components/PrivateRoute/RequireAuth.d.ts +6 -6
  17. package/src/lib/components/PrivateRoute/RequireAuth.spec.d.ts +1 -1
  18. package/src/lib/components/PrivateRoute/index.d.ts +1 -1
  19. package/src/lib/components/Providers/Providers.d.ts +11 -11
  20. package/src/lib/components/Providers/index.d.ts +1 -1
  21. package/src/lib/components/UserMenuRoles/UserMenuRoles.d.ts +8 -8
  22. package/src/lib/components/UserMenuRoles/UserMenuRoles.spec.d.ts +1 -1
  23. package/src/lib/components/UserMenuRoles/UserMenuRolesConnect.d.ts +7 -7
  24. package/src/lib/components/UserMenuRoles/UserMenuRolesConnect.spec.d.ts +1 -1
  25. package/src/lib/components/UserMenuRoles/UserMenuRolesConnect.stories.d.ts +6 -6
  26. package/src/lib/components/UserMenuRoles/index.d.ts +2 -2
  27. package/src/lib/components/apiHooks/index.d.ts +1 -1
  28. package/src/lib/components/apiHooks/useApi.d.ts +36 -36
  29. package/src/lib/components/apiHooks/useApi.spec.d.ts +1 -1
  30. package/src/lib/components/pages/Code.d.ts +4 -4
  31. package/src/lib/components/pages/Code.spec.d.ts +1 -1
  32. package/src/lib/components/pages/Login.d.ts +3 -3
  33. package/src/lib/components/pages/Login.spec.d.ts +1 -1
  34. package/src/lib/components/pages/Logout.d.ts +3 -3
  35. package/src/lib/components/pages/Logout.spec.d.ts +1 -1
  36. package/src/lib/utils/i18n.d.ts +6 -6
  37. package/src/lib/utils/mockdata.d.ts +18 -18
  38. package/src/lib/utils/session.d.ts +29 -29
  39. package/src/lib/utils/session.spec.d.ts +1 -1
  40. package/src/lib/utils/utils.d.ts +1 -1
  41. package/src/lib/utils/utils.spec.d.ts +1 -1
package/index.esm.js CHANGED
@@ -9,7 +9,7 @@ import { useTranslation, Trans } from 'react-i18next';
9
9
  import 'i18next';
10
10
  import { Box, LinearProgress, FormGroup, FormLabel, FormControlLabel, Radio } from '@mui/material';
11
11
  import { useDispatch } from 'react-redux';
12
- import { snackbarActions } from '@opengeoweb/snackbar';
12
+ import { snackbarTypes, snackbarActions } from '@opengeoweb/snackbar';
13
13
 
14
14
  var en$1 = {
15
15
  "auth-logout-go-back-to-home-page": "Go back to the <1>Home Page</1>",
@@ -5665,22 +5665,22 @@ if ($stringify) {
5665
5665
  });
5666
5666
  }
5667
5667
 
5668
- /* *
5669
- * Licensed under the Apache License, Version 2.0 (the "License");
5670
- * you may not use this file except in compliance with the License.
5671
- * You may obtain a copy of the License at
5672
- *
5673
- * http://www.apache.org/licenses/LICENSE-2.0
5674
- *
5675
- * Unless required by applicable law or agreed to in writing, software
5676
- * distributed under the License is distributed on an "AS IS" BASIS,
5677
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5678
- * See the License for the specific language governing permissions and
5679
- * limitations under the License.
5680
- *
5681
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5682
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
5683
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
5668
+ /* *
5669
+ * Licensed under the Apache License, Version 2.0 (the "License");
5670
+ * you may not use this file except in compliance with the License.
5671
+ * You may obtain a copy of the License at
5672
+ *
5673
+ * http://www.apache.org/licenses/LICENSE-2.0
5674
+ *
5675
+ * Unless required by applicable law or agreed to in writing, software
5676
+ * distributed under the License is distributed on an "AS IS" BASIS,
5677
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5678
+ * See the License for the specific language governing permissions and
5679
+ * limitations under the License.
5680
+ *
5681
+ * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5682
+ * Copyright 2021 - Finnish Meteorological Institute (FMI)
5683
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
5684
5684
  * */
5685
5685
  var SessionStorageKey;
5686
5686
  (function (SessionStorageKey) {
@@ -6872,13 +6872,13 @@ const GEOWEB_ROLE_USER = {
6872
6872
  ns: ns$1
6873
6873
  })
6874
6874
  };
6875
- /**
6876
- * Creates a Credentials object based on the axios response from the token service.
6877
- *
6878
- * It will calculate the expires_at attribute based on the expires_in property found in the JWT.
6879
- *
6880
- * @param tokenResponse Response of the tokenservice as axios response object.
6881
- * @returns Credentials object.
6875
+ /**
6876
+ * Creates a Credentials object based on the axios response from the token service.
6877
+ *
6878
+ * It will calculate the expires_at attribute based on the expires_in property found in the JWT.
6879
+ *
6880
+ * @param tokenResponse Response of the tokenservice as axios response object.
6881
+ * @returns Credentials object.
6882
6882
  */
6883
6883
  const makeCredentialsFromTokenResponse = (tokenResponse, authConfig) => {
6884
6884
  const token = tokenResponse.data.body || tokenResponse.data;
@@ -6934,7 +6934,7 @@ const refreshAccessToken = ({
6934
6934
  grant_type: 'refresh_token',
6935
6935
  client_id: authClientId
6936
6936
  };
6937
- /* Send data in the "application/x-www-form-urlencoded" format.
6937
+ /* Send data in the "application/x-www-form-urlencoded" format.
6938
6938
  If only JSON is supported, use Axios' default content type ("application/x-www-form-urlencoded"). */
6939
6939
  const useDefaultContentType = authTokenURL.includes('amazonaws.com');
6940
6940
  const data = useDefaultContentType ? refreshPayload : new URLSearchParams(refreshPayload);
@@ -6950,8 +6950,10 @@ const refreshAccessTokenAndSetAuthContext = ({
6950
6950
  onSetAuth,
6951
6951
  config,
6952
6952
  timeout: _timeout2 = DEFAULT_TIMEOUT,
6953
- configURLS
6953
+ configURLS,
6954
+ onLogin
6954
6955
  }) => __awaiter(void 0, void 0, void 0, function* () {
6956
+ var _a;
6955
6957
  try {
6956
6958
  const refreshedToken = yield refreshAccessToken({
6957
6959
  auth,
@@ -6969,9 +6971,14 @@ const refreshAccessTokenAndSetAuthContext = ({
6969
6971
  }
6970
6972
  onSetAuth(newAuth);
6971
6973
  } catch (e) {
6972
- onSetAuth(Object.assign(Object.assign({}, auth), {
6973
- has_connection_issue: true
6974
- }));
6974
+ const status = (_a = e.response) === null || _a === void 0 ? void 0 : _a.status;
6975
+ if (status === 400) {
6976
+ onLogin(false);
6977
+ } else {
6978
+ onSetAuth(Object.assign(Object.assign({}, auth), {
6979
+ has_connection_issue: true
6980
+ }));
6981
+ }
6975
6982
  }
6976
6983
  });
6977
6984
  const createApiInstance = ({
@@ -7153,9 +7160,9 @@ const useAuthenticationDefaultProps = () => {
7153
7160
  if (newAuth) {
7154
7161
  Object.assign(auth, newAuth);
7155
7162
  if (newAuth.has_connection_issue !== undefined && hasConnectionIssue !== auth.has_connection_issue) {
7156
- /*
7157
- * The hasconnection issue should trigger a render.
7158
- * This is needed to make the connection banner show that there is an issue.
7163
+ /*
7164
+ * The hasconnection issue should trigger a render.
7165
+ * This is needed to make the connection banner show that there is an issue.
7159
7166
  */
7160
7167
  setHasConnectionIssue(auth.has_connection_issue === true);
7161
7168
  }
@@ -7208,7 +7215,8 @@ const AuthenticationProvider = ({
7208
7215
  appURL: _configURLS.GW_APP_URL,
7209
7216
  authClientId: _configURLS.GW_AUTH_CLIENT_ID
7210
7217
  },
7211
- configURLS: _configURLS
7218
+ configURLS: _configURLS,
7219
+ onLogin
7212
7220
  });
7213
7221
  }
7214
7222
  }
@@ -7216,7 +7224,7 @@ const AuthenticationProvider = ({
7216
7224
  return () => {
7217
7225
  clearInterval(interval.current);
7218
7226
  };
7219
- }, [auth, _configURLS.GW_APP_URL, _configURLS.GW_AUTH_CLIENT_ID, _configURLS.GW_AUTH_TOKEN_URL, onSetAuth, _configURLS]);
7227
+ }, [auth, _configURLS.GW_APP_URL, _configURLS.GW_AUTH_CLIENT_ID, _configURLS.GW_AUTH_TOKEN_URL, onSetAuth, _configURLS, onLogin]);
7220
7228
  const contextValue = React__default.useMemo(() => ({
7221
7229
  isLoggedIn,
7222
7230
  onLogin,
@@ -7284,7 +7292,7 @@ const HandleOAuth2Code = () => {
7284
7292
  }, isPkceRequired && {
7285
7293
  code_verifier: sessionStorageProvider.getOauthCodeVerifier()
7286
7294
  });
7287
- /* Send data in the "application/x-www-form-urlencoded" format.
7295
+ /* Send data in the "application/x-www-form-urlencoded" format.
7288
7296
  If only JSON is supported, use Axios' default content type ("application/x-www-form-urlencoded"). */
7289
7297
  const useDefaultContentType = authConfig.GW_AUTH_TOKEN_URL.includes('amazonaws.com');
7290
7298
  const data = useDefaultContentType ? payload : new URLSearchParams(payload);
@@ -7345,41 +7353,41 @@ const HandleOAuth2Code = () => {
7345
7353
  });
7346
7354
  };
7347
7355
 
7348
- /* *
7349
- * Licensed under the Apache License, Version 2.0 (the "License");
7350
- * you may not use this file except in compliance with the License.
7351
- * You may obtain a copy of the License at
7352
- *
7353
- * http://www.apache.org/licenses/LICENSE-2.0
7354
- *
7355
- * Unless required by applicable law or agreed to in writing, software
7356
- * distributed under the License is distributed on an "AS IS" BASIS,
7357
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7358
- * See the License for the specific language governing permissions and
7359
- * limitations under the License.
7360
- *
7361
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
7362
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
7363
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
7356
+ /* *
7357
+ * Licensed under the Apache License, Version 2.0 (the "License");
7358
+ * you may not use this file except in compliance with the License.
7359
+ * You may obtain a copy of the License at
7360
+ *
7361
+ * http://www.apache.org/licenses/LICENSE-2.0
7362
+ *
7363
+ * Unless required by applicable law or agreed to in writing, software
7364
+ * distributed under the License is distributed on an "AS IS" BASIS,
7365
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7366
+ * See the License for the specific language governing permissions and
7367
+ * limitations under the License.
7368
+ *
7369
+ * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
7370
+ * Copyright 2023 - Finnish Meteorological Institute (FMI)
7371
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
7364
7372
  * */
7365
7373
  const getCurrentUrlLocation = (url, appUrl) => url ? url.replace(appUrl, '') : '/';
7366
7374
 
7367
- /* *
7368
- * Licensed under the Apache License, Version 2.0 (the "License");
7369
- * you may not use this file except in compliance with the License.
7370
- * You may obtain a copy of the License at
7371
- *
7372
- * http://www.apache.org/licenses/LICENSE-2.0
7373
- *
7374
- * Unless required by applicable law or agreed to in writing, software
7375
- * distributed under the License is distributed on an "AS IS" BASIS,
7376
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7377
- * See the License for the specific language governing permissions and
7378
- * limitations under the License.
7379
- *
7380
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
7381
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
7382
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
7375
+ /* *
7376
+ * Licensed under the Apache License, Version 2.0 (the "License");
7377
+ * you may not use this file except in compliance with the License.
7378
+ * You may obtain a copy of the License at
7379
+ *
7380
+ * http://www.apache.org/licenses/LICENSE-2.0
7381
+ *
7382
+ * Unless required by applicable law or agreed to in writing, software
7383
+ * distributed under the License is distributed on an "AS IS" BASIS,
7384
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7385
+ * See the License for the specific language governing permissions and
7386
+ * limitations under the License.
7387
+ *
7388
+ * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
7389
+ * Copyright 2021 - Finnish Meteorological Institute (FMI)
7390
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
7383
7391
  * */
7384
7392
  const OAuth2Login = () => {
7385
7393
  const {
@@ -7511,12 +7519,14 @@ const UserMenuRolesConnect = ({
7511
7519
  setIsLoading(false);
7512
7520
  setCurrentRole(role.name);
7513
7521
  _temporaryOnChangeRoleForDemo(role);
7514
- const message = t('auth-role-message-assigned', {
7515
- role: role.getTitle(t)
7516
- });
7517
- dispatch(snackbarActions.openSnackbar({
7518
- message
7519
- }));
7522
+ const message = {
7523
+ type: snackbarTypes.SnackbarMessageType.TRANSLATABLE_MESSAGE,
7524
+ key: 'auth-role-message-assigned',
7525
+ params: {
7526
+ role: role.getTitle(t)
7527
+ }
7528
+ };
7529
+ dispatch(snackbarActions.openSnackbar(message));
7520
7530
  });
7521
7531
  };
7522
7532
  return jsx(UserMenuRoles, {
@@ -7533,12 +7543,10 @@ const RequireAuth = ({
7533
7543
  const {
7534
7544
  isLoggedIn
7535
7545
  } = useAuthenticationContext();
7536
- return isLoggedIn ? children : jsx(Navigate, {
7537
- to: "/login",
7538
- state: {
7539
- url: window.location.href
7540
- }
7541
- });
7546
+ if (!isLoggedIn) {
7547
+ window.location.assign('/login');
7548
+ }
7549
+ return children;
7542
7550
  };
7543
7551
 
7544
7552
  const ApiContext = /*#__PURE__*/React.createContext({
@@ -7585,7 +7593,7 @@ function useApiContext() {
7585
7593
  return React.useContext(ApiContext);
7586
7594
  }
7587
7595
 
7588
- const generateRandomId = () => `-${Math.random().toString(36).substr(2, 9)}`;
7596
+ const generateRandomId = () => `-${Math.random().toString(36).substring(2, 11)}`;
7589
7597
  const useApi = (apiCall, params, callbacks) => {
7590
7598
  const {
7591
7599
  isMounted
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/authentication",
3
- "version": "9.28.1",
3
+ "version": "9.29.0",
4
4
  "description": "GeoWeb authentication library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -14,7 +14,7 @@
14
14
  "@opengeoweb/theme": "*",
15
15
  "i18next": "^23.11.5",
16
16
  "react-i18next": "^14.1.2",
17
- "@opengeoweb/snackbar": "9.28.1",
17
+ "@opengeoweb/snackbar": "9.29.0",
18
18
  "react-redux": "^8.1.3",
19
19
  "@reduxjs/toolkit": "^1.9.7",
20
20
  "@mui/material": "^6.1.1"
package/src/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import authTranslations from '../locales/authentication.json';
2
- import apiTranslations from '../locales/api.json';
3
- export { default as Code } from './lib/components/pages/Code';
4
- export { default as Login } from './lib/components/pages/Login';
5
- export { default as Logout } from './lib/components/pages/Logout';
6
- export * from './lib/components/UserMenuRoles';
7
- export * from './lib/components/AuthenticationContext';
8
- export * from './lib/components/PrivateRoute';
9
- export * from './lib/components/ApiContext';
10
- export * from './lib/components/apiHooks';
11
- export * from './lib/utils/session';
12
- export * from './lib/utils/utils';
13
- export { AUTH_NAMESPACE } from './lib/utils/i18n';
14
- export { authTranslations, apiTranslations };
1
+ import authTranslations from '../locales/authentication.json';
2
+ import apiTranslations from '../locales/api.json';
3
+ export { default as Code } from './lib/components/pages/Code';
4
+ export { default as Login } from './lib/components/pages/Login';
5
+ export { default as Logout } from './lib/components/pages/Logout';
6
+ export * from './lib/components/UserMenuRoles';
7
+ export * from './lib/components/AuthenticationContext';
8
+ export * from './lib/components/PrivateRoute';
9
+ export * from './lib/components/ApiContext';
10
+ export * from './lib/components/apiHooks';
11
+ export * from './lib/utils/session';
12
+ export * from './lib/utils/utils';
13
+ export { AUTH_NAMESPACE } from './lib/utils/i18n';
14
+ export { authTranslations, apiTranslations };
@@ -1,16 +1,16 @@
1
- import * as React from 'react';
2
- import { 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
+ import * as React from 'react';
2
+ import { 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 +1 @@
1
- export {};
1
+ export {};
@@ -1,3 +1,3 @@
1
- export * from './ApiContext';
2
- export * from './utils';
3
- export * from './types';
1
+ export * from './ApiContext';
2
+ export * from './utils';
3
+ export * from './types';
@@ -1,35 +1,36 @@
1
- import { TFunction } from 'i18next';
2
- export interface GeoWebJWT {
3
- access_token: string;
4
- refresh_token?: string;
5
- id_token: string;
6
- expires_in: number;
7
- }
8
- export interface Credentials {
9
- username: string;
10
- roles?: Role[];
11
- token: string;
12
- refresh_token: string;
13
- expires_at?: number;
14
- has_connection_issue?: boolean;
15
- }
16
- export interface ApiUrls {
17
- baseURL?: string;
18
- appURL?: string;
19
- authTokenURL?: string;
20
- authClientId?: string;
21
- }
22
- export interface ApiModule {
23
- auth?: Credentials;
24
- onSetAuth?: (cred: Credentials) => void;
25
- config?: ApiUrls;
26
- name?: string;
27
- }
28
- export interface CreateApiProps extends ApiModule {
29
- timeout?: number;
30
- }
31
- export type CreateApiFn = (props: CreateApiProps) => void;
32
- export interface Role {
33
- name: string;
34
- getTitle: (t: TFunction) => string;
35
- }
1
+ import { TFunction } from 'i18next';
2
+ export interface GeoWebJWT {
3
+ access_token: string;
4
+ refresh_token?: string;
5
+ id_token: string;
6
+ expires_in: number;
7
+ }
8
+ export interface Credentials {
9
+ username: string;
10
+ roles?: Role[];
11
+ token: string;
12
+ refresh_token: string;
13
+ expires_at?: number;
14
+ has_connection_issue?: boolean;
15
+ }
16
+ export interface ApiUrls {
17
+ baseURL?: string;
18
+ appURL?: string;
19
+ authTokenURL?: string;
20
+ authClientId?: string;
21
+ }
22
+ export interface ApiModule {
23
+ auth?: Credentials;
24
+ onSetAuth?: (cred: Credentials) => void;
25
+ config?: ApiUrls;
26
+ name?: string;
27
+ onLogin?: (isLoggedIn: boolean) => void;
28
+ }
29
+ export interface CreateApiProps extends ApiModule {
30
+ timeout?: number;
31
+ }
32
+ export type CreateApiFn = (props: CreateApiProps) => void;
33
+ export interface Role {
34
+ name: string;
35
+ getTitle: (t: TFunction) => string;
36
+ }
@@ -1,27 +1,27 @@
1
- import { AxiosInstance, AxiosResponse } from 'axios';
2
- import { ConfigType } from '@opengeoweb/shared';
3
- import { CreateApiProps, Credentials, Role } from './types';
4
- export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 60;
5
- export declare const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75;
6
- export declare const MILLISECOND_TO_SECOND: number;
7
- export declare const GEOWEB_ROLE_PRESETS_ADMIN: Role;
8
- export declare const GEOWEB_ROLE_USER: Role;
9
- /**
10
- * Creates a Credentials object based on the axios response from the token service.
11
- *
12
- * It will calculate the expires_at attribute based on the expires_in property found in the JWT.
13
- *
14
- * @param tokenResponse Response of the tokenservice as axios response object.
15
- * @returns Credentials object.
16
- */
17
- export declare const makeCredentialsFromTokenResponse: (tokenResponse: AxiosResponse, authConfig?: ConfigType) => Credentials;
18
- export declare const refreshAccessToken: ({ auth, config: { authTokenURL, authClientId, appURL }, timeout, }: CreateApiProps) => Promise<AxiosResponse>;
19
- export declare const refreshAccessTokenAndSetAuthContext: ({ auth, onSetAuth, config, timeout, configURLS, }: CreateApiProps & {
20
- configURLS?: ConfigType | undefined;
21
- }) => Promise<void>;
22
- export declare const createApiInstance: ({ auth, config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
23
- export declare const createNonAuthApiInstance: ({ config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
24
- export declare const fakeApiRequest: (signal?: AbortController) => Promise<void>;
25
- export declare const createFakeApiInstance: () => AxiosInstance;
26
- export declare const getCurrentTimeInSeconds: () => number;
27
- export declare const groupsToRoles: (groups: string[] | undefined, authConfig?: ConfigType) => Role[];
1
+ import { AxiosInstance, AxiosResponse } from 'axios';
2
+ import { ConfigType } from '@opengeoweb/shared';
3
+ import { CreateApiProps, Credentials, Role } from './types';
4
+ export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 60;
5
+ export declare const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75;
6
+ export declare const MILLISECOND_TO_SECOND: number;
7
+ export declare const GEOWEB_ROLE_PRESETS_ADMIN: Role;
8
+ export declare const GEOWEB_ROLE_USER: Role;
9
+ /**
10
+ * Creates a Credentials object based on the axios response from the token service.
11
+ *
12
+ * It will calculate the expires_at attribute based on the expires_in property found in the JWT.
13
+ *
14
+ * @param tokenResponse Response of the tokenservice as axios response object.
15
+ * @returns Credentials object.
16
+ */
17
+ export declare const makeCredentialsFromTokenResponse: (tokenResponse: AxiosResponse, authConfig?: ConfigType) => Credentials;
18
+ export declare const refreshAccessToken: ({ auth, config: { authTokenURL, authClientId, appURL }, timeout, }: CreateApiProps) => Promise<AxiosResponse>;
19
+ export declare const refreshAccessTokenAndSetAuthContext: ({ auth, onSetAuth, config, timeout, configURLS, onLogin, }: CreateApiProps & {
20
+ configURLS?: ConfigType | undefined;
21
+ }) => Promise<void>;
22
+ export declare const createApiInstance: ({ auth, config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
23
+ export declare const createNonAuthApiInstance: ({ config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
24
+ export declare const fakeApiRequest: (signal?: AbortController) => Promise<void>;
25
+ export declare const createFakeApiInstance: () => AxiosInstance;
26
+ export declare const getCurrentTimeInSeconds: () => number;
27
+ export declare const groupsToRoles: (groups: string[] | undefined, authConfig?: ConfigType) => Role[];
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,16 +1,16 @@
1
- import React from 'react';
2
- import { AuthenticationConfig, AuthenticationContextProps, AuthenticationDefaultStateProps } from './types';
3
- export declare const getRandomString: () => string;
4
- export declare const getCodeChallenge: (codeVerifier: string) => Promise<string>;
5
- export declare const replaceTemplateKeys: (url: string, clientId: string, appUrl: string, oauthState?: string, codeChallenge?: string) => string;
6
- export declare const getAuthConfig: (_configUrls: AuthenticationConfig) => AuthenticationConfig;
7
- export declare const AuthenticationContext: React.Context<AuthenticationContextProps>;
8
- export declare const useAuthenticationDefaultProps: () => AuthenticationDefaultStateProps;
9
- interface AuthenticationProviderProps {
10
- children: React.ReactNode;
11
- value?: AuthenticationDefaultStateProps;
12
- configURLS?: AuthenticationConfig;
13
- }
14
- export declare const AuthenticationProvider: React.FC<AuthenticationProviderProps>;
15
- export declare const useAuthenticationContext: () => AuthenticationContextProps;
16
- export {};
1
+ import React from 'react';
2
+ import { AuthenticationConfig, AuthenticationContextProps, AuthenticationDefaultStateProps } from './types';
3
+ export declare const getRandomString: () => string;
4
+ export declare const getCodeChallenge: (codeVerifier: string) => Promise<string>;
5
+ export declare const replaceTemplateKeys: (url: string, clientId: string, appUrl: string, oauthState?: string, codeChallenge?: string) => string;
6
+ export declare const getAuthConfig: (_configUrls: AuthenticationConfig) => AuthenticationConfig;
7
+ export declare const AuthenticationContext: React.Context<AuthenticationContextProps>;
8
+ export declare const useAuthenticationDefaultProps: () => AuthenticationDefaultStateProps;
9
+ interface AuthenticationProviderProps {
10
+ children: React.ReactNode;
11
+ value?: AuthenticationDefaultStateProps;
12
+ configURLS?: AuthenticationConfig;
13
+ }
14
+ export declare const AuthenticationProvider: React.FC<AuthenticationProviderProps>;
15
+ export declare const useAuthenticationContext: () => AuthenticationContextProps;
16
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,10 +1,10 @@
1
- import * as React from 'react';
2
- import { Credentials } from '../ApiContext/types';
3
- interface AuthenticationRenderTestComponentProps {
4
- auth: Credentials | null;
5
- newAuth: Credentials;
6
- onSetAuth: (auth: Credentials) => void;
7
- }
8
- export declare const resetNumRenders: () => void;
9
- declare const AuthenticationRenderTestComponent: React.FC<AuthenticationRenderTestComponentProps>;
10
- export default AuthenticationRenderTestComponent;
1
+ import * as React from 'react';
2
+ import { Credentials } from '../ApiContext/types';
3
+ interface AuthenticationRenderTestComponentProps {
4
+ auth: Credentials | null;
5
+ newAuth: Credentials;
6
+ onSetAuth: (auth: Credentials) => void;
7
+ }
8
+ export declare const resetNumRenders: () => void;
9
+ declare const AuthenticationRenderTestComponent: React.FC<AuthenticationRenderTestComponentProps>;
10
+ export default AuthenticationRenderTestComponent;
@@ -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, } from './AuthenticationContext';
2
+ export * from './types';
@@ -1,24 +1,24 @@
1
- import { SessionStorageProvider } from '../../utils/session';
2
- import { Credentials, Role } from '../ApiContext/types';
3
- export interface AuthenticationConfig {
4
- GW_AUTH_LOGIN_URL: string;
5
- GW_AUTH_LOGOUT_URL: string;
6
- GW_AUTH_TOKEN_URL: string;
7
- GW_AUTH_ROLE_CLAIM_NAME?: string;
8
- GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN?: string;
9
- GW_APP_URL: string;
10
- GW_BE_VERSION_BASE_URL?: string;
11
- GW_AUTH_CLIENT_ID: string;
12
- }
13
- export interface AuthenticationDefaultStateProps {
14
- isLoggedIn: boolean;
15
- onLogin: (isLoggedIn: boolean) => void;
16
- auth: Credentials | null;
17
- onSetAuth: (auth: Credentials) => void;
18
- sessionStorageProvider: SessionStorageProvider;
19
- currentRole?: Role;
20
- setCurrentRole?: (newRole: Role) => void;
21
- }
22
- export interface AuthenticationContextProps extends AuthenticationDefaultStateProps {
23
- authConfig: AuthenticationConfig;
24
- }
1
+ import { SessionStorageProvider } from '../../utils/session';
2
+ import { Credentials, Role } from '../ApiContext/types';
3
+ export interface AuthenticationConfig {
4
+ GW_AUTH_LOGIN_URL: string;
5
+ GW_AUTH_LOGOUT_URL: string;
6
+ GW_AUTH_TOKEN_URL: string;
7
+ GW_AUTH_ROLE_CLAIM_NAME?: string;
8
+ GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN?: string;
9
+ GW_APP_URL: string;
10
+ GW_BE_VERSION_BASE_URL?: string;
11
+ GW_AUTH_CLIENT_ID: string;
12
+ }
13
+ export interface AuthenticationDefaultStateProps {
14
+ isLoggedIn: boolean;
15
+ onLogin: (isLoggedIn: boolean) => void;
16
+ auth: Credentials | null;
17
+ onSetAuth: (auth: Credentials) => void;
18
+ sessionStorageProvider: SessionStorageProvider;
19
+ currentRole?: Role;
20
+ setCurrentRole?: (newRole: Role) => void;
21
+ }
22
+ export interface AuthenticationContextProps extends AuthenticationDefaultStateProps {
23
+ authConfig: AuthenticationConfig;
24
+ }
@@ -1,6 +1,6 @@
1
- import React from 'react';
2
- interface RequireAuthProps {
3
- children: React.ReactElement;
4
- }
5
- export declare const RequireAuth: React.FC<RequireAuthProps>;
6
- export {};
1
+ import React from 'react';
2
+ interface RequireAuthProps {
3
+ children: React.ReactElement;
4
+ }
5
+ export declare const RequireAuth: React.FC<RequireAuthProps>;
6
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- export * from './RequireAuth';
1
+ export * from './RequireAuth';
@@ -1,11 +1,11 @@
1
- import React from 'react';
2
- import { Store } from '@reduxjs/toolkit';
3
- interface AuthTranslationWrapperProps {
4
- children?: React.ReactNode;
5
- }
6
- export declare const AuthI18nProvider: React.FC<AuthTranslationWrapperProps>;
7
- export declare const DemoWrapper: React.FC<AuthTranslationWrapperProps>;
8
- export declare const DemoWrapperConnect: React.FC<AuthTranslationWrapperProps & {
9
- store: Store;
10
- }>;
11
- export {};
1
+ import React from 'react';
2
+ import { Store } from '@reduxjs/toolkit';
3
+ interface AuthTranslationWrapperProps {
4
+ children?: React.ReactNode;
5
+ }
6
+ export declare const AuthI18nProvider: React.FC<AuthTranslationWrapperProps>;
7
+ export declare const DemoWrapper: React.FC<AuthTranslationWrapperProps>;
8
+ export declare const DemoWrapperConnect: React.FC<AuthTranslationWrapperProps & {
9
+ store: Store;
10
+ }>;
11
+ export {};
@@ -1 +1 @@
1
- export * from './Providers';
1
+ export * from './Providers';
@@ -1,8 +1,8 @@
1
- import React from 'react';
2
- import { Role } from '../ApiContext/types';
3
- export declare const UserMenuRoles: React.FC<{
4
- roles?: Role[];
5
- currentRole?: string;
6
- onChangeRole: (role: Role) => void;
7
- isLoading: boolean;
8
- }>;
1
+ import React from 'react';
2
+ import { Role } from '../ApiContext/types';
3
+ export declare const UserMenuRoles: React.FC<{
4
+ roles?: Role[];
5
+ currentRole?: string;
6
+ onChangeRole: (role: Role) => void;
7
+ isLoading: boolean;
8
+ }>;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,7 +1,7 @@
1
- import React from 'react';
2
- import { Role } from '../ApiContext/types';
3
- export declare const UserMenuRolesConnect: React.FC<{
4
- temporaryOnChangeRoleForDemo?: (role: Role) => void;
5
- roles?: Role[];
6
- isAdmin?: boolean;
7
- }>;
1
+ import React from 'react';
2
+ import { Role } from '../ApiContext/types';
3
+ export declare const UserMenuRolesConnect: React.FC<{
4
+ temporaryOnChangeRoleForDemo?: (role: Role) => void;
5
+ roles?: Role[];
6
+ isAdmin?: boolean;
7
+ }>;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,6 +1,6 @@
1
- import React from 'react';
2
- declare const _default: {
3
- title: string;
4
- };
5
- export default _default;
6
- export declare const AuthenticationDemo: React.FC;
1
+ import React from 'react';
2
+ declare const _default: {
3
+ title: string;
4
+ };
5
+ export default _default;
6
+ export declare const AuthenticationDemo: React.FC;
@@ -1,2 +1,2 @@
1
- export { UserMenuRoles } from './UserMenuRoles';
2
- export * from './UserMenuRolesConnect';
1
+ export { UserMenuRoles } from './UserMenuRoles';
2
+ export * from './UserMenuRolesConnect';
@@ -1 +1 @@
1
- export { useApi } from './useApi';
1
+ export { useApi } from './useApi';
@@ -1,36 +1,36 @@
1
- import { ConfigType } from '@opengeoweb/shared';
2
- export type ApiParams = string | ConfigType | Record<string, string | undefined> | null;
3
- interface BaseApiHookProps {
4
- fetchApiData?: (params: ApiParams) => Promise<void>;
5
- clearResults?: () => void;
6
- }
7
- type PendingApiHookProps = BaseApiHookProps & {
8
- isLoading: true;
9
- result: null;
10
- error: null;
11
- };
12
- type DoneApiHookProps<R> = BaseApiHookProps & {
13
- isLoading: false;
14
- result: R;
15
- error: null;
16
- };
17
- type ErrorApiHookProps = BaseApiHookProps & {
18
- isLoading: false;
19
- result: null;
20
- error: Error;
21
- };
22
- export type ApiHookProps<TData> = ErrorApiHookProps | PendingApiHookProps | DoneApiHookProps<TData>;
23
- interface Callbacks<TData> {
24
- onSuccess?: (data: TData) => void;
25
- onError?: (e: Error) => void;
26
- }
27
- export declare const useApi: <TResponse extends {
28
- data: unknown;
29
- } | {
30
- data: unknown;
31
- }[], TResult = TResponse extends {
32
- data: infer TData;
33
- }[] ? TData[] : TResponse extends {
34
- data: infer TData_1;
35
- } ? TData_1 : never>(apiCall?: ((params?: ApiParams, id?: string) => Promise<TResponse>) | undefined, params?: ApiParams, callbacks?: Callbacks<TResult> | undefined) => ApiHookProps<TResult>;
36
- export {};
1
+ import { ConfigType } from '@opengeoweb/shared';
2
+ export type ApiParams = string | ConfigType | Record<string, string | undefined> | null;
3
+ interface BaseApiHookProps {
4
+ fetchApiData?: (params: ApiParams) => Promise<void>;
5
+ clearResults?: () => void;
6
+ }
7
+ type PendingApiHookProps = BaseApiHookProps & {
8
+ isLoading: true;
9
+ result: null;
10
+ error: null;
11
+ };
12
+ type DoneApiHookProps<R> = BaseApiHookProps & {
13
+ isLoading: false;
14
+ result: R;
15
+ error: null;
16
+ };
17
+ type ErrorApiHookProps = BaseApiHookProps & {
18
+ isLoading: false;
19
+ result: null;
20
+ error: Error;
21
+ };
22
+ export type ApiHookProps<TData> = ErrorApiHookProps | PendingApiHookProps | DoneApiHookProps<TData>;
23
+ interface Callbacks<TData> {
24
+ onSuccess?: (data: TData) => void;
25
+ onError?: (e: Error) => void;
26
+ }
27
+ export declare const useApi: <TResponse extends {
28
+ data: unknown;
29
+ } | {
30
+ data: unknown;
31
+ }[], TResult = TResponse extends {
32
+ data: infer TData;
33
+ }[] ? TData[] : TResponse extends {
34
+ data: infer TData_1;
35
+ } ? TData_1 : never>(apiCall?: ((params?: ApiParams, id?: string) => Promise<TResponse>) | undefined, params?: ApiParams, callbacks?: Callbacks<TResult> | undefined) => ApiHookProps<TResult>;
36
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,4 +1,4 @@
1
- import React from 'react';
2
- export declare const axiosInstance: import("axios").AxiosInstance;
3
- export declare const HandleOAuth2Code: React.FC;
4
- export default HandleOAuth2Code;
1
+ import React from 'react';
2
+ export declare const axiosInstance: import("axios").AxiosInstance;
3
+ export declare const HandleOAuth2Code: React.FC;
4
+ export default HandleOAuth2Code;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
- declare const OAuth2Login: React.FC;
3
- export default OAuth2Login;
1
+ import React from 'react';
2
+ declare const OAuth2Login: React.FC;
3
+ export default OAuth2Login;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
- declare const OAuth2Logout: React.FC;
3
- export default OAuth2Logout;
1
+ import React from 'react';
2
+ declare const OAuth2Logout: React.FC;
3
+ export default OAuth2Logout;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,6 +1,6 @@
1
- import i18n from 'i18next';
2
- import { UseTranslationResponse } from 'react-i18next';
3
- export declare const AUTH_NAMESPACE = "auth";
4
- export declare const initAuthTestI18n: () => void;
5
- export declare const useAuthenticationTranslation: () => UseTranslationResponse<typeof AUTH_NAMESPACE, typeof i18n>;
6
- export declare const translateKeyOutsideComponents: (key: string, params?: Record<string, string | number> | undefined) => string;
1
+ import i18n from 'i18next';
2
+ import { UseTranslationResponse } from 'react-i18next';
3
+ export declare const AUTH_NAMESPACE = "auth";
4
+ export declare const initAuthTestI18n: () => void;
5
+ export declare const useAuthenticationTranslation: () => UseTranslationResponse<typeof AUTH_NAMESPACE, typeof i18n>;
6
+ export declare const translateKeyOutsideComponents: (key: string, params?: Record<string, string | number> | undefined) => string;
@@ -1,18 +1,18 @@
1
- export declare const mockloginSuccess: {
2
- statusCode: number;
3
- body: {
4
- access_token: string;
5
- refresh_token: string;
6
- id_token: string;
7
- };
8
- };
9
- export declare const mockloginSuccessGitlab: {
10
- statusCode: number;
11
- access_token: string;
12
- refresh_token: string;
13
- id_token: string;
14
- };
15
- export declare const mockloginFailed: {
16
- statusCode: number;
17
- body: {};
18
- };
1
+ export declare const mockloginSuccess: {
2
+ statusCode: number;
3
+ body: {
4
+ access_token: string;
5
+ refresh_token: string;
6
+ id_token: string;
7
+ };
8
+ };
9
+ export declare const mockloginSuccessGitlab: {
10
+ statusCode: number;
11
+ access_token: string;
12
+ refresh_token: string;
13
+ id_token: string;
14
+ };
15
+ export declare const mockloginFailed: {
16
+ statusCode: number;
17
+ body: {};
18
+ };
@@ -1,29 +1,29 @@
1
- import { ConfigType } from '@opengeoweb/shared';
2
- export interface SessionStorageProvider {
3
- setConfig: (value: ConfigType) => void;
4
- getConfig: () => ConfigType;
5
- setOauthState: (value: string) => void;
6
- getOauthState: () => string;
7
- removeOauthState: () => void;
8
- setOauthCodeVerifier: (value: string) => void;
9
- getOauthCodeVerifier: () => string;
10
- removeOauthCodeVerifier: () => void;
11
- setOauthCodeChallenge: (value: string) => void;
12
- getOauthCodeChallenge: () => string;
13
- removeOauthCodeChallenge: () => void;
14
- setHasAuthenticated: (value: string) => void;
15
- getHasAuthenticated: () => string;
16
- removeHasAuthenticated: () => void;
17
- getCallbackUrl: () => string;
18
- setCallbackUrl: (value: string) => void;
19
- }
20
- export declare enum SessionStorageKey {
21
- CONFIG = "config",
22
- OAUTH_STATE = "oauth_state",
23
- OAUTH_CODE_VERIFIER = "code_verifier",
24
- OAUTH_CODE_CHALLENGE = "code_challenge",
25
- HAS_AUTHENTICATED = "has_authenticated",
26
- CALLBACK_URL = "callback_url"
27
- }
28
- export declare const getSessionStorageProvider: () => SessionStorageProvider;
29
- export declare const getConfig: () => ConfigType;
1
+ import { ConfigType } from '@opengeoweb/shared';
2
+ export interface SessionStorageProvider {
3
+ setConfig: (value: ConfigType) => void;
4
+ getConfig: () => ConfigType;
5
+ setOauthState: (value: string) => void;
6
+ getOauthState: () => string;
7
+ removeOauthState: () => void;
8
+ setOauthCodeVerifier: (value: string) => void;
9
+ getOauthCodeVerifier: () => string;
10
+ removeOauthCodeVerifier: () => void;
11
+ setOauthCodeChallenge: (value: string) => void;
12
+ getOauthCodeChallenge: () => string;
13
+ removeOauthCodeChallenge: () => void;
14
+ setHasAuthenticated: (value: string) => void;
15
+ getHasAuthenticated: () => string;
16
+ removeHasAuthenticated: () => void;
17
+ getCallbackUrl: () => string;
18
+ setCallbackUrl: (value: string) => void;
19
+ }
20
+ export declare enum SessionStorageKey {
21
+ CONFIG = "config",
22
+ OAUTH_STATE = "oauth_state",
23
+ OAUTH_CODE_VERIFIER = "code_verifier",
24
+ OAUTH_CODE_CHALLENGE = "code_challenge",
25
+ HAS_AUTHENTICATED = "has_authenticated",
26
+ CALLBACK_URL = "callback_url"
27
+ }
28
+ export declare const getSessionStorageProvider: () => SessionStorageProvider;
29
+ export declare const getConfig: () => ConfigType;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- export declare const getCurrentUrlLocation: (url: string, appUrl: string) => string;
1
+ export declare const getCurrentUrlLocation: (url: string, appUrl: string) => string;
@@ -1 +1 @@
1
- export {};
1
+ export {};