Festify / cordova-spotify-oauth

🔐 Easy Spotify authentication for Cordova / PhoneGap apps
MIT License
16 stars 18 forks source link

Works in emulator, fails on real device #10

Closed mhaddon closed 6 years ago

mhaddon commented 6 years ago

I have probably set up the callback wrong, because I do not really understand what value it should be set to, but...

I have set up a serverless-offline server on my own non-cloud server. It has my refresh and exchange urls which point to the relevant endpoints on my domain. But for redirectUrl, I have: http://localhost:8888/callback This redirectUrl is a registered callback on my App in Spotify.

In the config.xml I have:

        <config-file parent="/*" target="res/values/strings.xml">
            <string name="com_spotify_sdk_redirect_scheme">http</string>
            <string name="com_spotify_sdk_redirect_host">localhost:8888/callback</string>
        </config-file>

Inside the <platform name="android"> tag.

When I run the emulator with cordova emulate android. It all works fine...

When I send the app-debug.apk to my phone, the Loading message appears, then a small animation seems to happen where it tries to load something on the screen, then it disappears.

Any ideas please?

mhaddon commented 6 years ago

There was a problem where I had https instead of http for the scheme, but if I fix that I get this error (in JS):

"AUTH_FAILED: RECEIVED AUTHENTICATION RESPONSE OF INVALID TYPE ERROR".

The actual serverless server does not seem to have received any requests though and has nothing in its logs.

Once again, this works fine in the emulator.

NeoLegends commented 6 years ago

Could you try using a custom protocol instead of using http URLs and see if that works? Officially this plugin only supports custom protocols and not universal links (I‘m surprised it kinda did work in your case tho).

NeoLegends commented 6 years ago

Could be that the phone‘s link handling machinery is intercepting something.

mhaddon commented 6 years ago

I changed the callback to test://callback, same error message.

The serverless-offline server does not seem to get any requests.

Does the callback need to be an actual URL or is it just the URL that cordova watches for to know if it needs to redirect back to the main screen of the app?

It would be nice if the system supported serverless-offline as it allows people to install and configure the application on their own servers.

For some reason the emulator seems to be happy with whatever callback url i give it providing it is the same on the spotify app, server and client.

I am also using: "<engine name="android" spec="^7.0.0" />", if that is part of the problem?

NeoLegends commented 6 years ago

I changed the callback to test://callback, same error message.

Ok, seems to be a bug in the library / misconfiguration then. That link should definitely work.

Does the callback need to be an actual URL or is it just the URL that cordova watches for to know if it needs to redirect back to the main screen of the app?

It need not be an actual URL, just something the cordova app can listen to.

"AUTH_FAILED: RECEIVED AUTHENTICATION RESPONSE OF INVALID TYPE ERROR"

This error is thrown here https://github.com/Festify/cordova-spotify-oauth/blob/7e463284d8f054ef3d2fb695a44e64fc693fa42c/src/android/SpotifyOAuthPlugin.java#L88 and it indicates that the Spotify authentication library is not happy with the data it received through the link..

This makes me think that this is not an issue with the callback reaching the application (because otherwise that line wouldn't even run) but with the data being passed to the application instead. Could you somehow check which exact URL you're being redirected to?

It would be nice if the system supported serverless-offline as it allows people to install and configure the application on their own servers.

The plugin does not mandate the use of cloud platforms. You just need to provide it with an appropriate implementation of the token server. That said, I strongly recommend the use of cloud functions / serverless platforms because it frees you of the hassle of properly setting up, securing, maintaining and scaling a server.

The Festify app, for example, does not use the library's example server directly, but a slightly modified version thats hosted on Firebase Functions (also serverless, but a different provider).

I am also using: "", if that is part of the problem?

Uh, that could also be it. AFAIR the last time we used this plugin was with cordova-android v6, not v7.

mhaddon commented 6 years ago

Using adb logcat | grep -i spotify and remote debugging the messages i get from the device, I can see these messages:

03-13 21:47:26.107 22445 22445 D com.spotify.sdk.android.authentication.LoginActivity: https://accounts.spotify.com/authorize?client_id=redacted&response_type=code&redirect_uri=test%3A%2F%2Fcallback&show_dialog=true&utm_source=spotify-sdk&utm_medium=android-sdk&utm_campaign=android-sdk&scope=user-read-private%20user-read-birthdate%20playlist-read-private%20user-read-email%20user-library-read%20user-library-modify%20user-top-read%20playlist-read-collaborative%20playlist-modify-public%20playlist-modify-private%20user-follow-read%20user-follow-modify%20user-read-playback-state%20user-read-currently-playing%20user-modify-playback-state%20user-read-recently-played

03-13 21:47:26.107 22445 22445 D SpotifyAuthHandler: start

03-13 21:47:26.110 3511 4467 I ActivityManager: START u0 {act=com.spotify.sso.action.START_AUTH_FLOW pkg=com.spotify.music cmp=com.spotify.music/com.spotify.mobile.android.sso.AuthorizationActivity (has extras)} from uid 10129 on display 0

03-13 21:47:28.739 14451 14451 E Spotify : [main] INVALID_APP_ID

03-13 21:47:28.787 22445 22445 D com.spotify.sdk.android.authentication.LoginActivity: Error authenticating

03-13 21:47:28.787 22445 22445 D SpotifyAuthHandler: stop

INVALID_APP_ID lead me down a rabbit hole that proved I am not the smartest penguin in the Sahara desert. I fixed this by registering the debug keystore hash. As mentioned here: https://developer.spotify.com/technologies/spotify-android-sdk/tutorial/#registering-application-fingerprints

Thanks for the help, it looks like its all working.

Kruszylo commented 4 years ago

Hi, I experience the same type of error, my app works in emulator but does not work on a real device, I was thinking that it because I updated my real device, but now I'm not that sure as far as on emulator with android 9 the app works without any problem. Source code is here and error is:

source code