Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting AUTHENTICATION_SERVICE_UNAVAILABLE when calling authorize. #166

Closed
fickleEfrit opened this issue Oct 21, 2021 · 25 comments
Closed

Comments

@fickleEfrit
Copy link

fickleEfrit commented Oct 21, 2021

Hello, I am trying to get a React Native application working with this library. I previously had gotten authentication with Spotify to work when just using React Native App Auth on its own, but figured that if I'm going to be using this library to control Spotify in the background I should probably do the authentication with this as well.

However, when I call the authorize method of auth from an Android emulator I get the following:

backend.js:32 Possible Unhandled Promise Rejection (id: 1):
Error: AUTHENTICATION_SERVICE_UNAVAILABLE
Error: AUTHENTICATION_SERVICE_UNAVAILABLE
    at promiseMethodWrapper (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2220:36)
    at Object.SpotifyAuth.authorize (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:158119:14)
    at AppContextProvider.authenticate (http://10.0.2.2:8081/components/AppContext.bundle?platform=android&dev=true&minify=false&modulesOnly=true&runModule=false&shallow=true:265:40)
    at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:176031:7
    at Object.onPress (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:176123:16)
    at onPress (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:55751:27)
    at Pressability._performTransitionSideEffects (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:56376:15)
    at Pressability._receiveSignal (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:56314:16)
    at onResponderRelease (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:56232:20)
    at Object.invokeGuardedCallbackImpl (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:8899:16

The login screen for Spotify does not open, and only the first print statement comes through here:

// Initialize the session
        console.log("send authorization request");
        SpotifyAuth.authorize(config).then(newSession => {
            console.log("receive new session");
            SpotifyRemote.connect(newSession.accessToken);
            this.setState((state) => ({
                ...state,
                token: newSession.accessToken
            }));
            console.log(newSession.accessToken);
        });

I tried to look through the code for this library to see what might be causing this, but couldn't find anywhere that would throw this error within SpotifyAuth.ts. Do you have any idea what might be wrong in my configuration/code that would be causing this? I couldn't find anything similar online.

Thank you.

@fickleEfrit
Copy link
Author

@cjam Would really appreciate some guidance here, if you have any idea what may be causing this issue.

@cjam
Copy link
Owner

cjam commented Oct 31, 2021

Hey @fickleEfrit.

Sorry have been swamped at work. Are you still having issues with this? Can I see your config? Also. Did you make sure to setup the URI handlers for your app? I think there is some notes about it in the docs, but on iOS you must setup not only the handler for your app but also the outgoing URL for Spotify. If the Spotify app doesn't open up that is where I would start. Double check the setup notes on the Spotify sdk docs.

@fickleEfrit
Copy link
Author

No worries @cjam, thank you for checking! I am attempting to connect in Android for now, rather than iOS. Also, I believe the URI handlers are properly setup as when authenticating with react-native-app-auth I am able to successfully open Spotify and receive the auth token with the same callback url.

However, I am unable to simply pass that token into the spotify remote since it won't let me run any commands without having already run auth (even if I pass the token in). I looked through the docs and there appears to be a no auth version of the remote, but I couldn't see how that corresponded to the react native library. I'm new to React Native, so not sure if that just hasn't been added yet or if I am overlooking a method to run the remote sdk with an outside authorization source.

Here is my config:

const config: ApiConfig = {
            clientID: "omitted",
            redirectURL: "com.testtunesstudentapp://oauthredirect",
            tokenRefreshURL: spotifyRefreshURL,
            tokenSwapURL: spotifySwapURL,
            scopes: [ApiScope.AppRemoteControlScope, ApiScope.UserFollowReadScope],
            playURI,
            showDialog: showDialog,
        };

@cjam
Copy link
Owner

cjam commented Nov 2, 2021

@fickleEfrit Which version of this library are you using?

@fickleEfrit
Copy link
Author

@cjam Looks like I'm currently using 0.3.2. I will try bumping to the latest version and update you on whether that works.

@fickleEfrit
Copy link
Author

I tried running on 0.3.10 (in fact I ran yarn upgrade and made sure all libraries are on the latest version now) but am still getting the same issue. The loading screen appears, but immediately closes before showing me any Spotify stuff, and I get the same error about the authentication service being unavailable. Additionally, the endpoints for the sample token swap server never get hit, as it never gets to that point. I'm really wondering what is throwing this error, since there's just about no results for it on the web.

@cjam
Copy link
Owner

cjam commented Nov 11, 2021

What version of Android are you using @fickleEfrit ? There was issue #169 which added some docs for those using Android 11 and above. Perhaps you could take a look.

@fickleEfrit
Copy link
Author

fickleEfrit commented Nov 11, 2021

I'm on an emulated Pixel 2 on API level 29, Android 10.

@shaurya2612
Copy link
Contributor

Facing the same issue @cjam

@cjam
Copy link
Owner

cjam commented Nov 22, 2021

Hmm which version of this package? There is a prerelease in @next that might be worth a try if you haven't.

@mickaeloak
Copy link

@cjam I just started using the lib and I'm getting that issue as well on Android (Samsung Galaxy S9 - Android 10)
Actually since my user did not accept the Spotify App permissions yet, on iOS I get that modal in the Spotify app which asks to grant access. On Android (same Spotify account), I'm directly redirected to my app with that AUTHENTICATION_SERVICE_UNAVAILABLE error.

My lib version is 0.3.11-2 (next)

Thanks!

@mickaeloak
Copy link

@fickleEfrit did you find a solution? I'm totally blocked by this :(

@cjam
Copy link
Owner

cjam commented Dec 8, 2021 via email

@mickaeloak
Copy link

@cjam I'm not a Java developer but I tried digging deeper and it seems the error really happens inside of the Spotify app after calling AuthorizationClient.openLoginActivity(getCurrentActivity(), REQUEST_CODE, request);
It's really too bad all the is from the response coming from the Spotify SDK AuthorizationClient is this:

image

Would you know how to debug this further?

@fickleEfrit
Copy link
Author

@mickaeloak that looks like a good find. Not sure how to debug further. I'm still partially blocked by this as well, ended up going with some hacky usage of the web API but would very much prefer to switch to this module if this issue is ever resolved.

The Spotify docs https://spotify.github.io/android-sdk/auth-lib/docs/ don't have any mention of this particular error code, and it only mentions that in order to make auth flow work

  <activity
          android:name="LoginActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar" />

needs to be added to the manifest. My manifest has similar:

<activity
            android:name="com.spotify.sdk.android.authentication.LoginActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">
        </activity>

Could there be an issue with how the manifest is set up per the setup guide on react-native-spotify-remote?
It also looks like the AuthCallbackActivity portion of the manifest as mentioned in the docs for react-native-spotify-remote are no longer mentioned in the Spotify auth lib, unless that's coming from elsewhere in the documentation, if that could be related?

@cjam
Copy link
Owner

cjam commented Dec 19, 2021

I'll have to try this on the example, I've been absolutely swamped at work and have no time to be able to spend on this project as of late. I appreciate the attempts to debug the Java code tho @mickaeloak.

Out of curiosity, @mickaeloak / @fickleEfrit where are you located? There were some people on here with issues that came up as a result of Spotify changing some login / auth policies with respects to geo-location. I doubt that's the case here but just curious.

The issue I was referring to: #165 (comment)

@mickaeloak
Copy link

mickaeloak commented Dec 19, 2021

@cjam thanks! No worries if you can't debug this now, you saved me tons of time already with this library.
I am located in Montreal, Canada
But like you said, I doubt that is the same issue since everything works fine on iOS

@deng-yc
Copy link

deng-yc commented Dec 20, 2021

Same problem, I solved it after adding "Android packages" to the spotify dashboard

@fickleEfrit
Copy link
Author

@cjam I'm in the US.

@deng-yc Did you add the android package for your application or for the react-native-spotify-remote package?

@fickleEfrit
Copy link
Author

@deng-yc I added only my own application, and it is now working. Thanks so much for the fix! @mickaeloak @shaurya2612 definitely give this a try. Going to close the issue now.

@mickaeloak
Copy link

@fickleEfrit Mine was already added, so that doesn't solve it on my side. I doubled checked the values too.

@fickleEfrit
Copy link
Author

@mickaeloak should I reopen the issue then? Sorry to hear that didn't work for you!

@thomasdelobel
Copy link

thomasdelobel commented Apr 21, 2022

Thank you very much all, you saved me a lot of time ! 🙏

It was still raising the AUTHENTICATION_SERVICE_UNAVAILABLE error on Android only, even with the "Android Packages" section well filled in my Spotify app's dashboard, until I gave a try, few days ago, to write my SHA-1 fingerprints uppercase (as it is shown in the placeholder) instead of lowercase, and it did the trick.

So, fill your SHA-1 fingerprints 👉 uppercase 👈 in the Android Packages section of your Spotify app.

@mickaeloak
Copy link

@thomasdelobel wow thank you so much for this. The all caps thing was my issue 😐
Owe you a beer 🍺

@creativeedge
Copy link

Gettin same error AUTHENTICATION_SERVICE_UNAVAILABLE. Is this a solution that solves everyone’s problem with Spotify Auth just by using all caps for SHA-1 fingerprints?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants