flavors / django-graphql-social-auth

Python Social Auth support for Graphene Django
https://pypi.python.org/pypi/django-graphql-social-auth
MIT License
109 stars 33 forks source link

Question: How to use an idToken rather than an accessToken? #12

Open dllabs opened 5 years ago

dllabs commented 5 years ago

Google's docs for Android-based OAUTH2 authentication say that we should send an idToken rather than an accessToken to our backend server.

How do you do that using Graphene Social Auth?

The only docs/examples I've found use access tokens. For instance:

mutation SocialAuth($provider: String!, $accessToken: String!) {
  socialAuth(provider: $provider, accessToken: $accessToken) {
    social {
      uid
      extraData
    }
  }
}

I imagine I can use Graphene Social Auth as is, by exchanging my idTokens for accessTokens in my Android client, but I'd rather do that server-side as Google recommends, just by sending in the idToken to the server and then have Graphene Social Auth exchange it for an accessToken and then do its stuff.

thanks!

John

dllabs commented 5 years ago

I've figured out that the GooglePlus backend can work if I comment out the line in _graphql_social_auth/socialcore/backends/google.py that uses the accessToken, thereby forcing it to use the idToken instead, as follows:

def user_data(self, access_token, *args, **kwargs):
    # if 'id_token' not in self.data:
    #     return super(GooglePlusAuth, self).user_data(access_token, *args,
    #                                                  **kwargs)
    response = self.get_json(
        'https://www.googleapis.com/oauth2/v3/tokeninfo',
        params={'id_token': access_token}
    )
    self.process_error(response)
    return response

Better though would be to pass 'id_token' into self.data, so I don't have to comment out that line. How do I get 'id_token' into self.data in a django-graphql-social-auth mutation?

cheers

John

codalprashant commented 3 years ago

any updates on the above issue mentioned ?