Closed Nikos410 closed 4 years ago
See also #7. If you're using the authorization code flow, the library should refresh the token for you automatically.
If you're using the client credentials flow folks have just been recreating the client. Definitely open to ideas for making that workflow easier.
As per this discussion newToken, err := src.Token() // this actually goes and renews the tokens
which implies, I think, that zmb3/spotify/auth.go client.Token()
should also refresh token.
Now, this is just sidenote but you rarely need spotify token to last beyond default 60 minutes.
const state=abc123
) but it is not as intended.Hi, sorry for taking a while to respond.
I think I'm using the authorization code flow, like in the example in README.md.
So that means, if I create a client with Authenticator.NewClient(token)
and then perform actions using that client, the token will be updated automatically?
Yes. Your client should be authorized even if more then an hour passed.
Do log.Println(token.Expiry.Sub(time.Now()))
to make sure.
And newToken, _ := client.Token()
to obtain new token implicit.
If you would like to store new token (to file or database) this pseudocode might help.
tok, err := getTokenFromDB()
if err == nil {
client := auth.NewClient(tok)
if m, _ := time.ParseDuration("5m30s"); time.Until(tok.Expiry) < m {
newToken, _ := client.Token()
updateTokenInDB(newToken)
}
return &client
}
Alright, thank you very much, that does help me a lot
Hi there and thanks for this great library, it saved us a lot of work :)
I do have one problem though - an access token expires after 1 hour, but can be refreshed using the refresh token:
(https://developer.spotify.com/documentation/general/guides/authorization-guide#4-requesting-a-refreshed-access-token-spotify-returns-a-new-access-token-to-your-app)
Is there a way to do this using this library?
Thanks in advance!