-
Notifications
You must be signed in to change notification settings - Fork 529
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
AspNetCore3 - a new refresh token on every login #1725
Comments
Assigning to @amanda-tarafa as she knows more about this than I do, but please be aware that we're on vacation until Tuesday, so there may be no further responses until then. |
I can reply in more detail on Tuesday when I'm back at work. But short answer: yes the old refresh token might stop working for any of the reasons listed on the docs you linked, including, but not only, too many refresh tokens emitted. As it says there your app should be prepared for this, and the easiest way to do that in the scenario you described is to store the new refresh token every time there's one. I'm guessing that if your app can store it the first time, it can store it every time. I can't remember if you can request an access token without a refresh token or if Google.Apis.Auth.AspNetCore* would currently allow it. But even if it were possible, any of the other refresh token invalidation conditions could be met at any time and your app should be prepared to deal with that. |
@amanda-tarafa thank you for your valuable feedback. I was asking the same: is it possible to get an access_topken without a refresh_token? Reading documentation here https://developers.google.com/identity/protocols/oauth2/web-server#httprest_3 it seems to be possible setting access_type=online, instead of offline.
In Google APIs client Library for .NET I can't find an option to toggle from offline to online. |
I'll take a closer look next week at Google.Apis.Auth and Google.Apis.Auth.AspNetCore* to evaluate surfacing this as a new feature if it's not possible already. Two things though:
|
Having taken a closer look:
I know this is a lot of info, and you'll probably have to write a little bit more code than you were expecting to. But do let me know if you run into issues or if this is not helpful at all. |
Your code is very interesting and full of tips. |
Yes, on Google.Apis.Auth.AspNetCore3.IntegrationTests you can take a look at the List Google Drive files and List Calendars operations to see how to manage incremental auth via attributes or code. You shouldn't need to do much more than what's done in those operations. |
The refresh tokens shouldn't be expiring as you are allowed to have up to 50 outstanding refresh tokens for a user before the oldest expires. You should only be getting a new refresh token if the user is logging in again. (ie shown the consent screen and consenting to your access). If you are just using a refresh token to request a new access token this should not be causing a new refresh token to be returned by the auth server. |
But certainly once the 51st refresh token has been emmitted, the oldest one will become invalid. For users that frequently clear cookies or log in from different devices, or simply log out of your application, this cap can very reasonably be hit within a few months, or even days. Also, the caps are not guarenteed to remain unchanged, docs refer mostly to the existance of caps but not to a given cap value for this very reason. Applications shouldn't depend on the cap being 50, it could be changed to a different, smaller, value at any given moment. Thus, my recommendation is still to store the more recent refresh token for use in the backend service. |
@amanda-tarafa following you suggestion, I have created a very simple demo. A asp.net core web application for authenticating user and calling Drive/Calendar services. And a console-application - simulating a backend daemon - that uses refresh tokens released to web-application and stored in a shared file. (ok, not secure, but this is only a demo). Refresh_tokens intercepted and stored on OnTokenValidated. Hope this could be useful also for other facing my same issues. |
I'm glad we could help! |
I'm playing with Google.Apis.Auth.AspNetCore3.IntegrationTests sample. Everythins works fine but I see something strange from my point of view.
Every time a user login, Google auth service generates a new set of access_token + refresh_token.
Reading https://developers.google.com/identity/protocols/oauth2#expiration I understand that there is a limit on the number of valid refresh_token issued by Google for an application. Older refresh_token are automatically invalidated.
Imagine this case:
I'm worried that after many logins, the old refresh_token, stored in the backend, would be no longer valid.
Am I right? Is this risk real? If so, is there a way to login in aspnet core web app without asking for a new refresh_token and asking for it only when really needed, e.g. because I need to store it?
The text was updated successfully, but these errors were encountered: