HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/aigenerator/venv/lib64/python3.12/site-packages/social_core/backends/gae.py
"""
Google App Engine support using User API
"""

from google.appengine.api import users

from ..exceptions import AuthException
from .base import BaseAuth


class GoogleAppEngineAuth(BaseAuth):
    """GoogleAppengine authentication backend"""

    name = "google-appengine"

    def get_user_id(self, details, response):
        """Return current user id."""
        user = users.get_current_user()
        if user:
            return user.user_id()

    def get_user_details(self, response):
        """Return user basic information (id and email only)."""
        user = users.get_current_user()
        return {
            "username": user.user_id(),
            "email": user.email(),
            "fullname": "",
            "first_name": "",
            "last_name": "",
        }

    def auth_url(self):
        """Build and return complete URL."""
        return users.create_login_url(self.redirect_uri)

    def auth_complete(self, *args, **kwargs):
        """Completes login process, must return user instance."""
        if not users.get_current_user():
            raise AuthException("Authentication error")
        kwargs.update({"response": "", "backend": self})
        return self.strategy.authenticate(*args, **kwargs)