@gridsuite/commons-ui 0.20.2 → 0.20.5
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/lib/utils/AuthService.js
CHANGED
|
@@ -26,6 +26,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
26
26
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
27
27
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
28
28
|
*/
|
|
29
|
+
// set as a global variable to allow log level configuration at runtime
|
|
30
|
+
window.OIDCLog = _oidcClient.Log;
|
|
29
31
|
var hackauthoritykey = 'oidc.hack.authority';
|
|
30
32
|
var pathKey = 'powsybl-gridsuite-current-path';
|
|
31
33
|
|
|
@@ -46,6 +48,7 @@ function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings) {
|
|
|
46
48
|
/* hack to ignore the iss check. XXX TODO to remove */
|
|
47
49
|
var regextoken = /id_token=[^&]*/;
|
|
48
50
|
var regexstate = /state=[^&]*/;
|
|
51
|
+
var regexexpires = /expires_in=[^&]*/;
|
|
49
52
|
var authority;
|
|
50
53
|
|
|
51
54
|
if (window.location.hash) {
|
|
@@ -58,11 +61,26 @@ function initializeAuthenticationProd(dispatch, isSilentRenew, idpSettings) {
|
|
|
58
61
|
var strState = localStorage.getItem('oidc.' + state);
|
|
59
62
|
|
|
60
63
|
if (strState != null) {
|
|
61
|
-
|
|
64
|
+
var decoded = (0, _jwtDecode["default"])(id_token);
|
|
65
|
+
authority = decoded.iss;
|
|
62
66
|
var storedState = JSON.parse(strState);
|
|
67
|
+
console.debug('Replacing authority in storedState. Before: ', storedState.authority, 'after: ', authority);
|
|
63
68
|
storedState.authority = authority;
|
|
64
69
|
localStorage.setItem('oidc.' + state, JSON.stringify(storedState));
|
|
65
70
|
sessionStorage.setItem(hackauthoritykey, authority);
|
|
71
|
+
var matched_expires = window.location.hash.match(regexexpires);
|
|
72
|
+
|
|
73
|
+
if (matched_expires != null) {
|
|
74
|
+
var expires_in = parseInt(matched_expires[0].split('=')[1]);
|
|
75
|
+
var now = parseInt(Date.now() / 1000);
|
|
76
|
+
var exp = decoded.exp;
|
|
77
|
+
|
|
78
|
+
if (exp < now + expires_in) {
|
|
79
|
+
var newhash = window.location.hash.replace(matched_expires[0], 'expires_in=' + (exp - now));
|
|
80
|
+
console.debug('Replacing expires_in in window.location.hash because idtoken.exp is earlier. Before: ', window.location.hash, 'after: ', newhash);
|
|
81
|
+
window.location.hash = newhash;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
66
84
|
}
|
|
67
85
|
}
|
|
68
86
|
}
|