zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.33k stars 283 forks source link

refresh token #221

Open TAMILVIP007 opened 1 year ago

TAMILVIP007 commented 1 year ago

https://github.com/zmb3/spotify/blob/f897b41a6495bc134b79d4096d8d201f3970e344/examples/authenticate/authcode/authenticate.go#L31

hey there i used this method to generate oauth token to get user's current playing track. It shows it expires after one hour. How can i refresh token if its expired? without running a web auth again

cuotos commented 1 year ago

this library is using the golang.org oauth2 client behind the scenes, it will handle the refresh for you when the token has expired.

"Client returns an HTTP client using the provided token. The token will auto-refresh as necessary. The underlying HTTP transport will be obtained using the provided context"

https://pkg.go.dev/golang.org/x/oauth2#Config.Client

TAMILVIP007 commented 11 months ago

Does it means i dont want to ask user to login each1h? after token gets expired?

ATroschke commented 6 months ago

this library is using the golang.org oauth2 client behind the scenes, it will handle the refresh for you when the token has expired.

"Client returns an HTTP client using the provided token. The token will auto-refresh as necessary. The underlying HTTP transport will be obtained using the provided context"

https://pkg.go.dev/golang.org/x/oauth2#Config.Client

I am sorry for waking this Thread up again, but is this true?

How can I hook into this?

Here is my current situation: I am asking users to connect their Spotify Account to my App to retrieve information about a User (specifically, their Followed Artists). I am then periodically synchronizing their Artists with a simple m2m Table in my DB and Fetching releases for my Users to display a proper and complete "New Releases" page.

I currently have an Issue where I frequently get revoked token Errors due to the refresh token already being used somewhere and had issues to track the exact place where it happens down.

ATroschke commented 6 months ago

I'm just gonna answer myself here.

Spotify revokes refresh tokens after a single use, and the OAuth2 library did indeed automatically refresh my users access token.