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

How to set up redirect URIs? #1

Open
Chaphasilor opened this issue Oct 14, 2022 · 13 comments
Open

How to set up redirect URIs? #1

Chaphasilor opened this issue Oct 14, 2022 · 13 comments

Comments

@Chaphasilor
Copy link

Chaphasilor commented Oct 14, 2022

I can't find documentation on this and my attempts so far didn't work out.

I've set up the API server on my server, accessible on port X. I get the default response when navigating to /api as well, so that seems to work as expected.

I've configured applications for both Spotify and Deezer on their respective dashboards and used the IDs and keys for the necessary environment variables.

Now I'm stuck at the redirect URIs. I've configured the Spotify one to :X/api/spotify/auth, which I took from here.
In that function it seems like the redirect URI is hard-coded to the heroku instance, although I could be wrong.
I did the same for deezer, and this time there was no hard-coded backlink in the auth function.

Now, when I go to ultrasonics and try to authenticate with Spotify or Deezer, I always end up with an error saying "INVALID_CLIENT: Invalid redirect URI" (for Spotify) or "You must specify a valid redirect URI" (for Deezer).
But I have a redirect URI set up on the developer dashboard for both applications.
Are IPs not allowed for these redirect URIs? Given that the client is being redirected and has access to that local IP, it should technically work, right?

Some more documentation on the matter would be really helpful if we are to migrate away form the heroku-hosted API :)

Edit: Looking at the URL that is used to send the authentication request (to Spotify's/Deezer's website), it seems like the heroku instance URI is hard-coded for both services. Could this be changed please, for example by adding an environment variable for it?

@Chaphasilor
Copy link
Author

Chaphasilor commented Oct 14, 2022

These would be the places where the environment variable is needed:

Deezer:

"redirect_uri": "https://ultrasonics-api.herokuapp.com/api/deezer/auth",

Spotify:

"redirect_uri": "https://ultrasonics-api.herokuapp.com/api/spotify/auth",

"redirect_uri": "https://ultrasonics-api.herokuapp.com/api/spotify/auth"

@Chaphasilor
Copy link
Author

I've managed to patch the python files to load a base URL for the API from an environment variable and use that for the redirect URIs. Spotify authentication is now working, but for Deezer I'm getting the following error:

Access Denied
You don't have permission to access "http://connect.deezer.com/oauth/auth.php?" on this server.

My request looks like this:
https://connect.deezer.com/oauth/auth.php?app_id=<redacted>&redirect_uri=http://<IP>:<X>/api/deezer/auth&perms=basic_access,offline_access,manage_library,delete_library, which aligns with the documentation at https://developers.deezer.com/api/oauth. Any idea what I'm missing here?

Once I manage to get this working I'd be happy to create a PR for this :)

@Chaphasilor
Copy link
Author

Chaphasilor commented Oct 23, 2022

Okay, it seems like Deezer's Application domain doesn't support plain IP addresses, whereas Spotify has no problems with that.
So in order to authenticate with Deezer, you need to either use an actual domain for the API server, or use mDNS in order to replace you IP with an equivalent domain name...

Edit: it seems like mDNS resolution does not work from the ultrasonics python server / docker image, so you'll have to use the actual IP there (in the ultrasonics settings on the website), otherwise the initial auth will work, but renewing tokens will not, because for that the ultrasonics server has to make a request to the ultrasonics-api server :)

@MauliQT
Copy link

MauliQT commented Nov 7, 2022

Hi i am trying to setup the api rn, but i cant access the spotify auth site and I don't know how to do it, and you said you got it running, could you please help me out

@Chaphasilor
Copy link
Author

  1. Go here and log in with your Spotify Account: https://developer.spotify.com/dashboard/
  2. Create a new application, name it e.g. "ultrasonics"
  3. In your app's settings, set the redirect URL to the URL where your ultrasonics-api server is reachable

This might not be enough to help you out, if you still have problems I can send you some screenshots once I get back to my PC :)

@MauliQT
Copy link

MauliQT commented Nov 7, 2022

Does it have to be a public ip or can i do it just with my local ip. And if not is it possible to reverse proxy the api through nginx
Edit: tried routing it trough nginx it works, but still cant auth spotify
Screenshot 2022-11-07 at 16 36 12
Screenshot 2022-11-07 at 16 37 03
Screenshot 2022-11-07 at 17 06 19

Edit: changed Domain from music.fjcx764.uk to music.fjcx764.uk/api

@Chaphasilor
Copy link
Author

Chaphasilor commented Nov 7, 2022

Yeah local IPs should work for Spotify. What you seem to be missing is the correct path for the redirect URL, it should be http://192.168.2.124:8003/api/auth/spotify and not just http://192.168.2.124:8003 :)

@MauliQT
Copy link

MauliQT commented Nov 7, 2022

oh with the auth/spotify aswell

@MauliQT
Copy link

MauliQT commented Nov 7, 2022

still doesn't work, could you do some screenshots of your setup

@MauliQT
Copy link

MauliQT commented Nov 8, 2022

Nvm works now just had to restart everything

@Chaphasilor
Copy link
Author

Great!

@haudankaivajasi
Copy link

Okay, I'm just baffled now as I'm trying to get the self hosted ultrasonics-api to work on docker. I'm running both on my server and used the given docker commands to run the containers with api keys and secrets.

I have entered ultrasonics-api URL as: http://server_ip:8003/ in the Ultrasonics settings screen and added http://server_ip:8003/spotify/auth/request to Spotify api Redirect URIs. I also tried https://ultrasonics-api.mydomain.com/ in Ultrasonics settings and in https://ultrasonics-api.mydomain.com/spotify/auth/request in Spotify. I've restarted both Ultrasonics and the api container after changes just to be sure.

Every time I try to authenticate with Spotify it gives me a "Not found" page.

Is there a problem with the api container or what might cause this behavior?

@haudankaivajasi
Copy link

Okay, I'm just baffled now as I'm trying to get the self hosted ultrasonics-api to work on docker. I'm running both on my server and used the given docker commands to run the containers with api keys and secrets.

I have entered ultrasonics-api URL as: http://server_ip:8003/ in the Ultrasonics settings screen and added http://server_ip:8003/spotify/auth/request to Spotify api Redirect URIs. I also tried https://ultrasonics-api.mydomain.com/ in Ultrasonics settings and in https://ultrasonics-api.mydomain.com/spotify/auth/request in Spotify. I've restarted both Ultrasonics and the api container after changes just to be sure.

Every time I try to authenticate with Spotify it gives me a "Not found" page.

Is there a problem with the api container or what might cause this behavior?

Ok, I got it to work.
First I had to add this modified spotify.py file to the container with -v /file/location//ultrasonics/api/spotify.py:/app/ultrasonics_api/services/spotify.py and also add -e SPOTIFY_REDIRECT_URI=http://my_internal_ip:8003/api/spotify/auth \ to the docker command when running the container. This way it won't redirect straight to heroku app.

Then I added http://my_internal_ip:8003/api/ to ultrasonics settings via the web interface. Lastly I added http://my_internal_ip:8003/api/spotify/auth to the Spotify app's "Redirect URIs" section.

I hope this helps someone struggling to get this to work!

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

Successfully merging a pull request may close this issue.

3 participants