Skip to content

Instantly share code, notes, and snippets.

@sinnus
Created September 24, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinnus/6be8a4b0a142191a1cabd7f38274ca62 to your computer and use it in GitHub Desktop.
Save sinnus/6be8a4b0a142191a1cabd7f38274ca62 to your computer and use it in GitHub Desktop.
function apiReq(url) {
getToken()
.then(function(token) {
axios.get(url, {headers: {'Authorization' : 'Bearer ' + token}})
.then(function(response) {
alert(response.data);
});
})
}
function getToken() {
return new Promise(function(resolve, reject) {
keycloak.updateToken(5)
.then(function() {
resolve(keycloak.token);
})
.catch(function() {
alert('Failed to refresh token');
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment