2

In Django you can read _auth_user_id from request.session dictionary after you authenticate and log in user. As I understand in "normal" conditions (standard authentication backend) it should be user id (pk).

But what is _auth_user_id when I'm using django-auth-ldap as authentication backend? It returns integers but there is no such values in my LDAP database.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
pbm
  • 358
  • 2
  • 7
  • 22

1 Answers1

1

Every Django authentication backend--django-auth-ldap included--ultimately returns an instance of django.contrib.auth.models.User on a successful authentication. django.contrib.sessions, in turn, knows only about these user objects; it doesn't know or care which backend produced them. So request.session['_auth_user_id'] should be a User pk regardless of your backend. As a rule, of course, you would access request.user for convenience.

If you're using django-auth-ldap and you need to get back to the LDAP user, you can look at request.user.ldap_user. See the documentation for details and performance considerations.

psagers
  • 859
  • 4
  • 5