spotify / spotify-web-api-ts-sdk

A Typescript SDK for the Spotify Web API with types for returned data.
Other
355 stars 69 forks source link

Reauthorization happens very often #3

Closed Stefterv closed 1 year ago

Stefterv commented 1 year ago

I think I spoke too soon in my pull request #2 and I'm still running into having to authenticate very often when using the Authorization Code Flow with PKCE method.

Right now I have to re-auth every few hours, previously when manually requesting a new token with the refresh token on the server that would be much less often.

Is this an inherent limitation of the auth method? Am I using the library wrong? Or is it a bug?

Normally I would've delved deeper into myself but I figured other people might run into too

thisisjofrank commented 1 year ago

Hmmm, that does sound like a bug, I'll do a bit of investigation, sounds like maybe there's an issue with the cached token. Let me know if you do manage to delve deeper and find anything.

Stefterv commented 1 year ago

It's been fairly painful to replicate as I have to wait an hour every time for the auth token to expire. So far I've repeatedly found run across the first request before the redirect missing the actual Bearer token:

....
Accept-Encoding: gzip, deflate, br
Accept-Language: en-NL,en;q=0.9,en-US;q=0.8,nl;q=0.7,de;q=0.6
Authorization: Bearer
Content-Type: application/json
...

and thus receiving an 400 error:

...
Www-Authenticate: Bearer realm="spotify", error="invalid_request", error_description="Only valid bearer authentication supported"
...
Stefterv commented 1 year ago

Okay I can trigger it by manually changing the expire key in the localStorage. Right now I've debugged it until here.

The update functions are empty and thus the item is marked as expired and not returned.