Announcements

Help Wizard

Step 1

NEXT STEP

Private user auth access for backend services

Solved!

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...

https://community.spotify.com/t5/Spotify-for-Developers/Central-OAuth2-0-Authorization-on-the-Backen...

 

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

Reply

Accepted Solutions
Marked as solution

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!

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

View solution in original post

2 Replies
Marked as solution

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!

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

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

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random