@gridsuite/commons-ui 0.22.0 → 0.22.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.
@@ -87,7 +87,8 @@ var useStyles = (0, _makeStyles["default"])(function (theme) {
87
87
  return {
88
88
  grow: {
89
89
  flexGrow: 1,
90
- display: 'flex'
90
+ display: 'flex',
91
+ overflow: 'hidden'
91
92
  },
92
93
  logo: {
93
94
  flexShrink: 0,
@@ -41,6 +41,8 @@ function initializeAuthenticationDev(dispatch, isSilentRenew) {
41
41
  return Promise.resolve(userManager);
42
42
  }
43
43
 
44
+ var accessTokenExpiringNotificationTime = 60; // seconds
45
+
44
46
  function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings) {
45
47
  return idpSettings.then(function (r) {
46
48
  return r.json();
@@ -109,9 +111,10 @@ function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings) {
109
111
  response_type: 'id_token token',
110
112
  scope: idpSettings.scope,
111
113
  automaticSilentRenew: !isSilentRenew,
112
- accessTokenExpiringNotificationTime: 60
114
+ accessTokenExpiringNotificationTime: accessTokenExpiringNotificationTime
113
115
  };
114
116
  var userManager = new _oidcClient.UserManager(settings);
117
+ userManager.idpSettings = idpSettings; //store our settings in there as well to use it later
115
118
 
116
119
  if (!isSilentRenew) {
117
120
  handleUser(dispatch, userManager);
@@ -177,8 +180,40 @@ function handleUser(dispatch, userManager) {
177
180
  dispatchUser(dispatch, userManager);
178
181
  });
179
182
  userManager.events.addSilentRenewError(function (error) {
180
- console.debug(error);
181
- logout(dispatch, userManager);
183
+ console.debug(error); // wait for accessTokenExpiringNotificationTime so that the user is expired
184
+ // otherwise the library tries to signin immediately when we do getUser()
185
+
186
+ window.setTimeout(function () {
187
+ userManager.getUser().then(function (user) {
188
+ var now = parseInt(Date.now() / 1000);
189
+ var exp = (0, _jwtDecode["default"])(user.id_token).exp;
190
+ var idTokenExpiresIn = exp - now;
191
+
192
+ if (idTokenExpiresIn < 0) {
193
+ console.log('Error in silent renew, idtoken expired: ' + idTokenExpiresIn + ' => Logging out.', error); // TODO here allow to continue to use the app but in some kind of frozen state because we can't make API calls anymore
194
+
195
+ return logout(dispatch, userManager);
196
+ } else if (userManager.idpSettings.maxExpiresIn) {
197
+ if (idTokenExpiresIn < userManager.idpSettings.maxExpiresIn) {
198
+ // TODO here attempt last chance login ? snackbar to notify the user ? Popup ?
199
+ // for now we do the same thing as in the else block
200
+ console.log('Error in silent renew, but idtoken ALMOST expiring (expiring in' + idTokenExpiresIn + ') => last chance' + userManager.idpSettings.maxExpiresIn, error);
201
+ user.expires_in = userManager.idpSettings.maxExpiresIn;
202
+ userManager.storeUser(user).then(function () {
203
+ userManager.getUser();
204
+ });
205
+ } else {
206
+ console.log('Error in silent renew, but idtoken NOT expiring (expiring in' + idTokenExpiresIn + ') => postponing expiration to' + userManager.idpSettings.maxExpiresIn, error);
207
+ user.expires_in = userManager.idpSettings.maxExpiresIn;
208
+ userManager.storeUser(user).then(function () {
209
+ userManager.getUser();
210
+ });
211
+ }
212
+ } else {
213
+ console.log('Error in silent renew, unsupported configuration: token still valid for ' + idTokenExpiresIn + ' but maxExpiresIn is not configured:' + userManager.idpSettings.maxExpiresIn, error);
214
+ }
215
+ });
216
+ }, accessTokenExpiringNotificationTime * 1000);
182
217
  });
183
218
  console.debug('dispatch user');
184
219
  dispatchUser(dispatch, userManager);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "engines": {
6
6
  "npm": "<=6",