Skip to content

(Web) Existing expired token deleted when SDK is initialized with PKCE strategy #15

@SuspiciousLookingOwl

Description

@SuspiciousLookingOwl

Existing expired token seem to be removed from local storage instead of being refreshed when the SDK is being initialized.

To replicate:

  1. Initialize the SDK with PKCE Strategy like usual
const sdk = SpotifyApi.withUserAuthorization(...);
  1. Authenticate and complete the auth redirection normally
sdk.authenticate();
  1. Replace the expires value stored on the local storage manually using browser's dev console to simulate the token being expired
// get the token value
localStorage.getItem("spotify-sdk:AuthorizationCodeWithPKCEStrategy:token"); 
// { "access_token": "...", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "...", "scope": "...", "expires": 1708419488712 }

// then replace the token value on the local storage so that the token seems expired
localStorage.getItem(
  "spotify-sdk:AuthorizationCodeWithPKCEStrategy:token",
  '{ "access_token": "...", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "...", "scope": "...", "expires": 1600000000000 }'
); 
  1. Reload the page so that the SDK is re-initialized again.

  2. The token is now removed from the local storage instead of being refreshed and user has to reauthenticate again

// get the token value
localStorage.getItem("spotify-sdk:AuthorizationCodeWithPKCEStrategy:token"); 
// null

I don't know if this is the intended behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions