I use the following code to make sure I have a valid token before making a
request. Even though I am logged in, if I wait until the token expires
then make a request, the error function is called most of the time when I
try to update the token using the updateToken method. I have the page
reload, and I have a valid token again. However, I did not have to log in
again because the session had not expired. I am using
1.1.0-Alpha1-SNAPSHOT I have read the documentation. Am I missing
something?
keycloak.updateToken().success(function() {
if (data) {
$http({
url: 'http://localhost:8080' + url,
method: method,
data: data,
headers: {
'Content-Type': contentType,
'Accept': acceptType,
'Authorization': 'Bearer ' + service.auth.token
},
transformRequest: angular.identity
}).success(success).error(error);
} else {
$http({
url: 'http://localhost:8080' + url,
method: method,
headers: {
'Content-Type': contentType,
'Accept': acceptType,
'Authorization': 'Bearer ' + service.auth.token
}
}).success(success).error(error);
}
}).error(function() {
alert("Token could not be refreshed!");
location.reload();
});