spotify icon indicating copy to clipboard operation
spotify copied to clipboard

refresh token

Open TAMILVIP007 opened this issue 1 year ago • 4 comments

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

TAMILVIP007 avatar Apr 16 '23 08:04 TAMILVIP007

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

cuotos avatar May 31 '23 08:05 cuotos

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

TAMILVIP007 avatar Jul 14 '23 18:07 TAMILVIP007

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 avatar Dec 07 '23 19:12 ATroschke

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.

ATroschke avatar Dec 26 '23 18:12 ATroschke