Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#19912 closed New feature (wontfix)

Authenticate users in multiple database

Reported by: EvgeniyMakhmudov Owned by: EvgeniyMakhmudov
Component: contrib.auth Version: 1.4
Severity: Normal Keywords: authenticate
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A problem occur while using several database (each contains users tables) and don't using managers. Process authentication in Django is avaiable only for users table in default database. My proposal is in small modification in original (1.4) code:

# django.contrib.auth.backends.py
# class ModelBackend(object)
# ... 

    def authenticate(self, username=None, password=None, database='default'):
        try:
            user = User.objects.using(database).get(username=username)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

I don't tested this from global point of view, but in my app it is working.

Change History (5)

comment:1 Changed 3 years ago by EvgeniyMakhmudov

  • Needs documentation unset
  • Needs tests set
  • Owner changed from nobody to EvgeniyMakhmudov
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 3 years ago by EvgeniyMakhmudov

  • Owner EvgeniyMakhmudov deleted
  • Status changed from assigned to new

comment:3 Changed 3 years ago by EvgeniyMakhmudov

  • Owner set to EvgeniyMakhmudov
  • Status changed from new to assigned

comment:4 Changed 3 years ago by jacob

  • Resolution set to wontfix
  • Status changed from assigned to closed

I think this is in "write your own backend" territory. It's fairly simple to subclass ModelBackend and provide your own authentication using whatever database you choose. Once you start doing "special things" with auth, you're almost certainly going to have to write a custom backend.

[Also, this mixes up what arguments authenticate() takes: it's supposed to be **credentials, but the database isn't exactly considered credentials, I think.]

comment:5 Changed 3 years ago by EvgeniyMakhmudov

about first, ok. I understand.

about this:
[Also, this mixes up what arguments authenticate() takes: it's supposed to be **credentials, but the database isn't exactly considered credentials, I think.]

i don't understand, why it problem for authenticate()? Look, django.contrib.auth.authenticate takes **credentials and send it to backend, which by default alwsays the only 'django.contrib.auth.backends.ModelBackend'. This backend receive dictionary with needed username,password and if neccesseary database name, otherwise use predefault value 'default'. So, i can't see where is mixing?

Note: See TracTickets for help on using tickets.
Back to Top