-
Notifications
You must be signed in to change notification settings - Fork 218
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
Refresh token not updated in Cache #3160
Comments
interesting point. I tried to replicate and yes, I see the same behavior. Wonder that this is not more of an issue for others. |
Hi @odin568 ... The refresh token can be invalidated not just through expiration, but in a variety of situations - user changes password, MFA is enabled in your app, the refresh token gets invalidated. This is just a signal for the app to re-authenticate the user interactively. The error message that you mention The correct way of handling these exceptions, is to challenge the user again. Are you doing this? And after the user logs a second time, does the error not go away? Note that the SDK saves a blob containing all 3 tokens - access token, id token, refresh token - in the cache. It doesn't save a single item to Redis. One way to be sure is to use a tool like Fiddler to capture traffic and to monitor Redis.
Alternatively, please get verbose logs and send them over. You can send them over email if you like to avoid putting them here - bogavril at microsoft com |
@bgavrilMS
This is true but doesn't matter. That is where I did verfiy the issue. This single cache entry gets an updated AccessToken but no updated RefreshToken after a refreshTokenGrant |
I already did describe this situation. After a new challange the user is able to work for one more hour (access token expiry) since the access token gets replaced in the cache but not the refresh token |
@michiproep, @odin568 |
Closing as answered. |
@jmprieur:
Additionaly, within the first 30 days (where their first refresh token is still valid) we face another issue |
I found another hint for this issue.
|
Ok, disabling the L1 cache might do the trick but I'm still not happy with this!
|
@jmprieur : Do we expect a changing behaviour when the new HybridCache feature gets implemented? |
Hi @michiproep - thanks for troubleshooting further and finding this. Do you have a suggestion on how to better deal with this ? We recommend using session affinity settings to ensure that the same user lands on the same server. Or disable memory caches. I am not sure that hybrid cache fixes this problem. I see this in their docs Since this error occurs when hitting the IdP, we could have Id.Web catch it and, in case memory + distributed cache is enabled try to get the token from the distributed cache only, i.e. ignore the local memory cache on retry. Thoughts ? I'll mark it as an enhacement. CC @jmprieur |
Hi @bgavrilMS ,
I think the problem is not really due to running multiple replicas, it is really "after refresh token exchange, the new refresh token also needs to find it's way to the L2 cache". Because the described scenario is also happening if you run only a single replica of your app. New finding: It seems like after a fresh login (challenge) the refresh token gets exchanged. It only happens for refreshToken grants. Additional info: All our apps provide 2 logout buttons: |
Microsoft.Identity.Web Library
Microsoft.Identity.Web
Microsoft.Identity.Web version
3.4.0
Web app
Sign-in users and call web APIs
Web API
Protected web APIs (validating tokens)
Token cache serialization
Distributed caches
Description
We face a serious issue while calling downstream Api for a user.
When a user logs in into the web app (2nd time) after the refresh token has expired, he gets a new access token which is valid for one hour. The token gets written to the cache (in our case: redis) but the corresponding refresh token only gets cached on the first login of the user but never gets updated on new logins nor on refresh_token_exchange.
We can see that on refresh_token_exchange the access token gets updated in the cache.
Error: After the first refresh token has expired the user can never - except for one hour after each login - call the downstream api since the used refresh token for that user is always expired.
Reproduction steps
Error message
"error":"invalid_grant","error_description":"AADB2C90129: The provided grant has been revoked. Please reauthenticate and try again.\r\nCorrelation ID: ....
Id Web logs
Relevant code snippets
Regression
dontKnow
Expected behavior
with each refreshTokenExchange, the cache should contain the new refresh token
The text was updated successfully, but these errors were encountered: