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) {
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
req.send(params);
|
||||
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);
|
||||
}
|
||||
}).catch(err=>{
|
||||
logWarn('[KEYCLOAK] Failed to refresh token');
|
||||
kc.onAuthRefreshError && kc.onAuthRefreshError();
|
||||
for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
|
||||
p.setError(true);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -765,7 +757,7 @@
|
|||
var params = 'code=' + code + '&grant_type=authorization_code';
|
||||
var url = kc.endpoints.token();
|
||||
|
||||
params += '&client_id=' + encodeURIComponent(kc.clientId);
|
||||
params += '&client_id=' + encodeURIComponent(kc.clientId);
|
||||
params += '&redirect_uri=' + oauth.redirectUri;
|
||||
|
||||
if (oauth.pkceCodeVerifier) {
|
||||
|
|
Loading…
Reference in New Issue