android-sdk icon indicating copy to clipboard operation
android-sdk copied to clipboard

Single sign-on how to

Open JavoByte opened this issue 5 years ago • 24 comments

I have a running app integrated with Spotify Authentication flow via web login so I already have a token. Docs says I can use this token to user app remote sdk but I don't get how.

ConnectionParams doesn't seem to have a way to set the token. How should I give this params my token?

JavoByte avatar Jul 15 '18 19:07 JavoByte

I'm also wondering about this, is there any update that allows this yet? There does not seem to be support on the Android SDK for auth token usage, whereas on the iOS SDK there is.

SPTAppRemoteConnectionParams is the iOS equivalent object to ConnectionParams in the Android SDK. We have this example for iOS:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  SPTAppRemoteConnectionParamsImageFormat format = SPTAppRemoteConnectionParamsImageFormatAny;
  SPTAppRemoteConnectionParams *params =
    [[SPTAppRemoteConnectionParams alloc] initWithClientIdentifier:@"your_client_id"
                                                       redirectURI:@"your_redirect_uri"
                                                              name:@"your_app_name"
                                                       accessToken:nil
                                                  defaultImageSize:CGSizeZero
                                                       imageFormat:format];

  self.appRemote = [[SPTAppRemote alloc] initWithConnectionParameters:params
                                            logLevel:SPTAppRemoteLogLevelDebug];
  self.appRemote.delegate = self;

  return YES;
}

and this example on Android:

// Set the connection parameters
ConnectionParams connectionParams =
    new ConnectionParams.Builder(CLIENT_ID)
            .setRedirectUri(REDIRECT_URI)
            .showAuthView(true)
            .build();

You can see clearly that token usage is provided directly in the iOS SDK but not the Android SDK.

There is a paragraph on using a token but there are no answers at the links provided.

Download and add Authorization Library to your project as described in this guide. Create and send the authorization request as described in the Android SDK Authorization Guide. You need the app-remote-control scope to use the Spotify App Remote SDK.

Am I missing something here? It looks like it's not supported since we need to use SpotifyAppRemote.CONNECTOR.connect in some way to get a valid SpotifyAppRemote object with which to initiate playback, etc. Simply authenticating with app-remote-control is not enough to actually use it.

ghost avatar Sep 07 '18 08:09 ghost

I'm having the same issue. I successfully get a Token from the installed Spotify app, but don't know how to create an SpotifyAppRemote with it.

benjy3gg avatar Sep 19 '18 08:09 benjy3gg

Hey folks - we're looking into improving the documentation / sample code for this. Stay tuned!

arirawr avatar Sep 21 '18 12:09 arirawr

@arirawr Any update on this? I'm able to get a token and am unsure of how to proceed

welle108 avatar Nov 20 '18 23:11 welle108

Hi @arirawr , as far as I am able to gather, this is not a documentation issue, it is incomplete support by the SDK which will require a fix update.

ghost avatar Nov 21 '18 08:11 ghost

Hi @arirawr, do you have any update related to this? We are trying to create a token using the authorization library that we want to use both with the Web API SDK and the SpotifyAppRemote, but we do not found the way to pass the access token to the SpotifyAppRemote.

Can you help us with this? Thanks

xtinaddt avatar Feb 27 '19 15:02 xtinaddt

Has anyone found an answer to this problem? I facing the exact same issue and as far as I know, the documentation doesn't explain anything about how to get the ConnectionParams object with existing tokens... It is written that it's supposed to be possible, but I haven't figured out how... To be honest, looking trough the sdk code, I think this feature isn't even implemented, so this issue shouldn't be marked as "documention".

Mcluky avatar Apr 21 '19 15:04 Mcluky

I too am looking for an answer to this. Would be great to not have to different sources of authorization to use both the Web API and the AppRemote.

StrictTangent avatar May 03 '19 18:05 StrictTangent

I'm looking for this feature too. Is there any workaround for this?

felipef0x avatar May 22 '19 15:05 felipef0x

Anyone?

andrescr94 avatar Jun 14 '19 21:06 andrescr94

