RealmTeam / django-rest-framework-social-oauth2

python-social-auth and oauth2 support for django-rest-framework
MIT License
1.06k stars 191 forks source link

Which access token do I pass in for Google-Oauth2 post sign up? #222

Closed kaseyb002 closed 4 years ago

kaseyb002 commented 4 years ago

I've successfully signed in with a user through Google Sign In, and it created a user account with their email and name pre-populated.

But when I send subsequent requests I get a 500 back. The problem seems to occur when social-auth tries to talk to Google. Here's the key line in the stack trace:

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.googleapis.com/oauth2/v3/userinfo

I'm sending Authorization=Bearer google-oauth2 <access_token> in my auth header.

I am using the access token created by the social-auth framework (one that's 25-ish characters).

However, when I replace that token with the access token returned by Google (the super long one), everything works.

Is this the correct syntax for subsequent requests?

curl -H "Authorization: Bearer <backend_name> <backend_token>" http://localhost:8000/route/to/your/view

Edit: I figured it out. You need to remove the <backend_name> and just pass in Bearer <backend_token>. I guess I missed that somewhere in the docs.