Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter spotify sdk - refresh access token

I am using the following package: https://pub.dev/packages/spotify_sdk

This package provides the method getAuthenticationToken which returns an access token to spotify to be used with my server to retrieve some spotify's data related with the user:

authenticationToken = await SpotifySdk.getAuthenticationToken(
  clientId: dotenv.get('SPOTIFY_CLIENT_ID'),
  redirectUrl: dotenv.get('SPOTIFY_AUTH_REDIRECT_URL'),
  scope: 'user-read-email, user-top-read',
);

However, this token expires after 1 hours. Is there any way, without front end code (only server side), to refresh this token? What are my options?

like image 608
Rabbiot Rabbiot Avatar asked Sep 05 '25 03:09

Rabbiot Rabbiot


1 Answers

tl;dr

There is no direct way to get a refresh token via the package. But there are other ways to get around this limitation. See bypass

Feature availability

Normally the Spotify auth api would include a refresh token, but this feature does not exist in the android sdk (cf: flutter package: #75 Android sdk: #12 #220 #225) although it is supported by the ios as well as the web sdk.

If the app is to be used only from ios or from the web, the maintainers of the flutter package would most likely accept a pr that exposes the refresh methods of the supported platforms even though it would bring little value.

Contribute feature

If you are familiar with android development and the feature is important to you, you can try to integrate this feature into the android sdk yourself and then expose it in the flutter sdk.

Here this was already done in a fork:

  • Repository

  • Commit

The maker already opened a pull request but it has no responses yet (opend late 2018).

Bypass

A way around this would be to store the username and password of the user on the device (or on the server) although this would be bad from a security standpoint.


Another inspiration might be this comment from an android-sdk user who routed authentication through his server.

like image 157
M123 Avatar answered Sep 09 '25 12:09

M123