@opengeoweb/authentication 9.27.0 → 9.27.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
CHANGED
|
@@ -6855,9 +6855,8 @@ $({ global: true, bind: true, enumerable: true, forced: FORCED }, {
|
|
|
6855
6855
|
|
|
6856
6856
|
const API_NAMESPACE$1 = 'api';
|
|
6857
6857
|
const DEFAULT_TIMEOUT = 15000;
|
|
6858
|
-
const
|
|
6859
|
-
const
|
|
6860
|
-
const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75; // Refresh token when 75% expired. Set to (10 / 3600) * 100 = 0.2777778% to test with 10 second interval.
|
|
6858
|
+
const KEEP_ALIVE_POLLER_IN_SECONDS = 60; // Number of seconds between the checks if the token should be refreshed.
|
|
6859
|
+
const 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).
|
|
6861
6860
|
const DEFAULT_TOKEN_EXPIRES_IN = 3600; // Number of seconds a token expires by default
|
|
6862
6861
|
const MILLISECOND_TO_SECOND = 1 / 1000;
|
|
6863
6862
|
const ns$1 = API_NAMESPACE$1;
|
|
@@ -6910,7 +6909,6 @@ const makeCredentialsFromTokenResponse = (tokenResponse, authConfig) => {
|
|
|
6910
6909
|
token: access_token,
|
|
6911
6910
|
refresh_token: refresh_token || '',
|
|
6912
6911
|
expires_at: epochTimeTokenExpirationInSeconds,
|
|
6913
|
-
keep_session_alive_at: getCurrentTimeInSeconds() + KEEP_ALIVE_IN_SECONDS,
|
|
6914
6912
|
has_connection_issue: false
|
|
6915
6913
|
};
|
|
6916
6914
|
return newAuth;
|
|
@@ -6978,12 +6976,8 @@ const refreshAccessTokenAndSetAuthContext = ({
|
|
|
6978
6976
|
});
|
|
6979
6977
|
const createApiInstance = ({
|
|
6980
6978
|
auth,
|
|
6981
|
-
onSetAuth,
|
|
6982
6979
|
config: {
|
|
6983
|
-
baseURL
|
|
6984
|
-
authTokenURL,
|
|
6985
|
-
authClientId,
|
|
6986
|
-
appURL
|
|
6980
|
+
baseURL
|
|
6987
6981
|
} = {},
|
|
6988
6982
|
timeout: _timeout3 = DEFAULT_TIMEOUT
|
|
6989
6983
|
}) => {
|
|
@@ -6994,20 +6988,7 @@ const createApiInstance = ({
|
|
|
6994
6988
|
});
|
|
6995
6989
|
// Request interceptor for API calls done BEFORE the request is made.
|
|
6996
6990
|
axiosInstance.interceptors.request.use(axiosConfig => __awaiter(void 0, void 0, void 0, function* () {
|
|
6997
|
-
|
|
6998
|
-
if (timeInSecondsLeftBeforeExpiration < 0) {
|
|
6999
|
-
yield refreshAccessTokenAndSetAuthContext({
|
|
7000
|
-
auth,
|
|
7001
|
-
onSetAuth,
|
|
7002
|
-
config: {
|
|
7003
|
-
baseURL,
|
|
7004
|
-
authTokenURL,
|
|
7005
|
-
authClientId,
|
|
7006
|
-
appURL
|
|
7007
|
-
},
|
|
7008
|
-
timeout: _timeout3
|
|
7009
|
-
});
|
|
7010
|
-
}
|
|
6991
|
+
// Add the access token to the headers of the request.
|
|
7011
6992
|
const newConfig = Object.assign(Object.assign({}, axiosConfig), {
|
|
7012
6993
|
headers: Object.assign({
|
|
7013
6994
|
'Content-Type': 'application/json',
|
|
@@ -7023,20 +7004,10 @@ const createApiInstance = ({
|
|
|
7023
7004
|
axiosInstance.interceptors.response.use(response => response, error => __awaiter(void 0, void 0, void 0, function* () {
|
|
7024
7005
|
var _a;
|
|
7025
7006
|
const originalRequest = error.config;
|
|
7007
|
+
// If request fails with 401, retry the request once.
|
|
7026
7008
|
if (error.response && error.response.status && error.response.status === 401 && !originalRequest.inRetry) {
|
|
7027
7009
|
originalRequest.inRetry = true;
|
|
7028
|
-
|
|
7029
|
-
auth,
|
|
7030
|
-
onSetAuth,
|
|
7031
|
-
config: {
|
|
7032
|
-
baseURL,
|
|
7033
|
-
authTokenURL,
|
|
7034
|
-
authClientId,
|
|
7035
|
-
appURL
|
|
7036
|
-
},
|
|
7037
|
-
timeout: _timeout3
|
|
7038
|
-
});
|
|
7039
|
-
// Update the headers of the original request with the refreshed access token
|
|
7010
|
+
// Update the headers of the original request with the token from the current auth context.
|
|
7040
7011
|
if ((_a = originalRequest.headers) === null || _a === void 0 ? void 0 : _a.Authorization) {
|
|
7041
7012
|
originalRequest.headers.Authorization = `Bearer ${auth === null || auth === void 0 ? void 0 : auth.token}`;
|
|
7042
7013
|
}
|
|
@@ -7175,7 +7146,6 @@ const useAuthenticationDefaultProps = () => {
|
|
|
7175
7146
|
token: '',
|
|
7176
7147
|
refresh_token: '',
|
|
7177
7148
|
expires_at: 0,
|
|
7178
|
-
keep_session_alive_at: 0,
|
|
7179
7149
|
has_connection_issue: false
|
|
7180
7150
|
};
|
|
7181
7151
|
const auth = React__default.useRef(Object.assign({}, emptyCredentials)).current;
|
|
@@ -7221,12 +7191,14 @@ const AuthenticationProvider = ({
|
|
|
7221
7191
|
setCurrentRole
|
|
7222
7192
|
} = value || defaultValues;
|
|
7223
7193
|
const authConfig = _configURLS;
|
|
7194
|
+
// Checks the token expiration time regularly and renews it before it expires.
|
|
7224
7195
|
const interval = useRef();
|
|
7225
7196
|
React__default.useEffect(() => {
|
|
7226
7197
|
interval.current = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
7227
7198
|
if (auth) {
|
|
7228
7199
|
const currentTime = getCurrentTimeInSeconds();
|
|
7229
|
-
|
|
7200
|
+
const timeInSecondsLeftBeforeExpiration = auth.expires_at ? auth.expires_at - currentTime : 0;
|
|
7201
|
+
if (timeInSecondsLeftBeforeExpiration < 0) {
|
|
7230
7202
|
yield refreshAccessTokenAndSetAuthContext({
|
|
7231
7203
|
auth,
|
|
7232
7204
|
onSetAuth,
|
|
@@ -7669,4 +7641,4 @@ const useApi = (apiCall, params, callbacks) => {
|
|
|
7669
7641
|
};
|
|
7670
7642
|
};
|
|
7671
7643
|
|
|
7672
|
-
export { AUTH_NAMESPACE, ApiProvider, AuthenticationContext, AuthenticationProvider, HandleOAuth2Code as Code, GEOWEB_ROLE_PRESETS_ADMIN, GEOWEB_ROLE_USER,
|
|
7644
|
+
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, RequireAuth, SessionStorageKey, UserMenuRoles, UserMenuRolesConnect, apiTranslations, authTranslations, createApiInstance, createFakeApiInstance, createNonAuthApiInstance, fakeApiRequest, getApi, getAuthConfig, getCodeChallenge, getConfig, getCurrentTimeInSeconds, getCurrentUrlLocation, getRandomString, getSessionStorageProvider, groupsToRoles, makeCredentialsFromTokenResponse, refreshAccessToken, refreshAccessTokenAndSetAuthContext, useApi, useApiContext, useAuthenticationContext, useAuthenticationDefaultProps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/authentication",
|
|
3
|
-
"version": "9.27.
|
|
3
|
+
"version": "9.27.1",
|
|
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.27.
|
|
17
|
+
"@opengeoweb/snackbar": "9.27.1",
|
|
18
18
|
"react-redux": "^8.1.3",
|
|
19
19
|
"@reduxjs/toolkit": "^1.9.7",
|
|
20
20
|
"@mui/material": "^5.16.0"
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
2
|
import { ConfigType } from '@opengeoweb/shared';
|
|
3
3
|
import { CreateApiProps, Credentials, Role } from './types';
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 10;
|
|
4
|
+
export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 60;
|
|
6
5
|
export declare const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75;
|
|
7
6
|
export declare const MILLISECOND_TO_SECOND: number;
|
|
8
7
|
export declare const GEOWEB_ROLE_PRESETS_ADMIN: Role;
|
|
@@ -20,7 +19,7 @@ export declare const refreshAccessToken: ({ auth, config: { authTokenURL, authCl
|
|
|
20
19
|
export declare const refreshAccessTokenAndSetAuthContext: ({ auth, onSetAuth, config, timeout, configURLS, }: CreateApiProps & {
|
|
21
20
|
configURLS?: ConfigType | undefined;
|
|
22
21
|
}) => Promise<void>;
|
|
23
|
-
export declare const createApiInstance: ({ auth,
|
|
22
|
+
export declare const createApiInstance: ({ auth, config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
|
|
24
23
|
export declare const createNonAuthApiInstance: ({ config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
|
|
25
24
|
export declare const fakeApiRequest: (signal?: AbortController) => Promise<void>;
|
|
26
25
|
export declare const createFakeApiInstance: () => AxiosInstance;
|