@gridsuite/commons-ui 0.100.0 → 0.101.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.
@@ -1,8 +1,7 @@
1
1
  import { Dispatch } from 'react';
2
2
  import { Location, NavigateFunction } from 'react-router';
3
- import { Log, User, UserManager } from 'oidc-client';
3
+ import { Log, UserManager } from 'oidc-client';
4
4
  import { AuthenticationActions } from '../../../redux/actions/authActions';
5
- type UserValidationFunc = (user: User) => Promise<boolean>;
6
5
  type IdpSettingsGetter = () => Promise<IdpSettings>;
7
6
  export type IdpSettings = {
8
7
  authority: string;
@@ -25,10 +24,10 @@ declare global {
25
24
  }
26
25
  export declare function login(location: Location, userManagerInstance: UserManager | null): Promise<void> | undefined;
27
26
  export declare function logout(dispatch: Dispatch<AuthenticationActions>, userManagerInstance: UserManager | null): Promise<void> | undefined;
28
- export declare function dispatchUser(dispatch: Dispatch<AuthenticationActions>, userManagerInstance: CustomUserManager, validateUser: UserValidationFunc): Promise<void>;
27
+ export declare function dispatchUser(dispatch: Dispatch<AuthenticationActions>, userManagerInstance: CustomUserManager): Promise<void>;
29
28
  export declare function getPreLoginPath(): string | null;
30
29
  export declare function handleSigninCallback(dispatch: Dispatch<AuthenticationActions>, navigate: NavigateFunction, userManagerInstance: UserManager): void;
31
30
  export declare function handleSilentRenewCallback(userManagerInstance: UserManager): void;
32
- export declare function initializeAuthenticationDev(dispatch: Dispatch<AuthenticationActions>, isSilentRenew: boolean, validateUser: UserValidationFunc, isSigninCallback: boolean): Promise<UserManager>;
33
- export declare function initializeAuthenticationProd(dispatch: Dispatch<AuthenticationActions>, isSilentRenew: boolean, idpSettingsGetter: IdpSettingsGetter, validateUser: UserValidationFunc, isSigninCallback: boolean): Promise<CustomUserManager>;
31
+ export declare function initializeAuthenticationDev(dispatch: Dispatch<AuthenticationActions>, isSilentRenew: boolean, isSigninCallback: boolean): Promise<UserManager>;
32
+ export declare function initializeAuthenticationProd(dispatch: Dispatch<AuthenticationActions>, isSilentRenew: boolean, idpSettingsGetter: IdpSettingsGetter, isSigninCallback: boolean): Promise<CustomUserManager>;
34
33
  export {};
@@ -1,7 +1,7 @@
1
1
  import { jwtDecode } from "jwt-decode";
2
2
  import { Log, UserManager } from "oidc-client";
3
3
  import { UserManagerMock } from "./userManagerMock.js";
4
- import { setLoggedUser, setLogoutError, setUnauthorizedUserInfo, setUserValidationError, setSignInCallbackError, setShowAuthenticationRouterLogin, resetAuthenticationRouterError } from "../../../redux/actions/authActions.js";
4
+ import { setLoggedUser, setLogoutError, setSignInCallbackError, setShowAuthenticationRouterLogin, resetAuthenticationRouterError } from "../../../redux/actions/authActions.js";
5
5
  window.OIDCLog = Log;
6
6
  const hackAuthorityKey = "oidc.hack.authority";
7
7
  const oidcHackReloadedKey = "gridsuite-oidc-hack-reloaded";
@@ -104,40 +104,21 @@ function logout(dispatch, userManagerInstance) {
104
104
  return Promise.resolve();
105
105
  });
106
106
  }
