Session based django social

I'm using social-auth-app-django for authenticate with google. The process working fine and the user is register in the DataBase. The problem begins when I'm trying to login the users automatically when they register with Google. The users keeps to be unauthenticated in the session. Here is my current configurations using social-auth-app-django and djoser: settings.py:

AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend'
) 

DJOSER = {
    'PASSWORD_RESET_CONFIRM_URL': 'password/reset/confirm/{uid}/{token}',
    'PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND': True,
    'SEND_CONFIRMATION_EMAIL': True,
    'ACTIVATION_URL': 'activate/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,
    'CREATE_SESSION_ON_LOGIN': True,
    'SOCIAL_AUTH_TOKEN_STRATEGY': 'members.social_token.TokenStrategy',
    'SOCIAL_AUTH_ALLOWED_REDIRECT_URIS': [
        'http://localhost:3000/google'
    ],
    'SERIALIZERS': {
        'current_user': 'members.serializers.UserCreateSerializer',
    }

I think the most relevant part is the SOCIAL_AUTH_TOKEN_STRATEGY. Where the members.social_token.TokenStrategy is:

from django.contrib.auth import login
from django.http import HttpRequest
from django.conf import settings

from importlib import import_module
class TokenStrategy:
    @classmethod
    def obtain(cls, user):
        from rest_framework_simplejwt.tokens import RefreshToken
        from six import text_type

        refresh = RefreshToken.for_user(user)
        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        session_key = None
        request.session = engine.SessionStore(session_key)
        
        login(
            user=user,
            request=request,
        )
        user.is_active = True
        return {
            "access": text_type(refresh.access_token),
            "refresh": text_type(refresh),
            "user": user,
        }

I can see that the sessionid and the csrftoken is been saved in the browser cookies and in the TokenStrategy the request.user.is_authenticated equals to true. My problem is that for all the following requests the value of the request.user.is_authenticated keeps been false (in the swagger for instance). Any help?

Back to Top