How to Obtain the OAuth2 Access Token for Spotify API After Social Login Integration?

I’m currently trying on integrating the Spotify API to create a playlist management dashboard.

After we login through Spotify, how can I obtain the OAuth2 access token? I already try different way, such as accessing frappe.session, but still doesn’t know how to get the access token and the refresh token, I need this token to interact with the Spotify API, such as creating playlists and managing user data, and creating their Virtual Doctype. is there any way without customizing the oauth2 code?

2 Likes

You cannot use Social Login Key token, it is restricted or only identity scoped token

Use Connected App, it stores User’s token or even client_credentials token in Token Cache. This will be maintained and auto refreshed as needed.

This feature is used in OAuth2 based Email Account. You can refer the code from there.

https://docs.frappe.io/framework/user/en/guides/app-development/connected-app

in brief,

# First call or call when no valid token is found
app = frappe.get_doc("Connected App", "abcd")
app.initiate_web_application_flow()

# once token is in cache
token = app.get_active_token() # for frappe.session.user
token = app.get_active_token("user@example.com") # for user@example.com
2 Likes

This is works but my access_token become like this
‘access_token’: ‘*******************************************************************************************************************************************************************************************************************’

When I use this token in my request, it results in the following error:
{‘error’: 400, ‘message’: ‘Only valid bearer authentication supported’}

That’s a password field. Use doc.get_password("access_token")

1 Like

Thanksssss