0

I'm trying to configure a website with django and LDAP authentification. Upon my login page, I just type in any username and password, and expect to get to a different html page (without connecting to a database, for now. My method in my view.py file:

def login_view(request):
    if request.POST:
        print ('*'*50)
        print (request.POST)
        print ('*'*50)
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        print ('*'*50)
        print (user)
        print ('*'*50)
        if user is not None:
            if user.is_active:
                login(request, user)
                return redirect('index')
            else:
                messages.error(request, "User is not active in Database") 
        else:
            messages.error(request, "Please check your username and password!")
    return render(request, 'login.html')

I'm new to django so not even too sure whether I should be seeing any page of if this error message is correct. I'm using Python3.5 and I installed successfully pyasn1-0.2.3. Then going into my console I can successfully import ldap3. However I can't get any further than this.

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'UserAuth',
]

Any my directory looks like this:

UserAuth
  -> user_auth
  -> UserAuth
  manage.py

From what I can deduce, it appears that django_ldap_auth cannot be easily installed for 1. Windows 8.1 Enterprise and 2. for Python 3 (https://github.com/susundberg/django-auth-ldap-ad)

That is annoying, perhaps if I switch to Python2 maybe this would work....

pymat
  • 1,090
  • 1
  • 23
  • 45
  • what error are you getting? – Exprator May 29 '17 at 15:48
  • 1
    pip install django-auth-ldap use this – Exprator May 29 '17 at 15:57
  • @Exprator: ImportError at /login/ No module named 'django_auth_ldap'. When I use the "pip install django-auth-ldap" command I get a "No matching distribution found for django-auth-ldap" error message. – pymat May 30 '17 at 06:43
  • post your settings file – Exprator May 30 '17 at 06:48
  • and did you install pyldap? – Exprator May 30 '17 at 06:48
  • For the installation of pyldap I used: ldap3-2.2.4.win-amd64.exe – pymat May 30 '17 at 07:18
  • post your setting files – Exprator May 30 '17 at 07:19
  • pip install ldap3 and check once – Exprator May 30 '17 at 07:25
  • Ok the pip worked, because then "import ldap3'" came back with no errors. – pymat May 30 '17 at 07:33
  • and have you used ldap backend in the settings file? it wont work unless you use that – Exprator May 30 '17 at 07:35
  • You mean: AUTHENTICATION_BACKENDS = ( 'django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend', ) – pymat May 30 '17 at 08:47
  • I downloaded the file: "django_auth_ldap-1.2.8-py3-none-any.whl" then did pip install on this file when saved to my desktop. The message came back as "Requirement already satisfied", then "Collecting pyldap" but "could not find a version that satisfies the requirement pyldap (from django-auth-ldap==1.2.8) – pymat May 30 '17 at 09:57
  • you dont need that userauth in the installed apps if you are usign ldap. https://pythonhosted.org/django-auth-ldap/ go through this and follow the steps – Exprator May 30 '17 at 10:02
  • I don't want to use the live (production) ldap server for the moment. I have instead an ldap.sh script, and for the moment just want to get it up and running. – pymat May 30 '17 at 10:38
  • For the moment I commented out the AUTHENTICATION_BACKENDS in my settings.py file, and now my page gets redirected. But at a later stage this will need to be added for testing against the LDAP server (in production), so problem NOT solved. – pymat May 30 '17 at 11:30
  • It seems that installing on my Mac and MBP were very straight forward ("pip install python-ldap" and "pip-install django-auth-ldap"), but I get a connection timeout error when using the Windows PC...could be a proxy setting issue at my work that may need sorting first. – pymat Jun 05 '17 at 20:08
  • From what I can deduce, it appears that django_ldap_auth cannot be easily installed for 1. Windows 8.1 Enterprise and 2. for Python 3 (https://github.com/susundberg/django-auth-ldap-ad) That is annoying, perhaps if I switch to Python2 maybe this would work.... – pymat Jun 07 '17 at 07:23

1 Answers1

0

I reached a dead with this and unless I hear on the contrary, then for Python3 users on Windows, this will also become a dead end. A thread on the matter can be found here.

Instead I'll now try with Radius.

pymat
  • 1,090
  • 1
  • 23
  • 45