107
- function dispatchUser(dispatch, userManagerInstance, validateUser) {
107
+ function dispatchUser(dispatch, userManagerInstance) {
108
108
  return userManagerInstance.getUser().then((user) => {
109
+ var _a;
109
110
  if (user) {
110
111
  if (getIdTokenExpiresIn(user) < 0) {
111
112
  console.debug("User token is expired and will not be dispatched");
112
113
  return Promise.resolve();
113
114
  }
114
- const validateUserPromise = (validateUser == null ? void 0 : validateUser(user)) || Promise.resolve(true);
115
- return validateUserPromise.then((valid) => {
116
- var _a, _b;
117
- if (!valid) {
118
- console.debug("User isn't authorized to log in and will not be dispatched");
119
- return dispatch(setUnauthorizedUserInfo((_a = user == null ? void 0 : user.profile) == null ? void 0 : _a.name, ""));
120
- }
121
- console.debug("User has been successfully loaded from store.");
122
- reloadTimerOnExpiresIn(
123
- user,
124
- userManagerInstance,
125
- computeMinExpiresIn(
126
- user.expires_in,
127
- user.id_token,
128
- (_b = userManagerInstance.idpSettings) == null ? void 0 : _b.maxExpiresIn
129
- )
130
- );
131
- return dispatch(setLoggedUser(user));
132
- }).catch((e) => {
133
- var _a;
134
- console.log("Error in dispatchUser", e);
135
- return dispatch(
136
- setUserValidationError((_a = user == null ? void 0 : user.profile) == null ? void 0 : _a.name, {
137
- error: e
138
- })
139
- );
140
- });
115
+ console.debug("User has been successfully loaded from store.");
116
+ reloadTimerOnExpiresIn(
117
+ user,
118
+ userManagerInstance,
119
+ computeMinExpiresIn(user.expires_in, user.id_token, (_a = userManagerInstance.idpSettings) == null ? void 0 : _a.maxExpiresIn)
120
+ );
121
+ return dispatch(setLoggedUser(user));
141
122
  }
142
123
  console.debug("You are not logged in.");
143
124
  return Promise.resolve();
@@ -175,10 +156,10 @@ function handleSigninCallback(dispatch, navigate, userManagerInstance) {
175
156
  function handleSilentRenewCallback(userManagerInstance) {
176
157
  userManagerInstance.signinSilentCallback();
177
158
  }
178
- function handleUser(dispatch, userManager, validateUser) {
159
+ function handleUser(dispatch, userManager) {
179
160
  userManager.events.addUserLoaded((user) => {
180
161
  console.debug("user loaded", user);
181
- dispatchUser(dispatch, userManager, validateUser);
162
+ dispatchUser(dispatch, userManager);
182
163
  });
183
164
  userManager.events.addSilentRenewError((error) => {
184
165
  console.debug(error);
@@ -223,19 +204,19 @@ function handleUser(dispatch, userManager, validateUser) {
223
204
  }, accessTokenExpiringNotificationTime * 1e3);
224
205
  });
225
206
  console.debug("dispatch user");
226
- dispatchUser(dispatch, userManager, validateUser);
207
+ dispatchUser(dispatch, userManager);
227
208
  }
228
- async function initializeAuthenticationDev(dispatch, isSilentRenew, validateUser, isSigninCallback) {
209
+ async function initializeAuthenticationDev(dispatch, isSilentRenew, isSigninCallback) {
229
210
  const userManager = new UserManagerMock({});
230
211
  if (!isSilentRenew) {
231
- handleUser(dispatch, userManager, validateUser);
212
+ handleUser(dispatch, userManager);
232
213
  if (!isSigninCallback) {
233
214
  handleSigninSilent(dispatch, userManager);
234
215
  }
235
216
  }
236
217
  return userManager;
237
218
  }
238
- async function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettingsGetter, validateUser, isSigninCallback) {
219
+ async function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettingsGetter, isSigninCallback) {
239
220
  const idpSettings = await idpSettingsGetter();
240
221
  try {
241
222
  const settings = {
@@ -252,7 +233,7 @@ async function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings
252
233
  const userManager = new UserManager(settings);
253
234
  userManager.idpSettings = idpSettings;
254
235
  if (!isSilentRenew) {
255
- handleUser(dispatch, userManager, validateUser);
236
+ handleUser(dispatch, userManager);
256
237
  if (!isSigninCallback) {
257
238
  handleSigninSilent(dispatch, userManager);
258
239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.100.0",
3
+ "version": "0.101.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",