2

I have an Android app, which the user can link to Spotify, with : AuthenticationClient.openLoginActivity(getActivity(), SPOTIFY_REQUEST_CODE, request);

The problem is that I want the user to change his Spotify account so I want to logout the user from Spotify to log with another account. But the data of the connection are saved in the cache and when I use this line again : "AuthenticationClient.openLoginActivity(getActivity(), SPOTIFY_REQUEST_CODE, request);", it does not show the connection dialog because the user is already connected.

In the doc, it says : "To log out and clear all stored tokens, use the AuthenticationClient#clearCookies method. Both Spotify and Facebook tokens will be removed."

But the method clearCookies does not exist anymore. What can I do to logout the user and allow him to connect on another account ?

mctregouet
  • 23
  • 4

3 Answers3

2

I've searched on the net and seems that this code

AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, type, redirectUri)
           .setShowDialog(true)
           .setScopes(scopes).build();

took from this post it's your only choice to try to logout a user.

I can't test it, so you should try it yourself and see if works.

The documentation on the Spotify Android SDK is outdated and is not reflecting the new Spotify auth library on GitHub.

MatPag
  • 41,742
  • 14
  • 105
  • 114
2

Spotify's Android SDK documentation is definitely outdated. My observation is that when you call

AuthorizationClient.clearCookies(context) 

directly before starting Spotify's auth activity, it just works fine. But if you call it once and then expect that the user is logged out, when you start the activity later in the future, cached credentials keep messing around.

I do not prefer

builder.setScopes(arrayOf("")).setShowDialog(false).build()

as it shows you a "not you? Click to log out" option. So basically you need to log out on the Spotify UI, cannot do it from code.

In my case, the application saves the logged in user's email (I need that to show on the UI, anyway). When I want to log the user out programmatically, I just delete the saved email from the app and call

clearCookies()

when I start Spotify's Activity if the variable is empty.

Aaron Fodor
  • 21
  • 2
  • 5
0

A bit late, but you can use this AuthorizationClient.clearCookies(this) as AuthenticationClient no longer exists

jane
  • 124
  • 10