auth0 for django admin

Hi,

I am trying to use auth0 based login for django admin, I can see that auth0 part works I can even find the proper user of my db. then I tried to log in the user with auth’s login(request, user) but seems that is not working, I end up anonymous user in request and end up looping in login → callback … etc


def login(request):
    print("IN LOGIN" , request.user)
        return oauth.auth0.authorize_redirect(
            request, request.build_absolute_uri(reverse("callback"))
        )

def callback(request):
    print("IN CALLBACK")
    print(request.session)
    token = oauth.auth0.authorize_access_token(request)
   # oauth is form authlib package

    user = authenticate(auth_id=token.get('userinfo').get('sub'))
    print("USER = ", user) # I get proper user 

    if user:
        request.user = user
        auth_login(request, user)
       # from django.contrib.auth import login as auth_login
        print("AFTER AUTH LOGIN")
      
        return redirect(request.build_absolute_uri(reverse("admin:index")))
    else:
        return redirect(request.build_absolute_uri(reverse("login")))

Here is my urls:

urlpatterns = [
    path("", views.index, name="index"),
    path("login", views.login, name="login"),
    path("logout", views.logout, name="logout"),
    path("callback", views.callback, name="callback"),
    path('admin/login/', views.login, name="login"),
    path('admin/', admin.site.urls),
...