How to manually authenticate after get django user?

marman picture marman · Jan 21, 2011 · Viewed 9.7k times · Source

Im writing a facebook-connect app that login user after authenticate session on facebook, question is how can i authenticate user on django after get user object?

user = User.objects.get(email=email)
user = authenticate(username=user.username, password=user.password)
login(request, user)

Is there another way to achieve this ?

Answer

Lyle Pratt picture Lyle Pratt · Jan 21, 2011

You don't actually need to authenticate() first if you do this (but I didn't tell you!):

user.backend = 'django.contrib.auth.backends.ModelBackend'

login(request, user)