spotify / android-sdk

Spotify SDK for Android
https://developer.spotify.com/documentation/android/
Apache License 2.0
454 stars 117 forks source link

Spotify App Remote `AuthenticationFailedException` When Connecting Offline Immediately After A Successful Connection #330

Open Abominabl31 opened 1 year ago

Abominabl31 commented 1 year ago

...This is a referral from @SpotifyCares via Twitter and the Spotify Community Forum. Spotify Cares indicated this would be the best place to address this issue. Thanks for your help!

Issue Found: on 2022-Aug-10, Spotify community posts date back to at least 2022-May-10

SDK Version: 0.7.2

OS Version: Android 12

Scope(s): app-remote-control playlist-modify-public playlist-read-collaborative playlist-modify-private user-library-modify user-read-email user-read-private

Steps To Reproduce:

  1. Use the connect method of Spotify App Remote while a network connection is usable to initially connect and use Spotify App Remote successfully, specifically playback of a playlist URI at a known index and playback of a known track URI
  2. Place the device in airplane mode or otherwise simulate an unreliable network connection, perhaps with proxy tools
  3. Force stop both the Spotify app and the app using Spotify App Remote
  4. Restart the app using Spotify App remote
  5. Use the connect method as before

This used to work, so it does seem to be a regression - possibly in the latest Spotify app since the cause is detailed as "remote"? Note, this makes an app using Spotify App Remote unusable when network is unavailable - which is a lot of the time for a mobile device user, of course. 👉🏻 https://community.spotify.com/t5/Spotify-for-Developers/Android-Spotify-App-Remote-AuthenticationFailedException-When/td-p/5415218 👉🏻 https://community.spotify.com/t5/Spotify-for-Developers/Connect-SpotifyAppRemote-when-offline/m-p/5380018/highlight/true#M4549

Expected Result:

  1. Spotify App Remote's connect method should succeed when a network connection is unavailable if the following criteria are met
    • The app has recently had a successful connection with working network
    • The app and the official Spotify app have not had any scope or authentication changes
    • A reasonable time has not passed for authentication to expire (Say, a seven day grace period?)
    • Requested playlist and track URIs are downloaded or cached by the Spotify app
    • An detailed and unique exception would be appropriate for at least these cases
    • A working connection has not previously been established
    • Authentication has expired
    • The request playlist or track URI is not cached or downloaded

Actual Result:

  1. Most of the expected result was working as of earlier this year. The new result is this exception being thrown by connect.
    com.spotify.android.appremote.api.error.AuthenticationFailedException: {“message”:“Could not authenticate within 60 s. It is possible that there\u0027s an issue with Spotify auth services or the connection is unstable”}
    at com.spotify.android.appremote.api.LocalConnector.asAppRemoteException(LocalConnector.java:137)
    at com.spotify.android.appremote.api.LocalConnector.access$000(LocalConnector.java:34)
    at com.spotify.android.appremote.api.LocalConnector$1.onConnectionFailed(LocalConnector.java:117)
    at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:162)
    at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:95)
    at android.os.AsyncTask.finish(AsyncTask.java:771)
    at android.os.AsyncTask.access$900(AsyncTask.java:199)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7870)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    Caused by: com.spotify.protocol.client.error.RemoteClientException: {“message”:“Could not authenticate within 60 s. It is possible that there\u0027s an issue with Spotify auth services or the connection is unstable”}
    at com.spotify.protocol.client.RemoteWampClient.getRemoteClientException(RemoteWampClient.java:139)
    at com.spotify.protocol.client.RemoteWampClient.access$200(RemoteWampClient.java:16)
    at com.spotify.protocol.client.RemoteWampClient$1.onAbort(RemoteWampClient.java:44)
    at com.spotify.protocol.client.WampRouterImpl.routeAbort(WampRouterImpl.java:100)
    at com.spotify.protocol.client.WampRouterImpl.route(WampRouterImpl.java:26)
    at com.spotify.protocol.client.AppProtocolCommunicator.onData(AppProtocolCommunicator.java:78)
    at com.spotify.android.appremote.internal.RemoteServiceIo.handleMessage(RemoteServiceIo.java:111)
    at com.spotify.android.appremote.internal.RemoteServiceIo.access$000(RemoteServiceIo.java:45)
    at com.spotify.android.appremote.internal.RemoteServiceIo$IncomingHandler.handleMessage(RemoteServiceIo.java:89)
Abominabl31 commented 1 year ago

This issue is still getting posts on the Spotify Community forum as well.
👉🏻 https://community.spotify.com/t5/Spotify-for-Developers/Android-Spotify-App-Remote-AuthenticationFailedException-When/td-p/5415218 👉🏻 https://community.spotify.com/t5/Spotify-for-Developers/Connect-SpotifyAppRemote-when-offline/m-p/5420333/highlight/true#M5430

If this issue will be worked on at any point in the future, it would be great to know that it has been received and read. Without some feedback, it is hard to know this issue has been queued for future work. Any feedback helps.

petrnalevka commented 1 year ago

Hello.. 3 months later still the same problem.. Would be great if someone could look into this.. Thank you

nicholaschum commented 1 year ago

Still having this issue. Doesn't make sense that Offline Mode will allow it to connect to the API but Online Mode doesn't.