Private user auth access for backend services

Hi,

 

I'm writing a backend Python service (using Spotipy) which will receive HTTP requests and post things, etc, and it will be deployed in a docker container in a server somewhere off my machine. It needs access to certain scopes that require auth i.e. `"user-read-private", "user-read-email"`. 

 

From what I've read of the docs, 'Authorization Code Flow' *should* be the way to go, but from what I can tell, this requires *browser* access so a user can authenticate with Spotify.

 

Because I am writing a backend server, this will not work, there will be no browser access.

 

It's worth noting that I don't need random users giving access -- I'm providing my own client ID and token, and it will do everything on my account.

 

I've been googling around for this problem and I am really struggling to understand, all the answers are too brief or lack the detail to really explain it, so please bear with me and spell it out, if you can 😅 A couple of example posts that *seem* similar:

 

- https://community.spotify.com/t5/Spotify-for-Developers/Authorization-code-flow-on-backend-server/td-p/5651248

- https://community.spotify.com/t5/Spotify-for-Developers/Central-OAuth2-0-Authorization-on-the-Backend-Side-using-PHP-and/td-p/5417820

 

As I mentioned, these answers are pretty brief, are there docs that specifically address these workflows and show examples of how it should work?

 

Thanks

Child Item
Child Item
Child Item

Accepted answers

Hi Terpal,

Using Spotipy is straightforward! Just make sure you're using the same redirect URL on both your development machine and server. Run it on your development machine first, then copy the generated .cache file to your server.

Note: The .cache file will be located in the directory from which you're running the script. If your script is located at /home/app but you run it from /home, the .cache file will be in /home. The same applies to your server—copy it to the directory from which you'll run the script there.

Once that’s done, everything should work smoothly.

 

Let me know if this helps or if you have any further questions!

All comments

Hi Terpal,

Using Spotipy is straightforward! Just make sure you're using the same redirect URL on both your development machine and server. Run it on your development machine first, then copy the generated .cache file to your server.

Note: The .cache file will be located in the directory from which you're running the script. If your script is located at /home/app but you run it from /home, the .cache file will be in /home. The same applies to your server—copy it to the directory from which you'll run the script there.

Once that’s done, everything should work smoothly.

 

Let me know if this helps or if you have any further questions!

Sorry for the slow reply, took a while before I could test it, but magnifique! That works, I just copied over the .cache after locally authenticating and it worked! Cheers Ximzend

Child Item
Child Item