Also shocked this feature doesn't exist; requiring users to sign in twice feels like a complete show-stopper for my integration. Spent a full hour looking over the reference and docs trying to figure out what I was missing, considering they all certainly implied you could just pass a token on into the App Remote APIs.

thomasboyt avatar Jun 28 '19 04:06 thomasboyt

Meanwhile, the iOS SDK does let you simply provide whatever access token you want when connecting the app remote, making this all the more baffling: https://developer.spotify.com/documentation/ios/quick-start/#connecting-to-spotify

thomasboyt avatar Jun 28 '19 05:06 thomasboyt

For an Android app I'm working on we were using the Streaming SDK. Seeing it is deprecated and the repo is being removed November 1st we wanted to migrate to this Android SDK.

Previously we requested an auth token using the flow described by Spotify that also returns a refresh token so we could silently refresh the token before it expired and the user could continue to use the app.

With this SDK I noticed that the token retrieved after login is also only valid for an hour and there is no refresh token nor is there a method to trigger a refresh. Our app stops working after an hour untill a new login is triggered.

There's also no way of setting the auth token so we could refresh it using the refresh token. The only way that seems to be possible is to trigger a login every hour. No user interaction is necessary as the user is already logged-in and the scope doesn't change but still the login is visible on screen.

The iOS SDK has a way of setting an auth token.

To me this looks like Spotify has deprecated a SDK that worked perfectly fine without providing a working alternative.

Maybe I've missed something in the documentation and examples and if I did and there is a way of getting this to work I gladly hear it.

sschimmel avatar Oct 22 '19 07:10 sschimmel

Any news about this? You're showing the benefits of Single sign-on in the documentation and it doesn't actually work

AntoineGagnon avatar Jan 29 '20 19:01 AntoineGagnon

@arirawr I really think the lable "documentation" seems to be wrong here since looking at the exposed android api, there is no way to use your own access token.

Mcluky avatar Jan 31 '20 05:01 Mcluky

@mcluky I'm sorry but I'm no longer at Spotify and can't help you with this.

arirawr avatar Jan 31 '20 08:01 arirawr

Any news on this issue? It would be really cool to be able to use the access token that we retrieve with a refresh token with the SpotifyAppRemote.

Tinouga avatar May 14 '20 17:05 Tinouga

Why is that everytime I go to use a public API, I spend ages getting everything working, only to find out that something really basic and essential is not actually included.

Seriously, how has this issue been here for 2 years and it still isn't fixed?

richjhart avatar Jun 08 '20 13:06 richjhart

How wrong I was that I could quickly make an application using this authentication library, I looked at the source code, re-read the documentation until I realized that we do not have an easy way to update the access token, then why do we need this library?

I am used AppAuth library and feeling good

WiMank avatar Aug 28 '20 14:08 WiMank

I was frustrated when I found out we can't refresh token so I've implemented a solution using AppAuth library to make it easy to integrate into Android apps. The project is a fork from spotify-web-api-android.

Check the needed auth dependency and this section to get access token and silently refresh token in your app.

Hope I'm allowed to share here and hope this helps.

pghazal avatar Nov 08 '20 11:11 pghazal

I am having the same issue while integrating Android SDK to my app. I get the access token from web API and want to set it to SpotifyAppRemote. Could anyone help this?

sayasheng avatar Nov 17 '20 02:11 sayasheng

It has been almost 4 years now... Are there any plans to implement a way to get refresh tokens from the Spotify App?

oemel09 avatar Feb 05 '22 12:02 oemel09

Haha, they're probably all busy making the UX a little worse in the next app update.

Seriously though, my impression is that this SDK was brought to life by a specific team at Spotify. That team probably fell apart for some reason (it happens), and no one who's left even knows how the SDK works anymore. I wouldn't get my hopes up on this issue being resolved this year.

BjoernPetersen avatar Feb 05 '22 15:02 BjoernPetersen

I wanted to get just the Authorization Code, but I'm it's returning empty. Anyone could grab It successfuly?

tbassani avatar Jan 13 '23 22:01 tbassani