@cosmotech/core 1.18.2 → 1.19.1-beta.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.
- package/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs.js +28 -14
- package/dist/index.esm.js +28 -14
- package/package.json +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## **1.19.0** <sub><sup>2024-10-22 (07716f7...07716f7)</sup></sub>
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- add configuration option `rolesJwtClaim` in `AuthKeycloakRedirect` provider ([07716f7](https://github.com/Cosmo-Tech/webapp-component-core/commit/07716f7))
|
|
6
|
+
|
|
1
7
|
## **1.18.2** <sub><sup>2024-09-23 (e619d7e...e619d7e)</sup></sub>
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/dist/index.cjs.js
CHANGED
|
@@ -57370,13 +57370,15 @@ var acquireTokens = /*#__PURE__*/function () {
|
|
|
57370
57370
|
}();
|
|
57371
57371
|
var handleResponse = response => {
|
|
57372
57372
|
if (response != null) {
|
|
57373
|
+
var _account$idTokenClaim, _account$idTokenClaim2;
|
|
57373
57374
|
var account = response.account;
|
|
57374
57375
|
_updateTokensInStorage(response);
|
|
57375
57376
|
writeToStorage('authIdTokenPopup', response.idToken);
|
|
57376
57377
|
writeToStorage('authAuthenticated', 'true');
|
|
57377
57378
|
writeToStorage('authAccountId', account.homeAccountId);
|
|
57379
|
+
writeToStorage('authEmail', (_account$idTokenClaim = account.idTokenClaims) === null || _account$idTokenClaim === void 0 ? void 0 : _account$idTokenClaim.email);
|
|
57378
57380
|
authData.accountId = account.homeAccountId;
|
|
57379
|
-
authData.userEmail = account.
|
|
57381
|
+
authData.userEmail = (_account$idTokenClaim2 = account.idTokenClaims) === null || _account$idTokenClaim2 === void 0 ? void 0 : _account$idTokenClaim2.email;
|
|
57380
57382
|
authData.username = account.name;
|
|
57381
57383
|
authData.userId = account.localAccountId;
|
|
57382
57384
|
redirectOnAuthSuccess();
|
|
@@ -57402,6 +57404,7 @@ var signOut = () => {
|
|
|
57402
57404
|
clearFromStorage('authIdToken');
|
|
57403
57405
|
clearFromStorage('authAccessToken');
|
|
57404
57406
|
clearFromStorage('authAccountId');
|
|
57407
|
+
clearFromStorage('authEmail');
|
|
57405
57408
|
writeToStorage('authAuthenticated', 'false');
|
|
57406
57409
|
var logoutRequest = {
|
|
57407
57410
|
account: msalApp.getAccountByHomeId((_authData$accountId = authData.accountId) !== null && _authData$accountId !== void 0 ? _authData$accountId : accountId),
|
|
@@ -57422,13 +57425,24 @@ var _updateTokensInStorage = tokens => {
|
|
|
57422
57425
|
}
|
|
57423
57426
|
};
|
|
57424
57427
|
var _extractRolesFromAccessToken = accessToken => {
|
|
57425
|
-
var
|
|
57426
|
-
if (accessToken)
|
|
57427
|
-
|
|
57428
|
-
|
|
57429
|
-
|
|
57430
|
-
|
|
57431
|
-
|
|
57428
|
+
var _config2;
|
|
57429
|
+
if (!accessToken) return [];
|
|
57430
|
+
var decodedToken = JSON.parse(atob(accessToken.split('.')[1]));
|
|
57431
|
+
// The exact key to use may depend from keycloak client & Cosmo Tech API configuration (c.f. the value of
|
|
57432
|
+
// csm.platform.authorization.roles-jwt-claim in your k8s tenant secrets)
|
|
57433
|
+
var rolesTokenAttribute = (_config2 = config) === null || _config2 === void 0 ? void 0 : _config2.rolesJwtClaim;
|
|
57434
|
+
if (rolesTokenAttribute) {
|
|
57435
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken[rolesTokenAttribute]) return decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken[rolesTokenAttribute];
|
|
57436
|
+
console.warn("Authentication provider configuration defined rolesJwtClaim=\"".concat(rolesTokenAttribute, "\" ") + 'but this key was not found in the access token. Please check your webapp and API configuration.');
|
|
57437
|
+
}
|
|
57438
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken.roles) return decodedToken.roles; // Legacy default key in token
|
|
57439
|
+
|
|
57440
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken.userRoles) {
|
|
57441
|
+
console.warn("DEPRECATED: the token claim for API roles was automatically found in 'userRoles', but the lookup " + 'for this specific key will be removed in a future version. Please update your webapp configuration to ' + "explicitly set AUTH_KEYCLOAK_ROLES_JWT_CLAIM to 'userRoles'.");
|
|
57442
|
+
return decodedToken.userRoles;
|
|
57443
|
+
}
|
|
57444
|
+
console.warn("Couldn't extract roles from access token. Please check your webapp and API configuration.");
|
|
57445
|
+
return [];
|
|
57432
57446
|
};
|
|
57433
57447
|
var isUserSignedIn = /*#__PURE__*/function () {
|
|
57434
57448
|
var _ref4 = _asyncToGenerator(function* () {
|
|
@@ -57446,12 +57460,12 @@ var isUserSignedIn = /*#__PURE__*/function () {
|
|
|
57446
57460
|
clearFromStorage('authInteractionInProgress');
|
|
57447
57461
|
var locationHashParameters = new URLSearchParams(window.location.hash.substring(1));
|
|
57448
57462
|
if (locationHashParameters.has('state')) {
|
|
57449
|
-
var
|
|
57450
|
-
if (locationHashParameters.has('iss', (
|
|
57463
|
+
var _config3;
|
|
57464
|
+
if (locationHashParameters.has('iss', (_config3 = config) === null || _config3 === void 0 || (_config3 = _config3.msalConfig) === null || _config3 === void 0 || (_config3 = _config3.auth) === null || _config3 === void 0 || (_config3 = _config3.authorityMetadata) === null || _config3 === void 0 ? void 0 : _config3.issuer)) {
|
|
57451
57465
|
msalApp.handleRedirectPromise().then(handleResponse); // Resume redirect workflow process
|
|
57452
57466
|
} else if (locationHashParameters.has('iss')) {
|
|
57453
|
-
var
|
|
57454
|
-
var configIssuer = (
|
|
57467
|
+
var _config4;
|
|
57468
|
+
var configIssuer = (_config4 = config) === null || _config4 === void 0 || (_config4 = _config4.msalConfig) === null || _config4 === void 0 || (_config4 = _config4.auth) === null || _config4 === void 0 || (_config4 = _config4.authorityMetadata) === null || _config4 === void 0 ? void 0 : _config4.issuer;
|
|
57455
57469
|
var urlIssuer = locationHashParameters.get('iss');
|
|
57456
57470
|
console.warn("Issuer found in url \"".concat(urlIssuer, "\" does not match keycloak configuration: \"").concat(configIssuer, "\""));
|
|
57457
57471
|
}
|
|
@@ -57482,10 +57496,10 @@ var refreshTokens = /*#__PURE__*/function () {
|
|
|
57482
57496
|
};
|
|
57483
57497
|
}();
|
|
57484
57498
|
var getUserEmail = () => {
|
|
57485
|
-
var
|
|
57499
|
+
var _ref6, _readFromStorage, _msalApp$getAllAccoun2;
|
|
57486
57500
|
if (!checkInit()) return;
|
|
57487
57501
|
// Note: account data from MSAL seems to contain user email in the 'username' property
|
|
57488
|
-
return (
|
|
57502
|
+
return (_ref6 = (_readFromStorage = readFromStorage('authEmail')) !== null && _readFromStorage !== void 0 ? _readFromStorage : authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _ref6 !== void 0 ? _ref6 : (_msalApp$getAllAccoun2 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun2 === void 0 || (_msalApp$getAllAccoun2 = _msalApp$getAllAccoun2[0]) === null || _msalApp$getAllAccoun2 === void 0 ? void 0 : _msalApp$getAllAccoun2.username;
|
|
57489
57503
|
};
|
|
57490
57504
|
var getUserName = () => {
|
|
57491
57505
|
var _authData$name, _msalApp$getAllAccoun3;
|
package/dist/index.esm.js
CHANGED
|
@@ -57368,13 +57368,15 @@ var acquireTokens = /*#__PURE__*/function () {
|
|
|
57368
57368
|
}();
|
|
57369
57369
|
var handleResponse = response => {
|
|
57370
57370
|
if (response != null) {
|
|
57371
|
+
var _account$idTokenClaim, _account$idTokenClaim2;
|
|
57371
57372
|
var account = response.account;
|
|
57372
57373
|
_updateTokensInStorage(response);
|
|
57373
57374
|
writeToStorage('authIdTokenPopup', response.idToken);
|
|
57374
57375
|
writeToStorage('authAuthenticated', 'true');
|
|
57375
57376
|
writeToStorage('authAccountId', account.homeAccountId);
|
|
57377
|
+
writeToStorage('authEmail', (_account$idTokenClaim = account.idTokenClaims) === null || _account$idTokenClaim === void 0 ? void 0 : _account$idTokenClaim.email);
|
|
57376
57378
|
authData.accountId = account.homeAccountId;
|
|
57377
|
-
authData.userEmail = account.
|
|
57379
|
+
authData.userEmail = (_account$idTokenClaim2 = account.idTokenClaims) === null || _account$idTokenClaim2 === void 0 ? void 0 : _account$idTokenClaim2.email;
|
|
57378
57380
|
authData.username = account.name;
|
|
57379
57381
|
authData.userId = account.localAccountId;
|
|
57380
57382
|
redirectOnAuthSuccess();
|
|
@@ -57400,6 +57402,7 @@ var signOut = () => {
|
|
|
57400
57402
|
clearFromStorage('authIdToken');
|
|
57401
57403
|
clearFromStorage('authAccessToken');
|
|
57402
57404
|
clearFromStorage('authAccountId');
|
|
57405
|
+
clearFromStorage('authEmail');
|
|
57403
57406
|
writeToStorage('authAuthenticated', 'false');
|
|
57404
57407
|
var logoutRequest = {
|
|
57405
57408
|
account: msalApp.getAccountByHomeId((_authData$accountId = authData.accountId) !== null && _authData$accountId !== void 0 ? _authData$accountId : accountId),
|
|
@@ -57420,13 +57423,24 @@ var _updateTokensInStorage = tokens => {
|
|
|
57420
57423
|
}
|
|
57421
57424
|
};
|
|
57422
57425
|
var _extractRolesFromAccessToken = accessToken => {
|
|
57423
|
-
var
|
|
57424
|
-
if (accessToken)
|
|
57425
|
-
|
|
57426
|
-
|
|
57427
|
-
|
|
57428
|
-
|
|
57429
|
-
|
|
57426
|
+
var _config2;
|
|
57427
|
+
if (!accessToken) return [];
|
|
57428
|
+
var decodedToken = JSON.parse(atob(accessToken.split('.')[1]));
|
|
57429
|
+
// The exact key to use may depend from keycloak client & Cosmo Tech API configuration (c.f. the value of
|
|
57430
|
+
// csm.platform.authorization.roles-jwt-claim in your k8s tenant secrets)
|
|
57431
|
+
var rolesTokenAttribute = (_config2 = config) === null || _config2 === void 0 ? void 0 : _config2.rolesJwtClaim;
|
|
57432
|
+
if (rolesTokenAttribute) {
|
|
57433
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken[rolesTokenAttribute]) return decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken[rolesTokenAttribute];
|
|
57434
|
+
console.warn("Authentication provider configuration defined rolesJwtClaim=\"".concat(rolesTokenAttribute, "\" ") + 'but this key was not found in the access token. Please check your webapp and API configuration.');
|
|
57435
|
+
}
|
|
57436
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken.roles) return decodedToken.roles; // Legacy default key in token
|
|
57437
|
+
|
|
57438
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken.userRoles) {
|
|
57439
|
+
console.warn("DEPRECATED: the token claim for API roles was automatically found in 'userRoles', but the lookup " + 'for this specific key will be removed in a future version. Please update your webapp configuration to ' + "explicitly set AUTH_KEYCLOAK_ROLES_JWT_CLAIM to 'userRoles'.");
|
|
57440
|
+
return decodedToken.userRoles;
|
|
57441
|
+
}
|
|
57442
|
+
console.warn("Couldn't extract roles from access token. Please check your webapp and API configuration.");
|
|
57443
|
+
return [];
|
|
57430
57444
|
};
|
|
57431
57445
|
var isUserSignedIn = /*#__PURE__*/function () {
|
|
57432
57446
|
var _ref4 = _asyncToGenerator(function* () {
|
|
@@ -57444,12 +57458,12 @@ var isUserSignedIn = /*#__PURE__*/function () {
|
|
|
57444
57458
|
clearFromStorage('authInteractionInProgress');
|
|
57445
57459
|
var locationHashParameters = new URLSearchParams(window.location.hash.substring(1));
|
|
57446
57460
|
if (locationHashParameters.has('state')) {
|
|
57447
|
-
var
|
|
57448
|
-
if (locationHashParameters.has('iss', (
|
|
57461
|
+
var _config3;
|
|
57462
|
+
if (locationHashParameters.has('iss', (_config3 = config) === null || _config3 === void 0 || (_config3 = _config3.msalConfig) === null || _config3 === void 0 || (_config3 = _config3.auth) === null || _config3 === void 0 || (_config3 = _config3.authorityMetadata) === null || _config3 === void 0 ? void 0 : _config3.issuer)) {
|
|
57449
57463
|
msalApp.handleRedirectPromise().then(handleResponse); // Resume redirect workflow process
|
|
57450
57464
|
} else if (locationHashParameters.has('iss')) {
|
|
57451
|
-
var
|
|
57452
|
-
var configIssuer = (
|
|
57465
|
+
var _config4;
|
|
57466
|
+
var configIssuer = (_config4 = config) === null || _config4 === void 0 || (_config4 = _config4.msalConfig) === null || _config4 === void 0 || (_config4 = _config4.auth) === null || _config4 === void 0 || (_config4 = _config4.authorityMetadata) === null || _config4 === void 0 ? void 0 : _config4.issuer;
|
|
57453
57467
|
var urlIssuer = locationHashParameters.get('iss');
|
|
57454
57468
|
console.warn("Issuer found in url \"".concat(urlIssuer, "\" does not match keycloak configuration: \"").concat(configIssuer, "\""));
|
|
57455
57469
|
}
|
|
@@ -57480,10 +57494,10 @@ var refreshTokens = /*#__PURE__*/function () {
|
|
|
57480
57494
|
};
|
|
57481
57495
|
}();
|
|
57482
57496
|
var getUserEmail = () => {
|
|
57483
|
-
var
|
|
57497
|
+
var _ref6, _readFromStorage, _msalApp$getAllAccoun2;
|
|
57484
57498
|
if (!checkInit()) return;
|
|
57485
57499
|
// Note: account data from MSAL seems to contain user email in the 'username' property
|
|
57486
|
-
return (
|
|
57500
|
+
return (_ref6 = (_readFromStorage = readFromStorage('authEmail')) !== null && _readFromStorage !== void 0 ? _readFromStorage : authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _ref6 !== void 0 ? _ref6 : (_msalApp$getAllAccoun2 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun2 === void 0 || (_msalApp$getAllAccoun2 = _msalApp$getAllAccoun2[0]) === null || _msalApp$getAllAccoun2 === void 0 ? void 0 : _msalApp$getAllAccoun2.username;
|
|
57487
57501
|
};
|
|
57488
57502
|
var getUserName = () => {
|
|
57489
57503
|
var _authData$name, _msalApp$getAllAccoun3;
|