Spotify Redirect Issues

I’ve had Spotify configured and working for a long time. Recently, I encountered some issues, so I removed the configuration and tried to re-add it, but I have faced constant problems.

I got my Client ID and Client Secret etc and used https://my.home-assistant.io/redirect/oauth but after entering, I get the following:

I

clicking link account gives me:

I assumed My Home Assistant might be disabled - So I used my DuckDNS address (https://myaddress.duckdns.org:8443/auth/external/callback) and get the error INVALID_CLIENT: Invalid redirect URI

Where am I going wrong, please?

I haven’t changed any network settings or made any adjustments within HomeAssistant. To add (if relevant) I also use HA cloud.

@Jakesa
I recommend the following instructions to users of my SpotifyPlus Integration when they experience issues like this. Hope it helps!

OAuth Redirect Errors - INVALID_CLIENT: Invalid client

This error can occur sometimes when initially installing (or reinstalling) the SpotifyPlus Integration (it can also occur for the HA Spotify Integration). I believe it’s either due to a malformed Redirect URI value in the Spotify Developer Application details, or when something doesn’t get cleaned up correctly during the integration uninstall process.

To fix this, you need to do ALL of the following:

  1. verify that the https://my.home-assistant.io/redirect/oauth uri is listed in the Spotify Developer Application settings “Redirect URIs” list. This is an internal url that Home Assistant uses to intercept the OAuth2 request redirect result. The entry must be listed exactly as it is spelled (case-sensitive), and without the ending slash.
  2. Go to the Home Assistant Application Credentials settings (under Settings \ Devices, click on 3 vertical dots menu in upper right and select Application Credentials) and see if it created any OAuth application credentials related to SpotifyPlus (or Spotify if you’re installing HA Spotify). If so, delete them.
  3. Open the Spotify Web Player in a new browser window and logout of Spotify. This will force you into a logon screen the next time you try to authorize the OAuth request.

Hi, thank you for your advice. Unfortunately, I’m still encountering the same issue after following the steps.

It directs me to Spotify to log in and instructs me to link Home Assistant after logging in, but then I receive:

It could be an issue with the way you are linking your account. I took the following out of the SpotifyPlus Integration Install Instructions wiki doc.

Note the " IMPORTANT " parts of the doc below. Note that I use http://homeassistantvm:8123 in my environment. Are you using http://homeassistant.local:8123? or https://homeassistant.local:8123? or do you have a custom url? Note that you should NOT be using your public facing url to do this (has to be the local HA url as mentioned above).

Note that you may also need to repeat the deletion of the Application Credentials mentioned earlier in order to retry.

Step 4e - Home Assistant Link Account

Click on Link Account (see Figure 4e) to allow Home Assistant to link the OAuth2 Application Credential to Spotify.

IMPORTANT - Note the hi-lited URL prefix value in the Figure 4e example (top of the page in the URL); this should match the Redirect URI value (e.g. https://my.home-assistant.io/redirect/oauth) that you entered for the Spotify Developer Application in Step 2b - Create Application. If it does NOT match, then you will need to modify the Spotify Developer Application settings and add it as an allowed Redirect URI value. Note that you can specify more than one Redirect URI value in the Spotify Developer Application settings. You can adjust the Spotify Developer Application settings after this step is complete if need be.

IMPORTANT - Note the Your Instance URL value in the Figure 4e example (toward the bottom); this should match the url that you use to access Home Assistant. You may need to adjust the http:// to https:// if you access your instance of Home Assistant via Secure Sockets Layer (SSL). Click the pencil icon to the right of the Your Instance URL url value to adjust the entry if necessary.

Figure 4e - Home Assistant Link Account Form

I use https://serverURL:8123 I noticed on the 'link to home assistant page my instance URL was not matching. I edited this as you described and no longer get the same error as before.

However, I am now getting the error Error while obtaining access token :

I deleted credentials and logged out of Spotify before attempting this.

@Jakesa
Progress is good. :slight_smile:

Rerun the process, including removing App Credentials / Spotify Logout. You might try using the SpotifyPlus Integration Install Instructions, but just substitute the Spotify Integration (or just install SpotifyPlus if you like - it’s a direct replacement for the HA Spotify integration).

When you get to the “Link Account to Home Assistant?” screen, take a screen capture of that window, including the browser url (like my Figure 4e picture in the previous reply). I need to know what url prefix is being used for the request, as well as what the instance url is.

Also post a screen capture of your Spotify Developer App settings (don’t need the client id). I’m interested in what the “Redirect URIs” value looks like. It will look similar to this:

Sorry this maybe a silly question but does SpotifyPlus work with Spotcast?

Here is the screen capture:

I noticed my HA instance URL was not in the Spotify dev account redirect URLs like the image you provided so I tried it with that too but I still got the same error

Error while obtaining access token

@Jakesa

Regarding the Spotify Developer App Redirect URIs settings:

  • https://192.168.1.10:8123 is not needed, and should be removed from the Spotify Developer App Redirect URIs settings
  • https://my.home-assistant.io/redirect/oauth matches the browser url for the “Link Account to Home Assistant?” page, which is correct.
  • Note that the http://127.0.0.1:8090/ and http://127.0.0.1:8080/ (localhost) entries in my Spotify Developer App settings are used to test other processes outside of Home Assistant, so you will not need those 2 entries.

Regarding the https://192.168.1.10:8123/:

  • is this the url that you use to access your HA instance? or do you use http://192.168.1.10:8123/ (e.g. not HTTPS)? If you are using https://192.168.1.10:8123/, then I would retry the process with the http://192.168.1.10:8123/ url. It might be running into an SSL certificate issue when trying to use the HTTPS url.

Regarding Spotcast

SpotifyPlus does not require Spotcast to work. It uses it’s own methods of re-activating Google Cast devices that require it.

You can keep Spotcast installed if it is used for other things if you like; it will not interfere with SpotifyPlus, or vice versa. You can also have the regular HA Spotify integration installed as well, if you want to compare it to SpotifyPlus.

Thank you for this help.

Yes I use https://192.168.1.10:8123/ to access my HA instance.

when I try the process with http://192.168.1.10:8123/:

I get the following:

@Jakesa
It appears the latest http://192.168.1.10:8123/ was a step back, and exhibits the same behavior as the https://homeassistant.local:8123/.

Do you have the homeassistant: key specified in your configuration.yaml file? If so, what do you have specified for the internal_url: value? Your homeassistant: key should look something like this:

homeassistant:
  external_url: 'https://xxxxxxx.duckdns.org'
  internal_url: 'http://192.168.1.248:8123'
  allowlist_external_dirs:
  ...

If you DO have an internal_url: value, then use that value to access your Home Assistant image from your browser of choice. In the example above, I use http://192.168.1.248:8123 to access my HA on the internal network. I also use the Google Chrome browser myself, but any browser should work.

With that said, let’s try adding the HA Application Credentials manually (instead of through the Spotify integration install process).
Use the following:

***** IMPORTANT *****
You will want to clear any previous Application Credentials again, as well as log out of Spotify.

Also restart Home Assistant and clear your browser cache (including files, cookies, and images) prior to executing the following steps.

Step 3 - Home Assistant Application Credential(s)

We are now ready to add Home Assistant Application Credentials for each of the Spotify Developer Applications that were created in Step 2.

Go to the Application Credentials page to list any existing OAuth2 application credentials, as well as define new ones. This is located under Settings \ Devices & Services \ Application Credentials (have to click the 3 dots menu in the upper right corner).

Step 3a - Add Application Credential(s)

Click the Add Application Credentials button to add a new credential.

Fill in the Credential Form fields (see Figure 3a):

  • Integration: Spotify (select from dropdown list).
    Note - if you don’t see the Spotify entry in the list, then it denotes that a problem occurred with the integration installation (e.g. failed, HA was not restarted, browser cache was not cleared, etc).
  • Name: Enter a name for the credential. I would suggest using “Spotify FIRST LAST” for this value, with FIRST being the Spotify user first name and LAST being the Spotify user last name (e.g. “Spotify John Smith”).
  • OAuth client ID: The Spotify Developer App Client ID value for the Spotify User.
  • OAuth client secret: The Spotify Developer App Client Secret value for the Spotify User.
  • click Add to add the credential.

Figure 3a - Home Assistant Application Credentials Form

For multiple Spotify User support, repeat the above step for each of the Spotify Developer Applications that you created. Once you are done, your Application Credentials list should contain all of your Spotify credential entries (see Figure 3b).

Figure 3b - Home Assistant Application Credentials List

If the above worked, then you are now ready to add the Spotify integration. When you add the integration, it should allow yo uto select a pre-existing Application Credential to use with the Spotify instance being installed (assuming the above steps worked to add the credential).

@Jakesa
Did the above reply get this working for you? Please let me know either way.
Thanks