@eui/base 14.0.26 → 14.0.27
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.
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
SESSION_STORAGE_KEY_IMPERSONATED_USER_ID: "ux-openid-connect-impersonated-user-id",
|
|
21
21
|
SESSION_STORAGE_KEY_DEVELOPMENT_URL: "ux-openid-connect-dev-url",
|
|
22
22
|
SESSION_STORAGE_KEY_ORIGINAL_URL: "ux-openid-connect-original-url",
|
|
23
|
+
SESSION_STORAGE_KEY_TRACK_USERNAME: "ux-openid-connect-track-username",
|
|
24
|
+
SESSION_STORAGE_KEY_TRACK_LOGIN: "ux-openid-connect-track-login",
|
|
23
25
|
SESSION_STORAGE_KEY_PUBLIC_KEY: "ux-openid-connect-public-key",
|
|
24
26
|
SESSION_STORAGE_KEY_PRIVATE_KEY: "ux-openid-connect-private-key",
|
|
25
27
|
SESSION_STORAGE_KEY_LOGIN_TIMESTAMP: "ux-openid-connect-login-timestamp",
|
|
@@ -32,8 +34,10 @@
|
|
|
32
34
|
DEFAULT_ACCESS_TOKEN_SIGNING_ALGORITHM: "ES256",
|
|
33
35
|
|
|
34
36
|
config: null,
|
|
37
|
+
configInitialised: false,
|
|
35
38
|
metadata: null,
|
|
36
39
|
waitForClientQueue: [],
|
|
40
|
+
waitForConfigQueue: [],
|
|
37
41
|
waitForIdTokenQueue: [],
|
|
38
42
|
waitForApiGatewayAccessTokenQueue: [],
|
|
39
43
|
loginWasRequested: false,
|
|
@@ -42,6 +46,7 @@
|
|
|
42
46
|
requestingApiGatewayAccessToken: false,
|
|
43
47
|
wasLoggedIn: false,
|
|
44
48
|
client: null,
|
|
49
|
+
usedEuLoginAccessTokens: {},
|
|
45
50
|
|
|
46
51
|
// --------------- Login with EU Login ---------------
|
|
47
52
|
loadConfiguration: function (callbackFunction) {
|
|
@@ -164,12 +169,20 @@
|
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
var continuePendingRequests = function () {
|
|
173
|
+
var queue = OpenIdConnect.waitForIdTokenQueue;
|
|
174
|
+
OpenIdConnect.wasLoggedIn = true;
|
|
175
|
+
while (queue.length > 0) {
|
|
176
|
+
// Extra timeout to prevent endless loop in case of accidental recursion due to still not being authorized because of an unknown issue:
|
|
177
|
+
setTimeout(queue.pop(), 0);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// We may have the ID token already being processed, while the configuration is still loading:
|
|
182
|
+
if (OpenIdConnect.configInitialised) {
|
|
183
|
+
continuePendingRequests();
|
|
184
|
+
} else {
|
|
185
|
+
OpenIdConnect.waitForConfigQueue.push(continuePendingRequests);
|
|
173
186
|
}
|
|
174
187
|
});
|
|
175
188
|
} else {
|
|
@@ -180,8 +193,8 @@
|
|
|
180
193
|
|
|
181
194
|
getAuthorizationHeaders: function (url, callbackFunction, errorCallbackFunction) { // calls the callback function with an object containing all the headers necessary to authenticate the request
|
|
182
195
|
if (url != null && (typeof callbackFunction) == "function") {
|
|
183
|
-
if (OpenIdConnect.
|
|
184
|
-
if (OpenIdConnect.config.enabled) {
|
|
196
|
+
if (OpenIdConnect.configInitialised) {
|
|
197
|
+
if (OpenIdConnect.config != null && OpenIdConnect.config.enabled) {
|
|
185
198
|
if (sessionStorage.getItem(OpenIdConnect.SESSION_STORAGE_KEY_ID_TOKEN) != null) {
|
|
186
199
|
if (OpenIdConnect.config.apiGatewayServices) {
|
|
187
200
|
var service = OpenIdConnect.getMatchingServiceFromConfiguration(url, OpenIdConnect.config.apiGatewayServices);
|
|
@@ -285,6 +298,17 @@
|
|
|
285
298
|
var euLoginTokenService = null;
|
|
286
299
|
var getApiGatewayAccessToken = function () {
|
|
287
300
|
if (euLoginTokenApiGateway != null && (euLoginTokenService != null || audienceId == null)) {
|
|
301
|
+
// Prevent the same EU Login access token from being used:
|
|
302
|
+
if (euLoginTokenApiGateway != null && OpenIdConnect.usedEuLoginAccessTokens [euLoginTokenApiGateway.access_token]) {
|
|
303
|
+
// Due to unexpected racing conditions, the same EU Login access token is being used to request the API Gateway token.
|
|
304
|
+
// Simply retry:
|
|
305
|
+
OpenIdConnect.requestingApiGatewayAccessToken = false;
|
|
306
|
+
setTimeout(function () {
|
|
307
|
+
OpenIdConnect.getApiGatewayAuthorizationHeaders(audienceId, callbackFunction, errorCallbackFunction, authenticatedByGateway);
|
|
308
|
+
}, 0);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
288
312
|
var impersonatedUserId = OpenIdConnect.getImpersonatedUserId();
|
|
289
313
|
if (impersonatedUserId == null) {
|
|
290
314
|
// We now have an EU Login access token for the API Gateway and the target service.
|
|
@@ -298,6 +322,17 @@
|
|
|
298
322
|
// and by propagating the EU Login access token for the target service...
|
|
299
323
|
var apiGatewayAccessToken = OpenIdConnect.parseSafely(xhr, errorCallbackFunction);
|
|
300
324
|
OpenIdConnect.storeCachedApiGatewayAccessToken(apiGatewayAccessToken);
|
|
325
|
+
|
|
326
|
+
// Prevent the same EU Login access token from being used:
|
|
327
|
+
if (euLoginTokenService != null && OpenIdConnect.usedEuLoginAccessTokens [euLoginTokenService.access_token]) {
|
|
328
|
+
// Due to unexpected racing conditions, the same EU Login access token is being used to request the API Gateway token.
|
|
329
|
+
// Simply retry:
|
|
330
|
+
OpenIdConnect.requestingApiGatewayAccessToken = false;
|
|
331
|
+
setTimeout(function () {
|
|
332
|
+
OpenIdConnect.getApiGatewayAuthorizationHeaders(audienceId, callbackFunction, errorCallbackFunction, authenticatedByGateway);
|
|
333
|
+
}, 0);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
301
336
|
OpenIdConnect.returnApiGatewayAuthorizationHeaders(apiGatewayAccessToken, euLoginTokenService, callbackFunction, authenticatedByGateway);
|
|
302
337
|
} else if (xhr.status >= 400) {
|
|
303
338
|
OpenIdConnect.handleErrorResponse(xhr, errorCallbackFunction);
|
|
@@ -313,6 +348,9 @@
|
|
|
313
348
|
"eul_access_token=" + OpenIdConnect.signAccessToken(euLoginTokenApiGateway.access_token) + "&"+
|
|
314
349
|
"consumer_key=" + encodeURIComponent(OpenIdConnect.config.apiGatewayConsumerKey)
|
|
315
350
|
);
|
|
351
|
+
if (euLoginTokenApiGateway != null) {
|
|
352
|
+
OpenIdConnect.usedEuLoginAccessTokens [euLoginTokenApiGateway.access_token] = true;
|
|
353
|
+
}
|
|
316
354
|
} else {
|
|
317
355
|
// Re-impersonate:
|
|
318
356
|
OpenIdConnect.impersonate(impersonatedUserId, function () {
|
|
@@ -338,11 +376,21 @@
|
|
|
338
376
|
// We already have an API Gateway access token.
|
|
339
377
|
// Now request an EU Login access token for the target service.
|
|
340
378
|
if (audienceId != null && audienceId != "") {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
379
|
+
var gatherHeaders = function () {
|
|
380
|
+
OpenIdConnect.doServiceAccessTokenRequest(audienceId, function (newEuLoginToken) {
|
|
381
|
+
// Prevent the same EU Login access token from being used:
|
|
382
|
+
if (newEuLoginToken != null && OpenIdConnect.usedEuLoginAccessTokens [newEuLoginToken.access_token]) {
|
|
383
|
+
// Due to unexpected racing conditions, the same EU Login access token is being used to request the API Gateway token.
|
|
384
|
+
// Simply retry:
|
|
385
|
+
return gatherHeaders();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// We have now both the API Gateway access token and a EU Login access token for the target service;
|
|
389
|
+
// we can call the API Gateway.
|
|
390
|
+
OpenIdConnect.returnApiGatewayAuthorizationHeaders(OpenIdConnect.getCachedApiGatewayAccessToken(), newEuLoginToken, callbackFunction, authenticatedByGateway);
|
|
391
|
+
}, errorCallbackFunction);
|
|
392
|
+
};
|
|
393
|
+
gatherHeaders();
|
|
346
394
|
} else {
|
|
347
395
|
OpenIdConnect.returnApiGatewayAuthorizationHeaders(OpenIdConnect.getCachedApiGatewayAccessToken(), null, callbackFunction, authenticatedByGateway);
|
|
348
396
|
}
|
|
@@ -511,6 +559,7 @@
|
|
|
511
559
|
|
|
512
560
|
if (serviceAccessToken != null && serviceAccessToken.access_token != null) {
|
|
513
561
|
headers ["Authorization-Propagation"] = OpenIdConnect.signAccessToken(serviceAccessToken.access_token);
|
|
562
|
+
OpenIdConnect.usedEuLoginAccessTokens [serviceAccessToken.access_token] = true;
|
|
514
563
|
}
|
|
515
564
|
OpenIdConnect.addImpersonationHeaders(headers);
|
|
516
565
|
|
|
@@ -739,6 +788,20 @@
|
|
|
739
788
|
}
|
|
740
789
|
},
|
|
741
790
|
|
|
791
|
+
continuePendingUserTracking: function () {
|
|
792
|
+
var fullName = sessionStorage.getItem(OpenIdConnect.SESSION_STORAGE_KEY_TRACK_USERNAME);
|
|
793
|
+
if (fullName != null && (typeof dtrum) != "undefined" && (typeof dtrum.identifyUser) == "function") {
|
|
794
|
+
dtrum.identifyUser(fullName);
|
|
795
|
+
}
|
|
796
|
+
sessionStorage.removeItem(OpenIdConnect.SESSION_STORAGE_KEY_TRACK_USERNAME);
|
|
797
|
+
|
|
798
|
+
var loginAction = sessionStorage.getItem(OpenIdConnect.SESSION_STORAGE_KEY_TRACK_LOGIN);
|
|
799
|
+
if (loginAction != null && (typeof dtrum) != "undefined" && (typeof dtrum.leaveAction) == "function" && (typeof dtrum.sendBeacon) == "function") {
|
|
800
|
+
dtrum.leaveAction(loginAction);
|
|
801
|
+
dtrum.sendBeacon(true, true, true);
|
|
802
|
+
sessionStorage.removeItem(OpenIdConnect.SESSION_STORAGE_KEY_TRACK_LOGIN);
|
|
803
|
+
}
|
|
804
|
+
},
|
|
742
805
|
|
|
743
806
|
|
|
744
807
|
// --------------- Utility functions ---------------
|
|
@@ -860,6 +923,7 @@
|
|
|
860
923
|
sessionStorage.removeItem(OpenIdConnect.SESSION_STORAGE_KEY_ID_TOKEN);
|
|
861
924
|
// Also invalidate the API Gateway token because it can be used for authentication too:
|
|
862
925
|
OpenIdConnect.clearCachedApiGatewayAccessToken();
|
|
926
|
+
OpenIdConnect.trackUserLogin();
|
|
863
927
|
|
|
864
928
|
var redirectUrl = OpenIdConnect.config.spaRedirectUrl;
|
|
865
929
|
// Also allow the redirect URL to go to localhost in case of mock OpenIDConnect servers:
|
|
@@ -892,6 +956,12 @@
|
|
|
892
956
|
}
|
|
893
957
|
}
|
|
894
958
|
|
|
959
|
+
// Check for functional test account logins:
|
|
960
|
+
var parameters = new URLSearchParams(window.top.location.search);
|
|
961
|
+
if (parameters != null && parameters.get("1fa") != null) {
|
|
962
|
+
extraQueryParams ["acr_values"] = "https://ecas.ec.europa.eu/loa/basic";
|
|
963
|
+
}
|
|
964
|
+
|
|
895
965
|
if (! OpenIdConnect.requestingLogin) {
|
|
896
966
|
OpenIdConnect.requestingLogin = true;
|
|
897
967
|
OpenIdConnect.client.createSigninRequest({redirect_uri: redirectUrl, extraQueryParams: extraQueryParams}).then(function (req) {
|
|
@@ -975,6 +1045,7 @@
|
|
|
975
1045
|
firstName: tokenObject.given_name,
|
|
976
1046
|
lastName: tokenObject.family_name
|
|
977
1047
|
}));
|
|
1048
|
+
OpenIdConnect.trackUserName(tokenObject);
|
|
978
1049
|
} else {
|
|
979
1050
|
console.error("Not accepting ID token; incorrect audience (SPA) detected.");
|
|
980
1051
|
}
|
|
@@ -1154,6 +1225,14 @@
|
|
|
1154
1225
|
}
|
|
1155
1226
|
},
|
|
1156
1227
|
|
|
1228
|
+
continuePendingConfigRequests: function () {
|
|
1229
|
+
var queue = OpenIdConnect.waitForConfigQueue;
|
|
1230
|
+
while (queue.length > 0) {
|
|
1231
|
+
// Extra timeout to prevent endless loop in case of accidental recursion due to still not being authorized because of an unknown issue:
|
|
1232
|
+
setTimeout(queue.pop(), 0);
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
|
|
1157
1236
|
makeSessionApplicationSpecific: function () {
|
|
1158
1237
|
// Sometimes multiple applications are deployed on the same domain.
|
|
1159
1238
|
// Make the session application-specific:
|
|
@@ -1169,6 +1248,35 @@
|
|
|
1169
1248
|
OpenIdConnect.SESSION_STORAGE_KEY_PRIVATE_KEY += applicationSuffix;
|
|
1170
1249
|
OpenIdConnect.SESSION_STORAGE_KEY_LOGIN_TIMESTAMP += applicationSuffix;
|
|
1171
1250
|
}
|
|
1251
|
+
},
|
|
1252
|
+
|
|
1253
|
+
trackUserLogin: function () {
|
|
1254
|
+
if ((typeof dtrum) != "undefined" && (typeof dtrum.actionName) == "function" && (typeof dtrum.enterAction) == "function" && (typeof dtrum.sendBeacon) == "function") {
|
|
1255
|
+
sessionStorage.setItem(OpenIdConnect.SESSION_STORAGE_KEY_TRACK_LOGIN, dtrum.enterAction("EU Login (old client)"));
|
|
1256
|
+
dtrum.actionName("EU Login (old client)");
|
|
1257
|
+
dtrum.sendBeacon(true, true, true);
|
|
1258
|
+
}
|
|
1259
|
+
},
|
|
1260
|
+
|
|
1261
|
+
trackUserName: function (tokenObject) {
|
|
1262
|
+
if (tokenObject != null) {
|
|
1263
|
+
var firstName = tokenObject.given_name;
|
|
1264
|
+
if (firstName == "UNKNOWN") {
|
|
1265
|
+
firstName = tokenObject.sub;
|
|
1266
|
+
}
|
|
1267
|
+
var lastName = tokenObject.family_name;
|
|
1268
|
+
if (lastName == "UNKNOWN") {
|
|
1269
|
+
lastName = "Generic User";
|
|
1270
|
+
}
|
|
1271
|
+
var fullName = lastName + " " + firstName;
|
|
1272
|
+
|
|
1273
|
+
if ((typeof dtrum) != "undefined" && (typeof dtrum.identifyUser) == "function") {
|
|
1274
|
+
dtrum.identifyUser(fullName);
|
|
1275
|
+
} else {
|
|
1276
|
+
// The username will be picked up after restoring the original URL:
|
|
1277
|
+
sessionStorage.setItem(OpenIdConnect.SESSION_STORAGE_KEY_TRACK_USERNAME, fullName);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1172
1280
|
}
|
|
1173
1281
|
};
|
|
1174
1282
|
|
|
@@ -1180,11 +1288,16 @@
|
|
|
1180
1288
|
if (OpenIdConnect.config != null && OpenIdConnect.config.enabled) {
|
|
1181
1289
|
OpenIdConnect.makeSessionApplicationSpecific();
|
|
1182
1290
|
OpenIdConnect.initializeKeypair();
|
|
1291
|
+
OpenIdConnect.configInitialised = true;
|
|
1292
|
+
OpenIdConnect.continuePendingConfigRequests();
|
|
1183
1293
|
if (OpenIdConnect.config.autoLogin == null || OpenIdConnect.config.autoLogin) {
|
|
1184
1294
|
OpenIdConnect.loginWithOpenIDConnect();
|
|
1185
1295
|
} else {
|
|
1186
1296
|
OpenIdConnect.loginWithOpenIDConnect(true);
|
|
1187
1297
|
}
|
|
1298
|
+
} else {
|
|
1299
|
+
OpenIdConnect.configInitialised = true;
|
|
1300
|
+
OpenIdConnect.continuePendingConfigRequests();
|
|
1188
1301
|
}
|
|
1189
1302
|
});
|
|
1190
1303
|
} catch (error) {
|