Skip to content

Commit

Permalink
feat(authentication): enable token renewal in client
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <[email protected]>
  • Loading branch information
TheMaskedTurtle committed Dec 18, 2023
1 parent 9c52821 commit 5b91e89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export {
} from './utils/EquipmentType';

export {
dispatchUser,
getExpiresIn,
getPreLoginPath,
initializeAuthenticationDev,
initializeAuthenticationProd,
logout,
dispatchUser,
getPreLoginPath,
} from './utils/AuthService';

export { elementType, getFileIcon } from './utils/ElementType';
Expand Down
26 changes: 19 additions & 7 deletions src/utils/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ function initializeAuthenticationProd(
post_logout_redirect_uri: idpSettings.post_logout_redirect_uri,
silent_redirect_uri: idpSettings.silent_redirect_uri,
scope: idpSettings.scope,
automaticSilentRenew: !isSilentRenew,
accessTokenExpiringNotificationTime:
accessTokenExpiringNotificationTime,
automaticSilentRenew:
!isSilentRenew && !authorizationCodeFlowEnabled,
accessTokenExpiringNotificationTime,
...responseSettings,
};
let userManager = new UserManager(settings);
Expand Down Expand Up @@ -385,13 +385,25 @@ function handleUser(dispatch, userManager, validateUser) {
dispatchUser(dispatch, userManager, validateUser);
}

function getExpiresIn(idToken, maxTokenTtl) {
const decodedIdToken = jwtDecode(idToken);
const now = Date.now() / 1000;
const livingTime = now - decodedIdToken.iat;
const expiresIn = decodedIdToken.exp - now;
if (!maxTokenTtl) {
return expiresIn;
}
return Math.min(maxTokenTtl - livingTime, expiresIn, 0);
}

export {
dispatchUser,
getExpiresIn,
getPreLoginPath,
handleSigninCallback,
handleSilentRenewCallback,
initializeAuthenticationDev,
initializeAuthenticationProd,
handleSilentRenewCallback,
login,
logout,
dispatchUser,
handleSigninCallback,
getPreLoginPath,
};

0 comments on commit 5b91e89

Please sign in to comment.