Package: django-google-integrations
Django Google IntegrationsDjango Google Integrations is a package that allows integrating Google OAuth into your Django application. It is build as a thin wrapper around thegoogle-auth-oauthlib.
You can view the full documentation athttps://PrimedigitalGlobal.github.io/django-google-integrations/FeaturesProvides following APIs:Authorization URL API:It generates googleauthorization-urlwhich redirects user to Google's Authorization Server to request consent from resource owner.Authorize Web API:Exchange authorization code for access token.Talk to resource server with access token and fetch user's profile information.Authorize IOS Token API:Verifies an ID Token issued by Google's OAuth 2.0 authorization server.Fetch user details from decoded token.DependenciesPython >= 3.6Django >= 2.2.17djangorestframework >= 3.10.2google-api-python-client >= 2.9.0google-auth-httplib2 >= 0.1.0google-auth-oauthlib >= 0.4.1SetupYou can install the library directly from pypi using pip:$ pip install django-google-integrationsGenerate Google Client ConfigEdit your settings.py file:INSTALLED_APPS = (
        ...
        "django_google_integrations"
)

# Django Google Integrations Config
GOOGLE_CONFIG = {
    "CLIENT_CONFIG_JSON": "[Google Client Config Json]",
    "CLIENT_ID": "[Google Client ID]",
    "CLIENT_SECRET": "[Google Client Secret]",
    "SERVICE_ACCOUNT_SCOPES": [
            "openid",
            "https://www.googleapis.com/auth/userinfo.email",
            "https://www.googleapis.com/auth/userinfo.profile",
        ],
    "REDIRECT_URI": "http://localhost:3000/google/auth/callback",
    "RESPONSE_HANDLER_CLASS": "example.testapp.google_response_handler.GoogleSigninResponseHandler",
}Create Response Handler Class and update path inGOOGLE_CONFIGfrom django_google_integrations.services import GoogleResponseHandler

class GoogleSigninResponseHandler(GoogleResponseHandler):
    def handle_fetch_or_create_user(self, flow, google_user_data):
        email = google_user_data.get("email", None)
        user = get_user_by_email(email)
        is_created = False
        if not user:
            user_dict = {
                "first_name": google_user_data.get("given_name", ""),
                "last_name": google_user_data.get("family_name", ""),
                "password": None,
            }
            user = create_user_account(email, **user_dict)
            is_created = True

        extra_context = {"is_created": is_created}
        return user, extra_context

    def generate_response_json(self, user, extra_context):
        response = AuthUserSerializer(user)
        return response.dataNOTE:AuthUserSerializerused in above ref. could be created as per app's functionality and contain fields which needs to be sent in response of authorization.Following service methods are used in above code ref. which could be created as per app's functionality:get_user_by_emailcreate_user_accountUpdate URLsfrom django_google_integrations.apis import GoogleAuthViewSet

default_router = routers.DefaultRouter(trailing_slash=False)
default_router.register("auth/google", GoogleAuthViewSet, basename="google-auth")Code of ConductIn order to foster a kind, inclusive, and harassment-free community, we have a code of conduct, which can be foundhere. We ask you to treat everyone as a smart human programmer that shares an interest in Python and Django Google Integrations with you.