Skip to content
Snippets Groups Projects
Commit 3ef450c9 authored by Elisa Giglio's avatar Elisa Giglio
Browse files

fix refresh token

parent 915b9df0
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ else if(uri.includes("#")){
else {
await requestFirstToken(uriAuthCode); // post per la richiesta del token
if(token !== null) {
expirationTime = moment().add(token.expires_in,`s`);
expirationTime = moment().add(token.refresh_expires_in,`s`);
sessionStorage.setItem("expirationTime", expirationTime.toJSON());
const myDomains = await RequestToDomain.getMyDomains();
......@@ -93,7 +93,7 @@ async function requestFirstToken(uriAuthCode) {
async function getToken() {
const now = moment();
if(now - expirationTime < 1) {
if(expirationTime - now < 60000) {
//this token has expired, so request new token
await requestUsingRefreshToken();
}
......@@ -121,7 +121,7 @@ async function getToken() {
if(response.ok) {
alreadyRefreshed = true;
sessionStorage.setItem("token", JSON.stringify(token));
expirationTime = moment().add(token.expires_in,`s`);
expirationTime = moment().add(token.refresh_expires_in,`s`);
sessionStorage.setItem("expirationTime", expirationTime.toJSON());
oldTimeout = timeoutRefresh();
}
......@@ -140,12 +140,8 @@ function timeoutRefresh() {
clearTimeout(oldTimeout);
return setTimeout(async () => {
console.log("fired!",{alreadyRefreshed})
if(!alreadyRefreshed) {
await requestUsingRefreshToken();
alreadyRefreshed = false;
console.log("refreshed!")
}
await requestUsingRefreshToken();
alreadyRefreshed = false;
}, (token.expires_in*1000)-5000); // richiedo il nuovo token 5 secondi prima che il token scada
}
......@@ -164,7 +160,7 @@ async function logoutKeycloak() {
async function getIdToken() {
const now = moment();
if(now - expirationTime < 1) {
if(expirationTime - now < 60000) {
//this token has expired, so request new token
await requestUsingRefreshToken();
}
......
......@@ -23,7 +23,7 @@ const connectOptions = {
onSuccess: onConnect,
userName: "gruppo2",
password: "funziona",
// useSSL: true,
useSSL: true,
// cleanSession: false,
onFailure: onFailure,
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment