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/channels/in_ldap/auth.py

26 lines
830 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
from django.http import HttpRequest
2019-10-01 08:24:10 +00:00
from structlog import get_logger
2018-11-11 12:41:48 +00:00
from passbook.channels.in_ldap.connector import Connector
from passbook.channels.in_ldap.models import LDAPInlet
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, request: HttpRequest, **kwargs):
2018-11-11 12:41:48 +00:00
"""Try to authenticate a user via ldap"""
2019-12-31 11:51:16 +00:00
if "password" not in kwargs:
2018-11-11 12:41:48 +00:00
return None
for inlet in LDAPInlet.objects.filter(enabled=True):
LOGGER.debug("LDAP Auth attempt", inlet=inlet)
_ldap = Connector(inlet)
user = _ldap.auth_user(**kwargs)
if user:
return user
return None