wagnerdelima / drf-social-oauth2

drf-social-oauth2 makes it easy to integrate Django social authentication with major OAuth2 providers, i.e., Facebook, Twitter, Google, etc.
https://drf-social-oauth2.readthedocs.io/en/latest/
MIT License
271 stars 34 forks source link

Google oauth2 #138

Closed PrasanthPerumalsamy closed 1 year ago

PrasanthPerumalsamy commented 2 years ago

google oauth2 not providing access tokens for newly created id's only providing id_token

here is the link https://developers.google.com/identity/sign-in/web/backend-auth

Please update the package...

SukiCZ commented 1 year ago

Hi @PrasanthPerumalsamy I was facing same issue and fixed that with a custom Backend that inherits from GooglePlusAuth.

from social_core.backends.google import GooglePlusAuth

class GoogleIdentityBackend(GooglePlusAuth):
    name = "google-identity"

    def user_data(self, access_token, *args, **kwargs):
        """Don't care about the `id_token`"""
        response = self.get_json(
            # https://oauth2.googleapis.com/tokeninfo
            "https://www.googleapis.com/oauth2/v3/tokeninfo",
            params={"id_token": access_token},
        )
        self.process_error(response)
        return response

I believe this issue is more related to python-social-core

MehdiDRISSIB commented 1 year ago

I got the same issue. google provide only id_token and not accesstoken. Any help please @wagnerdelima How to convert token in this case ? When I try to convert-token with id_token I got the error:

{"message":{"error":"access_denied","error_description":"Your credentials aren't allowed"}}

The credentials are corrects in my post request except the token

SukiCZ commented 1 year ago

@MehdiDRISSIB Have you tried customize the GooglePlusAuth? The customization I'd posted works for me.

MehdiDRISSIB commented 1 year ago

@SukiCZ Many thanks for your feedback. As I use Facebook login also in my app which works well, I would like keep the same api for both which is convert-token. If it's not fixed in the package, yes I would have to go through another way and probably try your view. I will give a feedback if I try your solution

wagnerdelima commented 1 year ago

Hi guys. I didn't understand the problem per se. I will close this issue and you can create another based on a template that makes it easier to understand.

Thanks.