@cosmotech/core 1.18.1 → 1.18.2
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 +21 -23
- package/dist/index.esm.js +21 -23
- package/package.json +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## **1.18.2** <sub><sup>2024-09-23 (e619d7e...e619d7e)</sup></sub>
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- fix empty user roles when using Keycloak auth provider ([e619d7e](https://github.com/Cosmo-Tech/webapp-component-core/commit/e619d7e))
|
|
6
|
+
|
|
1
7
|
## **1.18.1** <sub><sup>2024-09-17 (3629ee8...3629ee8)</sup></sub>
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/dist/index.cjs.js
CHANGED
|
@@ -57287,7 +57287,6 @@ var readFromStorage = key => localStorage.getItem(key);
|
|
|
57287
57287
|
var clearFromStorage = key => localStorage.removeItem(key);
|
|
57288
57288
|
var name = 'auth-keycloakRedirect';
|
|
57289
57289
|
var authData = {
|
|
57290
|
-
authenticated: readFromStorage('authAuthenticated') === 'true',
|
|
57291
57290
|
accountId: undefined,
|
|
57292
57291
|
userEmail: undefined,
|
|
57293
57292
|
username: undefined,
|
|
@@ -57351,20 +57350,19 @@ var acquireTokens = /*#__PURE__*/function () {
|
|
|
57351
57350
|
var _msalApp$getAllAccoun;
|
|
57352
57351
|
var forceRefresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
57353
57352
|
if (!checkInit()) return;
|
|
57354
|
-
if (!forceRefresh) {
|
|
57353
|
+
if (!forceRefresh && readFromStorage('authAuthenticated') === 'true') {
|
|
57355
57354
|
var idToken = readFromStorage('authIdToken');
|
|
57356
57355
|
var accessToken = readFromStorage('authAccessToken');
|
|
57357
|
-
|
|
57358
|
-
|
|
57359
|
-
|
|
57360
|
-
|
|
57361
|
-
idToken
|
|
57362
|
-
};
|
|
57363
|
-
}
|
|
57356
|
+
return {
|
|
57357
|
+
accessToken,
|
|
57358
|
+
idToken
|
|
57359
|
+
};
|
|
57364
57360
|
}
|
|
57365
57361
|
var account = (_msalApp$getAllAccoun = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun === void 0 ? void 0 : _msalApp$getAllAccoun[0];
|
|
57366
57362
|
if (account === undefined) return;
|
|
57367
|
-
|
|
57363
|
+
var tokens = yield _acquireTokensByRequestAndAccount(config.accessRequest, account);
|
|
57364
|
+
_updateTokensInStorage(tokens);
|
|
57365
|
+
return tokens;
|
|
57368
57366
|
});
|
|
57369
57367
|
return function acquireTokens() {
|
|
57370
57368
|
return _ref3.apply(this, arguments);
|
|
@@ -57373,12 +57371,10 @@ var acquireTokens = /*#__PURE__*/function () {
|
|
|
57373
57371
|
var handleResponse = response => {
|
|
57374
57372
|
if (response != null) {
|
|
57375
57373
|
var account = response.account;
|
|
57374
|
+
_updateTokensInStorage(response);
|
|
57376
57375
|
writeToStorage('authIdTokenPopup', response.idToken);
|
|
57377
|
-
writeToStorage('authIdToken', response.idToken);
|
|
57378
|
-
writeToStorage('authAccessToken', response.accessToken);
|
|
57379
57376
|
writeToStorage('authAuthenticated', 'true');
|
|
57380
57377
|
writeToStorage('authAccountId', account.homeAccountId);
|
|
57381
|
-
authData.authenticated = true;
|
|
57382
57378
|
authData.accountId = account.homeAccountId;
|
|
57383
57379
|
authData.userEmail = account.username; // In MSAL account data, username property contains user email
|
|
57384
57380
|
authData.username = account.name;
|
|
@@ -57420,23 +57416,28 @@ var isAsync = () => {
|
|
|
57420
57416
|
};
|
|
57421
57417
|
var _updateTokensInStorage = tokens => {
|
|
57422
57418
|
if (tokens !== null && tokens !== void 0 && tokens.idToken) writeToStorage('authIdToken', tokens.idToken);
|
|
57423
|
-
if (tokens !== null && tokens !== void 0 && tokens.accessToken)
|
|
57419
|
+
if (tokens !== null && tokens !== void 0 && tokens.accessToken) {
|
|
57420
|
+
writeToStorage('authAccessToken', tokens.accessToken);
|
|
57421
|
+
authData.roles = _extractRolesFromAccessToken(tokens.accessToken);
|
|
57422
|
+
}
|
|
57424
57423
|
};
|
|
57425
57424
|
var _extractRolesFromAccessToken = accessToken => {
|
|
57426
57425
|
var result = [];
|
|
57427
57426
|
if (accessToken) {
|
|
57428
57427
|
var decodedToken = JSON.parse(atob(accessToken.split('.')[1]));
|
|
57429
|
-
|
|
57430
|
-
|
|
57431
|
-
}
|
|
57428
|
+
// The exact key to use may depend from keycloak client & API configuration
|
|
57429
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken.roles) result = decodedToken.roles;else if (decodedToken !== null && decodedToken !== void 0 && decodedToken.userRoles) result = decodedToken.userRoles;
|
|
57432
57430
|
}
|
|
57433
57431
|
return result;
|
|
57434
57432
|
};
|
|
57435
57433
|
var isUserSignedIn = /*#__PURE__*/function () {
|
|
57436
57434
|
var _ref4 = _asyncToGenerator(function* () {
|
|
57437
|
-
if (authData.authenticated) return true;
|
|
57438
57435
|
if (readFromStorage('authAuthenticated') === 'true') {
|
|
57439
|
-
|
|
57436
|
+
// Restore roles from access token if necessary (roles in auhtData may be lost after login redirection)
|
|
57437
|
+
if (authData.roles.length === 0) {
|
|
57438
|
+
var accessToken = readFromStorage('authAccessToken');
|
|
57439
|
+
if (accessToken) authData.roles = _extractRolesFromAccessToken(accessToken);
|
|
57440
|
+
}
|
|
57440
57441
|
return true;
|
|
57441
57442
|
}
|
|
57442
57443
|
try {
|
|
@@ -57460,10 +57461,7 @@ var isUserSignedIn = /*#__PURE__*/function () {
|
|
|
57460
57461
|
// Otherwise, try to acquire a token silently to implement SSO
|
|
57461
57462
|
var tokens = yield acquireTokens();
|
|
57462
57463
|
_updateTokensInStorage(tokens);
|
|
57463
|
-
if ((tokens === null || tokens === void 0 ? void 0 : tokens.accessToken) !== undefined)
|
|
57464
|
-
authData.roles = _extractRolesFromAccessToken(tokens.accessToken);
|
|
57465
|
-
return true;
|
|
57466
|
-
}
|
|
57464
|
+
if ((tokens === null || tokens === void 0 ? void 0 : tokens.accessToken) !== undefined) return true;
|
|
57467
57465
|
} catch (e) {
|
|
57468
57466
|
console.error(e);
|
|
57469
57467
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -57285,7 +57285,6 @@ var readFromStorage = key => localStorage.getItem(key);
|
|
|
57285
57285
|
var clearFromStorage = key => localStorage.removeItem(key);
|
|
57286
57286
|
var name = 'auth-keycloakRedirect';
|
|
57287
57287
|
var authData = {
|
|
57288
|
-
authenticated: readFromStorage('authAuthenticated') === 'true',
|
|
57289
57288
|
accountId: undefined,
|
|
57290
57289
|
userEmail: undefined,
|
|
57291
57290
|
username: undefined,
|
|
@@ -57349,20 +57348,19 @@ var acquireTokens = /*#__PURE__*/function () {
|
|
|
57349
57348
|
var _msalApp$getAllAccoun;
|
|
57350
57349
|
var forceRefresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
57351
57350
|
if (!checkInit()) return;
|
|
57352
|
-
if (!forceRefresh) {
|
|
57351
|
+
if (!forceRefresh && readFromStorage('authAuthenticated') === 'true') {
|
|
57353
57352
|
var idToken = readFromStorage('authIdToken');
|
|
57354
57353
|
var accessToken = readFromStorage('authAccessToken');
|
|
57355
|
-
|
|
57356
|
-
|
|
57357
|
-
|
|
57358
|
-
|
|
57359
|
-
idToken
|
|
57360
|
-
};
|
|
57361
|
-
}
|
|
57354
|
+
return {
|
|
57355
|
+
accessToken,
|
|
57356
|
+
idToken
|
|
57357
|
+
};
|
|
57362
57358
|
}
|
|
57363
57359
|
var account = (_msalApp$getAllAccoun = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun === void 0 ? void 0 : _msalApp$getAllAccoun[0];
|
|
57364
57360
|
if (account === undefined) return;
|
|
57365
|
-
|
|
57361
|
+
var tokens = yield _acquireTokensByRequestAndAccount(config.accessRequest, account);
|
|
57362
|
+
_updateTokensInStorage(tokens);
|
|
57363
|
+
return tokens;
|
|
57366
57364
|
});
|
|
57367
57365
|
return function acquireTokens() {
|
|
57368
57366
|
return _ref3.apply(this, arguments);
|
|
@@ -57371,12 +57369,10 @@ var acquireTokens = /*#__PURE__*/function () {
|
|
|
57371
57369
|
var handleResponse = response => {
|
|
57372
57370
|
if (response != null) {
|
|
57373
57371
|
var account = response.account;
|
|
57372
|
+
_updateTokensInStorage(response);
|
|
57374
57373
|
writeToStorage('authIdTokenPopup', response.idToken);
|
|
57375
|
-
writeToStorage('authIdToken', response.idToken);
|
|
57376
|
-
writeToStorage('authAccessToken', response.accessToken);
|
|
57377
57374
|
writeToStorage('authAuthenticated', 'true');
|
|
57378
57375
|
writeToStorage('authAccountId', account.homeAccountId);
|
|
57379
|
-
authData.authenticated = true;
|
|
57380
57376
|
authData.accountId = account.homeAccountId;
|
|
57381
57377
|
authData.userEmail = account.username; // In MSAL account data, username property contains user email
|
|
57382
57378
|
authData.username = account.name;
|
|
@@ -57418,23 +57414,28 @@ var isAsync = () => {
|
|
|
57418
57414
|
};
|
|
57419
57415
|
var _updateTokensInStorage = tokens => {
|
|
57420
57416
|
if (tokens !== null && tokens !== void 0 && tokens.idToken) writeToStorage('authIdToken', tokens.idToken);
|
|
57421
|
-
if (tokens !== null && tokens !== void 0 && tokens.accessToken)
|
|
57417
|
+
if (tokens !== null && tokens !== void 0 && tokens.accessToken) {
|
|
57418
|
+
writeToStorage('authAccessToken', tokens.accessToken);
|
|
57419
|
+
authData.roles = _extractRolesFromAccessToken(tokens.accessToken);
|
|
57420
|
+
}
|
|
57422
57421
|
};
|
|
57423
57422
|
var _extractRolesFromAccessToken = accessToken => {
|
|
57424
57423
|
var result = [];
|
|
57425
57424
|
if (accessToken) {
|
|
57426
57425
|
var decodedToken = JSON.parse(atob(accessToken.split('.')[1]));
|
|
57427
|
-
|
|
57428
|
-
|
|
57429
|
-
}
|
|
57426
|
+
// The exact key to use may depend from keycloak client & API configuration
|
|
57427
|
+
if (decodedToken !== null && decodedToken !== void 0 && decodedToken.roles) result = decodedToken.roles;else if (decodedToken !== null && decodedToken !== void 0 && decodedToken.userRoles) result = decodedToken.userRoles;
|
|
57430
57428
|
}
|
|
57431
57429
|
return result;
|
|
57432
57430
|
};
|
|
57433
57431
|
var isUserSignedIn = /*#__PURE__*/function () {
|
|
57434
57432
|
var _ref4 = _asyncToGenerator(function* () {
|
|
57435
|
-
if (authData.authenticated) return true;
|
|
57436
57433
|
if (readFromStorage('authAuthenticated') === 'true') {
|
|
57437
|
-
|
|
57434
|
+
// Restore roles from access token if necessary (roles in auhtData may be lost after login redirection)
|
|
57435
|
+
if (authData.roles.length === 0) {
|
|
57436
|
+
var accessToken = readFromStorage('authAccessToken');
|
|
57437
|
+
if (accessToken) authData.roles = _extractRolesFromAccessToken(accessToken);
|
|
57438
|
+
}
|
|
57438
57439
|
return true;
|
|
57439
57440
|
}
|
|
57440
57441
|
try {
|
|
@@ -57458,10 +57459,7 @@ var isUserSignedIn = /*#__PURE__*/function () {
|
|
|
57458
57459
|
// Otherwise, try to acquire a token silently to implement SSO
|
|
57459
57460
|
var tokens = yield acquireTokens();
|
|
57460
57461
|
_updateTokensInStorage(tokens);
|
|
57461
|
-
if ((tokens === null || tokens === void 0 ? void 0 : tokens.accessToken) !== undefined)
|
|
57462
|
-
authData.roles = _extractRolesFromAccessToken(tokens.accessToken);
|
|
57463
|
-
return true;
|
|
57464
|
-
}
|
|
57462
|
+
if ((tokens === null || tokens === void 0 ? void 0 : tokens.accessToken) !== undefined) return true;
|
|
57465
57463
|
} catch (e) {
|
|
57466
57464
|
console.error(e);
|
|
57467
57465
|
}
|