flask_ldap3_login/__init__.py
def authenticate_direct_bind(self, username, password):
        """
        Performs a direct bind. We can do this since the RDN is the same
        as the login attribute. Hence we just string together a dn to find
        this user with.

        Args:
            username (str): Username of the user to bind (the field specified
                as LDAP_BIND_RDN_ATTR)
            password (str): User's password to bind with.

        Returns:
            AuthenticationResponse
        """

        bind_user = '{rdn}={username},{user_search_dn}'.format(
            rdn=self.config.get('LDAP_USER_RDN_ATTR'),
            username=username,
            user_search_dn=self.full_user_search_dn,
        )

        connection = self._make_connection(
            bind_user=bind_user,
            bind_password=password,
        )

        response = AuthenticationResponse()

        try:
            connection.bind()
            log.debug(
                "Authentication was successful for user '{0}'".format(username))
            response.status = AuthenticationResponseStatus.success
            # Get user info here.

            user_info = self.get_user_info(
                dn=bind_user, _connection=connection)
            response.user_dn = bind_user
            response.user_id = username
            response.user_info = user_info
            if self.config.get('LDAP_SEARCH_FOR_GROUPS'):
                response.user_groups = self.get_user_groups(
                    dn=bind_user, _connection=connection)

        except ldap3.core.exceptions.LDAPInvalidCredentialsResult:
            log.debug(
                "Authentication was not successful for user '{0}'".format(username))
            response.status = AuthenticationResponseStatus.fail
        except Exception as e:
            log.error(e)
            response.status = AuthenticationResponseStatus.fail

        self.destroy_connection(connection)
        return response
def authenticate_direct_bind(self, username, password):
        bind_user = '{rdn}={username},{user_search_dn}'.format(
            rdn=self.config.get('LDAP_USER_RDN_ATTR'),
            username=username,
            user_search_dn=self.full_user_search_dn,
        )

        connection = self._make_connection(
            bind_user=bind_user,
            bind_password=password,
        )

        response = AuthenticationResponse()

        try:
            connection.bind()
            log.debug(
                "Authentication was successful for user '{0}'".format(username))
            response.status = AuthenticationResponseStatus.success
            # Get user info here.

            user_info = self.get_user_info(
                dn=bind_user, _connection=connection)
            response.user_dn = bind_user
            response.user_id = username
            response.user_info = user_info
            if self.config.get('LDAP_SEARCH_FOR_GROUPS'):
                response.user_groups = self.get_user_groups(
                    dn=bind_user, _connection=connection)

        except ldap3.core.exceptions.LDAPInvalidCredentialsResult:
            log.debug(
                "Authentication was not successful for user '{0}'".format(username))
            response.status = AuthenticationResponseStatus.fail
        except Exception as e:
            log.error(e)
            response.status = AuthenticationResponseStatus.fail

        self.destroy_connection(connection)
        return response
def authenticate_direct_bind ( self , username , password ) : bind_user = '{rdn}={username},{user_search_dn}' . format ( rdn = self . config . get ( 'LDAP_USER_RDN_ATTR' ) , username = username , user_search_dn = self . full_user_search_dn , ) connection = self . _make_connection ( bind_user = bind_user , bind_password = password , ) response = AuthenticationResponse ( ) try : connection . bind ( ) log . debug ( "Authentication was successful for user '{0}'" . format ( username ) ) response . status = AuthenticationResponseStatus . success # Get user info here. user_info = self . get_user_info ( dn = bind_user , _connection = connection ) response . user_dn = bind_user response . user_id = username response . user_info = user_info if self . config . get ( 'LDAP_SEARCH_FOR_GROUPS' ) : response . user_groups = self . get_user_groups ( dn = bind_user , _connection = connection ) except ldap3 . core . exceptions . LDAPInvalidCredentialsResult : log . debug ( "Authentication was not successful for user '{0}'" . format ( username ) ) response . status = AuthenticationResponseStatus . fail except Exception as e : log . error ( e ) response . status = AuthenticationResponseStatus . fail self . destroy_connection ( connection ) return response
Performs a direct bind. We can do this since the RDN is the same
        as the login attribute. Hence we just string together a dn to find
        this user with.

        Args:
            username (str): Username of the user to bind (the field specified
                as LDAP_BIND_RDN_ATTR)
            password (str): User's password to bind with.

        Returns:
            AuthenticationResponse
Performs a direct bind . We can do this since the RDN is the same as the login attribute . Hence we just string together a dn to find this user with .