This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/sources/ldap/auth.py

24 lines
709 B
Python
Raw Normal View History

2018-11-11 12:41:48 +00:00
"""passbook LDAP Authentication Backend"""
from django.contrib.auth.backends import ModelBackend
2019-10-01 08:24:10 +00:00
from structlog import get_logger
2018-11-11 12:41:48 +00:00
2019-10-10 15:36:09 +00:00
from passbook.sources.ldap.connector import Connector
2019-10-07 14:33:48 +00:00
from passbook.sources.ldap.models import LDAPSource
2018-11-11 12:41:48 +00:00
LOGGER = get_logger()
2018-11-11 12:41:48 +00:00
class LDAPBackend(ModelBackend):
"""Authenticate users against LDAP Server"""
def authenticate(self, **kwargs):
"""Try to authenticate a user via ldap"""
if 'password' not in kwargs:
return None
for source in LDAPSource.objects.filter(enabled=True):
2019-10-10 15:36:09 +00:00
_ldap = Connector(source)
user = _ldap.auth_user(**kwargs)
if user:
return user
return None