viestat / react-native-spotify

A native module that allows you to use the Spotify SDK API with react-native
MIT License
108 stars 23 forks source link

[BUG]: Cannot Authenticate with Spotify App Installed #6

Open digitaldavenyc opened 8 years ago

digitaldavenyc commented 8 years ago

I am attempting to get Spotify Authentication working but it only shows a login view without any form to proceed, screenshot below.

There are no errors in the console for react-native. The only error I get in Xcode is -canOpenURL: failed for URL: "spotify-action://" - error: "(null)" but I understand this is only for using auth with the spotify app and not related to auth issues.

Could really use some help because since there are no errors to work with, I can't even figure out what's wrong.

screen shot 2016-09-19 at 12 38 33 pm
digitaldavenyc commented 8 years ago
import React, { Component } from 'react';
import { View, Text, StatusBar, Dimensions, TouchableOpacity, StyleSheet, Image } from 'react-native';
import SpotifyButton from '../components/buttons/spotify';
import { NativeModules } from 'react-native';

var SpotifyAuth = NativeModules.SpotifyAuth;

export default class Player extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loggedIn: false
        }
    }

    onLogin() {
        SpotifyAuth.setClientID('xxxxx','xxxxx://spotify', ['streaming'], (error) => {
            console.log('callback')
            if(!error){
                _this.setState({
                    loggedIn: true
                })
            } else {
                console.log('error:', error);
            }
        });
    }

    render() {
        return (
            <View style={{backgroundColor: '#171717', width: width, height: height, alignItems: 'center'}}>
                <StatusBar barStyle='light-content' />
                <SpotifyButton onLogin={this.onLogin} />
            </View>
        )
    }
}
digitaldavenyc commented 8 years ago

So this is weird, I figured out the issue. The Redirect URI protocol was the same name as my application name, if I changed it to a name to something else, login works. Very strange.

If your bundle is com.audiofly don't make your redirect uri audiofly://callback... try using audiofly-login://callback

digitaldavenyc commented 8 years ago

After fixing this problem on simulator, it is now back testing on a physical device. I tested on two separate iPhones and it's the same issue as the screenshot above, the login screen shows with no form.

viestat commented 8 years ago

@digitaldavenyc when you logged-in in the simulator did you check the remember me box?

digitaldavenyc commented 8 years ago

@viestat Probably, but the simulator is the one that works, I'm having issues with a physical iPhone. Even if it didn't remember me, I would expect the form to display to re-authenticate, but the form doesn't even show on the physical iPhone.

I have tried to remove any type of cache on the physical phone... I cleared safari's cache, deleted the app, restarted the phone and re-installed to the app to the phone. Problem still persists.

digitaldavenyc commented 8 years ago

@viestat any thoughts on this?

digitaldavenyc commented 8 years ago

@viestat I have figured out the problem and this is a critical issue I have discovered, if the Spotify app is installed on a physical phone, this repo will not work.

I dug threw the logs in Xcode and noticed -canOpenURL: failed for URL: "spotify-action://" - error: "(null)" would show on the simulator and not on a physical iphone, since that error is due to there being no Spotify app available. So I uninstalled Spotify on my phone and this magically fixed the error.

Curious if anyone can test this on another iPhone to confirm but there likely needs to be an update to the repo to fix this that will actually launch the Spotify to authenticate, if it's available, if not then the webkit view will need to be triggered. If that's not possible then there needs to be a way to force the webkit view to display.

moooji commented 8 years ago

I tried this on my physical phone with Spotify App installed and it works fine. It fails though, when I add "spotify-app" as URL Types -> URL Schemes to my app, but I guess that is expected.

I guess the issue might be that the spotify SDK tries to authenticate via the installed Spotify app (which should react to spotify-action:// I guess). Not sure how exactly that works, but it feels it could be related.

/**
 Allow login through Spotify App if installed. 'YES' by default.
 If set to 'NO' WebView login flow is used.
 */
@property (readwrite) BOOL allowNativeLogin;

So you could try to force WebView login by adding this to startAuth and see if that makes a difference on your phone.

[[SPTAuth defaultInstance] setAllowNativeLogin:false];

digitaldavenyc commented 8 years ago

@moooji That's really weird that you're able to launch the login with the Spotify app installed. I've tested it on two separate iPhones and confirmed the issue. Perhaps there is some other configuration problem but I don't think so, I've gone over this a million times.

I am not an objective-c developer so not quite sure how to implement your suggested code... Adding [[SPTAuth defaultInstance] setAllowNativeLogin:false]; to startAuth throws an error No visible @interface for 'SPTAuth' declares the selector 'setAllowNativeLogin:'

digitaldavenyc commented 8 years ago

@moooji that suggestion will not work. I just had an iOS developer review this and I think you referencing code from the Spotify 23SDK not the 17SDK that this library is using.

digitaldavenyc commented 8 years ago

@viestat it's been over a week, I'd really appreciate it if you could provide some insight to this. We are prepping to submit to the app store but this issue is blocking us from doing so.

viestat commented 8 years ago

@digitaldavenyc I have not been able to test a couple changes to the repo on a physical device. Once I can test properly I may be able to provide more input on this. In the meantime please tell me the IOS version of the physical devices you have tested on.

digitaldavenyc commented 8 years ago

@viestat I have tested this on iOS 9.3 for iPhone 6S Plus and iPhone SE.

FrenchBully commented 7 years ago

@viestat @digitaldavenyc did this ever get resolved? Is the repo having issues being deployed to a physical device?