moved also refresh token to fetch
This commit is contained in:
parent
7f50e2900e
commit
9411728b3a
|
@ -649,46 +649,38 @@
|
|||
refreshQueue.push(promise);
|
||||
|
||||
if (refreshQueue.length == 1) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('POST', url, true);
|
||||
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
req.withCredentials = true;
|
||||
|
||||
params += '&client_id=' + encodeURIComponent(kc.clientId);
|
||||
|
||||
var timeLocal = new Date().getTime();
|
||||
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState == 4) {
|
||||
if (req.status == 200) {
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers: {'Content-type':'application/x-www-form-urlencoded'},
|
||||
body : params,
|
||||
credentials: "include"
|
||||
}).then(resp=>{
|
||||
if(req.status == 200){
|
||||
return req.json()
|
||||
}
|
||||
if (req.status == 400) {
|
||||
kc.clearToken();
|
||||
}
|
||||
throw "Failed to refresh token"
|
||||
}).then(body=>{
|
||||
logInfo('[KEYCLOAK] Token refreshed');
|
||||
|
||||
timeLocal = (timeLocal + new Date().getTime()) / 2;
|
||||
|
||||
var tokenResponse = JSON.parse(req.responseText);
|
||||
|
||||
setToken(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], timeLocal);
|
||||
|
||||
kc.onAuthRefreshSuccess && kc.onAuthRefreshSuccess();
|
||||
for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
|
||||
p.setSuccess(true);
|
||||
}
|
||||
} else {
|
||||
}).catch(err=>{
|
||||
logWarn('[KEYCLOAK] Failed to refresh token');
|
||||
|
||||
if (req.status == 400) {
|
||||
kc.clearToken();
|
||||
}
|
||||
|
||||
kc.onAuthRefreshError && kc.onAuthRefreshError();
|
||||
for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
|
||||
p.setError(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
req.send(params);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue