mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-27 07:55:49 +03:00
[GH-ISSUE #237] issue with refreshtokens #170
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#170
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 @kasperkamperman on GitHub (Nov 8, 2021).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/237
Hi,
I followed the documentation on automatically refreshing tokens, however the auto_refresh function doesn't seem to work.
At least I expected that if a call can't be executed, the auto-refresh kicks in, refreshes the token and does the call again?
There are no new restrictions on my Spotify client app (created way before 2021-05-27).
I get this error (newest version of this php api):
I know it's not the clientid and if I refresh my token in another way (logging in in my service, store it in the database), it works good for an hour (after which the refresh token becomes invalid).
My code ($spotifyAuth are the tokens obtained from the database).
@jwilsson commented on GitHub (Nov 9, 2021):
Hey!
Your expectations on the functionality are 100% correct, you can check out the code if you're interested.
However, I'm afraid I can't reproduce the issue you're having. I've tried both the Authorization Code and PKCE flows (unsure which one you're using but figured it should be one of those) with two different apps created before and after 2021-05-27 and it always refreshes the access token automatically.
I'd love to help out but I'm really stumped at the moment. If I come up with any other thoughts or ideas I'll be sure to get back to you.
@kasperkamperman commented on GitHub (Nov 9, 2021):
Yes I have a stored accessToken and a refreshToken obtained with the Authorization code flow.
I reverted my code to my older implementation (see this issue https://github.com/jwilsson/spotify-web-api-php/issues/129) by wrapping the calls to the api in a function (don't mind the exeption variable wrongly written :) ).
I'll see if I can find some time to further debug it.
@jwilsson commented on GitHub (Nov 21, 2021):
Hi again!
Sorry for not getting back to you. I did have another look but I still can't reproduce it. I compared the implementation in the library to your "old" one and I can't see anything obvious that could be the issue. I'd really like to solve it but I'm at a total loss.
@kasperkamperman commented on GitHub (Nov 22, 2021):
No problem. If I find a bit of time, I check from my side what could be going on.
@kasperkamperman commented on GitHub (Nov 26, 2021):
Just in progress of debugging this issue. I came across a change of error message when you set the auto_refresh to true.
This code throws:
Uncaught SpotifyWebAPI\SpotifyWebAPIException: The access token expired in...When adding auto_refresh the error message changes:
Now the error reads:
Uncaught SpotifyWebAPI\SpotifyWebAPIAuthException: Invalid client inIt's strange that the error messages change when you set the auto-refresh option.
Of course the one without the option set is much more informative about what is causing the error, than the "invalid client" one.
When I update the accessToken, I get the expected output (so my personal information).
I'll check now if the refresh token indeed automatically refreshes (after a few hours).
@kasperkamperman commented on GitHub (Nov 27, 2021):
Finally I found the issue.
I defined the secret constant variables like this:
After that I used your code example:
So running this:
echo "secret: ".$session->getClientSecret()."\n";I got:
'CLIENT_ID'I should have called it like:
So without the apostrophe.
I think it went wrong because I based my original auth implementation on this issue code:
https://github.com/jwilsson/spotify-web-api-php/issues/100 So in progress switching to your new implementation I overlooked this.
--
So now everything seems to work.
I leave it up to you to close this.
Although error messages were different, it was indeed an invalid client configuration after all.
@jwilsson commented on GitHub (Nov 28, 2021):
Awesome! I'm so glad we got it figured out. Closing this issue but please don't hesitate to open a new one if there's any issues with the auto refresh functionality.