Giter Club home page Giter Club logo

Comments (9)

jscalo avatar jscalo commented on August 23, 2024

Following up… by all indications the app should be able to authenticate without the tokenSwapURL and tokenRefreshURL endpoints and get an access token that expires in an hour. And it seems like it almost works— if I break in application(_, open url, options) and peek at the incoming URL, it appears to have a valid access code:

myapp-spt://?code=AQCjw-6KFlBA532RvD1XrBbTwcgoZSQjCF0bSi2_ihDQuHBLAHBLAH

The problem is that afterward the call to sessionManager.application(app, open: url, options: options) for some reason is generating a sessionManager(didFailWith) error on the delegate. I've triple checked that my app's callback URI on the dashboard matches what's in the app and Info.plist (and they were working with the older framework).

The exact same thing happens in the Obj-C sample app if I comment out the lines that set the tokenSwapURL and tokenRefreshURL.

from ios-sdk.

weswes avatar weswes commented on August 23, 2024

You should use "the built-in app-remote-control Authorization flow" to avoid using tokenSwapURL and tokenRefreshURL and get an one hour access token.
Do not use STPSessionManager. Just STPAppRemote:

SPTConfiguration *configuration =
    [[SPTConfiguration alloc] initWithClientID:@"your_client_id" redirectURL:[NSURL urlWithString:@"your_redirect_uri"]];
self.appRemote = 
    [[SPTAppRemote alloc] initWithConfiguration:configuration logLevel:SPTAppRemoteLogLevelDebug];
BOOL spotifyInstalled = [self.appRemote authorizeAndPlayURI:@""]; // blank URI plays the last user song

Configure your AppDelegate to parse out the accessToken in application:openURL:options: and set it on the SPTAppRemote connectionParameters.

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    NSDictionary *params = [self.appRemote authorizationParametersFromURL:url];
    NSString *token = params[SPTAppRemoteAccessTokenKey];
    if (token) {
        self.appRemote.connectionParameters.accessToken = token;
    } else if (params[SPTAppRemoteErrorDescriptionKey]) {
        NSLog(@"%@", params[SPTAppRemoteErrorDescriptionKey]);
    }
    return YES;
}

from ios-sdk.

jackfreeman avatar jackfreeman commented on August 23, 2024

@jscalo, @weswes is correct. You do not need a backend server if you using the the built-in app-remote-control Authorization flow on SPTAppRemote.

If you need any additional scopes you will need to set up a backend server to perform the token swap.

from ios-sdk.

jscalo avatar jscalo commented on August 23, 2024

Thanks @jackfreeman and @weswes, I'll give it a shot. Mind pointing me to where this is documented? I don't see it in any of the iOS guides or the Authorization guide.

from ios-sdk.

jackfreeman avatar jackfreeman commented on August 23, 2024

https://github.com/spotify/ios-sdk#using-the-built-in-app-remote-control-authorization-flow-recommended

from ios-sdk.

jscalo avatar jscalo commented on August 23, 2024

Thanks @jackfreeman. One last question— the server flow can take a configuration with a nil playURI so that no audio plays after authentication. However in this flow the only way to start the auth process is with authorizeAndPlayURI which takes a non-nil URI, so that audio always plays after authenticating. Is there any way to prevent that?

from ios-sdk.

jackfreeman avatar jackfreeman commented on August 23, 2024

@jscalo Unfortunately the only way to auth without playing music is by using SPTSessionManager and setting up your own backend to handle the token swap.

from ios-sdk.

jscalo avatar jscalo commented on August 23, 2024

Weird. OK. Sending a bogus URI won't have the same effect?

from ios-sdk.

nicoletapop avatar nicoletapop commented on August 23, 2024

When the given access token through appDelegate openURL method by the built-in authorization expires, what can we do? Do we receive a new access token when calling appRemote.connect()? Or only when we call authorizeAndPlayURI? depending on whether the Spotify app is playing music or not

from ios-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.