mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-26 23:45:49 +03:00
[GH-ISSUE #20] Refresh token should not be in Session #9
Labels
No labels
bug
docs
enhancement
enhancement
enhancement
feedback wanted
good first issue
help wanted
help wanted
help wanted
invalid
pull-request
question
question
upstream
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-web-api-php#9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @hvt on GitHub (Dec 25, 2014).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/20
Just wanted to check whether you guys would agree on this, or not.
In my opinion, the
refresh_tokenshould not exist in theSessionclass. It should just be returned bySession::requestToken()(I refactored that toSession::requestRefreshAndAccessToken()in https://github.com/jwilsson/spotify-web-api-php/pull/19) and be supplied when the access token is refreshed.Why? Well, at the moment it is stored in the class for convenience, but no one would be using it like this. The access token expiration takes quite long (one hour at the moment), that anyone using the refresh token should already save it somewhere persistent. By removing it from the class, it will be more obvious the refresh token is not something volatile. Plus you leave it up to the user to do something with the token or not.
Therefore, I'd like to suggest to:
Session::$refreshToken(plus its associated get and set methods)Session::requestToken()(Session::requestRefreshAndAccessToken()in https://github.com/jwilsson/spotify-web-api-php/pull/19) to return an array containing the three returned values (access token, expiry date, and the refresh token) andnullwhen something goes wrong.Session::refreshToken()(Session::refreshAccessToken()in https://github.com/jwilsson/spotify-web-api-php/pull/19) to have the refresh token as a parameter.Next, something that just came to my mind: the access token's expire period also doesn't do much. I.e. it's saved, but you know nothing of it (e.g. when was the last access token retrieved). So we should either do something with it (calculate when the access token actually expires and act on it), or just leave this to the user of the class...
Just some ideas, wonder what you guys think ;].
@jwilsson commented on GitHub (Dec 28, 2014):
I think all of these points are great and very valid points. It would probably make the whole authorization process easier as well.
I do however think that we should keep
Session::getRefreshToken()but removeSession::setRefreshToken()since one might want to retrieve the token a while after the initial authorization.I also definitely think we should calculate the expires time for the user and return a Unix timestamp indicating when the access token expires, e.g.
time() + $expiresbut leave it to the user to actually act on it when the token expires. This change will of course let the user check if the access token is expired without sending a request that will fail and then act on it.Pinging @vdesabou since I know he's a big user of this.
@vdesabou commented on GitHub (Dec 28, 2014):
I think all the suggestions proposed here are good. On my side, I'm using the library in a command line mode, so I re-create an instance of Session and SpotifyWebAPI every time. I store the refresh token, and the expire time in a DB and calls
refreshToken()when needed. I don't think I'm gonna usegetExpires()anyway.@hvt commented on GitHub (Dec 28, 2014):
Session::getRefreshtoken()(plus the attribute).Session::setRefreshToken().Session::refreshAccessToken().time() + $expires) as an attribute ofSession.Some more discussion: what about renaming the
Session::getExpires()toSession::getAccessTokenExpiration()? And would adding anSession::isAccessTokenExpired()method be of any help?@jwilsson commented on GitHub (Dec 30, 2014):
👍
Hmm, I like the renaming idea but I don't know if an
Session::isAccessTokenExpired()method would be of any help. I'm not against it but I think we could hold it off for a bit if no one objects.@hvt commented on GitHub (Jan 5, 2015):
Will start on this once I got some more time (probably next week or so).
@jwilsson commented on GitHub (Jan 5, 2015):
Don't worry about it. I don't think we should include this until the 1.0 release anyway (and it's a while before that will happen).
@jwilsson commented on GitHub (Sep 29, 2015):
@hvt you interested in taking a stab at this? Just let me know if not and I'll take care of it :)
@hvt commented on GitHub (Sep 29, 2015):
@jwilsson No I haven't. You're good to fix it yourself :].
@jwilsson commented on GitHub (Sep 29, 2015):
@hvt Alright, thanks for your quick response!