Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger updateToken #57

Closed
CryptoZorro opened this issue Oct 15, 2020 · 5 comments
Closed

Trigger updateToken #57

CryptoZorro opened this issue Oct 15, 2020 · 5 comments

Comments

@CryptoZorro
Copy link

CryptoZorro commented Oct 15, 2020

Thanks for this helpful plugin.

I understand that there is an implicit token refresh, but I would like to trigger updateToken() before making an API call (or) as a part of error handling of an 403 response, like how it's mentioned in the JS adapter docs. How do I do this?

I did try $keycloak.updateToken but this function is not exposed with the $keycloak instance. Is there any other way? Thanks in advance!

keycloak.updateToken(60).then(function() {
    makeAPICall();
}).catch(function() {
    alert('Failed to refresh token');
});
@nlien
Copy link
Contributor

nlien commented Oct 15, 2020

I'm not sure if this will help you, but what about intercepting http requests and inspecting the status code?
For example with Axios, like this:

axios.interceptors.response.use(response => {
  return response
}, error => {
  if (error.response.status === 403) {
    // Do something
  } else {
    return Promise.reject(error)
  }
})

@CryptoZorro
Copy link
Author

CryptoZorro commented Oct 15, 2020

Yes that's exactly what I wanted to do as well, my actual question was, where you got // Do something, how do call updateToken(), so that I can retry my api call?

@nlien
Copy link
Contributor

nlien commented Oct 15, 2020

If updateToken() from the Keycloak JS adapter is the only thing that'll help, I guess this function also has to be exposed.

I'm wondering if it's better to just expose the whole Keycloak object altogether, acting like a proxy, so every function/property is exposed always....

@CryptoZorro
Copy link
Author

CryptoZorro commented Oct 15, 2020

I agree, there could be many use cases, where I see the updateToken being manually triggered. For example, I would like to updateToken on window.onfocus()... The plugin will be totally flexible!

@baltom
Copy link
Contributor

baltom commented Oct 27, 2020

@CryptoZorro this should now be possible with version 1.3.1+ by doing Vue.$keycloak.keycloak.updateToken(60)

@baltom baltom closed this as completed Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants