-
Notifications
You must be signed in to change notification settings - Fork 17
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
Authentication State Doesn't Persist Through Page Refresh #1
Comments
Thank for the great feedback! 😄 To my understanding (and I guess there are many opinions on how to do it right), the access token should not be stored. You are right, what currently happens is that, when you reload, the access token is lost. When redirection is in place, that would redirect you to the oauth provider. And if that figures out that you are still logged in, would automatically redirect you back to the application with a new code, which you can then trade for an access token. So, nothing is stored. We use that with Keycloak, and it works as expected. However, I guess not everyone wants to do it the same way. Taking a look at some pages from Auth0: https://auth0.com/docs/secure/security-guidance/data-security/token-storage#browser-in-memory-scenarios
And (the note):
However, I think it may be a valid use case to store the access (and I guess the refresh token) in the browser local storage. If someone does want to do that. I guess that The code already stores some state, which is needed to verify the code, and trade in the access token. So that part could also check for an existing access token, and try to use it instead. And when a new token is fetched, that could be stored in the local browser storage. |
got it, thanks ctron! Closing... |
When I reload my page, this redirection doesn't happen, I only see the How would I go about adding this redirection in for staying logged in, while not storing the token? |
True, as the What should happen is that it component detects that an authentication context/token is missing, and so it would redirect to the SSO server. If that still has a session active (maybe using cookies or storage) it would immediately redirect back to the application. So for the user, this would be transparent. I will see if I can add an explicit example for this case. |
I tried to create an example, but found out that So I created #6 I think it makes sense supporting this, and I would welcome your input on how to add this (how it would work best for you). |
I released version 0.4.0, which improves the |
Thanks @ctron. I'll give that a try :) |
First of all thank you for yew-oauth2 - having oauth in Rust webapps is amazing.
It seems like the access/refresh tokens are stored in an OAuth2Context object that can be retrieved by child components of
<OAuth2>
. Consequently, auth state seems to be lost when the page is refreshed.I'm not an expert in auth flows, but wouldn't storing the access token in a cookie be preferable? Both to resolve this issue and because it's likely all or most requests to backend APIs will need to include the access token anyway.
I suppose that would make this crate a bit "opinionated" in that some developers might want to handle this a different way. What's your recommended approach for handling this given how the crate works today?
The text was updated successfully, but these errors were encountered: