-
Notifications
You must be signed in to change notification settings - Fork 18k
x/oauth2/clientcredentials: Refresh token is never used #66620
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
Comments
the TokenSource creates an oauth2.Token https://cs.opensource.google/go/x/oauth2/+/refs/tags/v0.18.0:clientcredentials/clientcredentials.go;l=117-123 |
The code that actually sends the HTTP request for the new token is handled in whatever struct implements the oauth2.TokenSource interface. Here's the implementation in the regular oauth2 package: https://cs.opensource.google/go/x/oauth2/+/master:oauth2.go;l=280 |
The refresh code for the clientcredentials implementation will only ever give a |
Another observation: The API for acquiring a token is different between oauth2 and oauth2.credentials. The former uses this: The latter, on the other hand, uses this: The benefit of the way oauth2 does it is that it allows for persistent caching. Since you supply the initial token, you can get that token from anywhere. You could get it from the HTTP API provided by the server, but you could also have it stored in a database or something and retrieve it from there. The interface provided by oauth2.clientcredentials makes it impossible to do persistent caching. When the program restarts, it must get an entirely new token with a |
Go version
go version go1.22.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
TokenSource
on aclientcredentials.Config
What did you see happen?
The function requests an entirely new token with grant_type=client_credentials, even if a refresh token is available to use.
The SoundCloud API has a strict rate limit of 50 tokens every 12 hours for an app, which is why I ran into this problem: https://developers.soundcloud.com/docs/api/guide#authentication
What did you expect to see?
The function uses the previously acquired refresh token to get a new token, which is the behavior of x/oauth2
The text was updated successfully, but these errors were encountered: