Symfony LDAP invalid credentials

I keep getting an ‘Invalid credentials’ error when testing LDAP authentication with Symfony even though my email and my password should be correct. Is there any reason as to why this could be happening?

Twig:

    {% extends 'base.html.twig' %}

{% block body %}
    {% if error %}
        <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
    {% endif %}

    <form action="{{ path('login') }}" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="_username" value="{{ last_username }}" />

        <label for="password">Password:</label>
        <input type="password" id="password" name="_password" />

        <button type="submit">login</button>
    </form>
{% endblock %}

{% block stylesheets %}
{% endblock %}

My controller:

 /**
     * @Route("/login", name="login")
     * @param Request $request
     * @param AuthenticationUtils $authenticationUtils
     * @return Response
     */
    public function login(Request $request, AuthenticationUtils $authenticationUtils)
    {
        // get the login error if there is one
        $error = $authenticationUtils->getLastAuthenticationError();
        // last username entered by the user
        $lastUsername = $authenticationUtils->getLastUsername();


        return $this->render('security/login.html.twig', array(
            'last_username' => $lastUsername,
            'error'         => $error,
        ));
    }

services.yaml

services:
    SymfonyComponentLdapLdap:
        arguments: ['@SymfonyComponentLdapAdapterExtLdapAdapter']

    SymfonyComponentLdapAdapterExtLdapAdapter:
        arguments:
            - connection_string: 'xxx'
              options:
                  protocol_version: 3

security.yaml

main:
            anonymous: lazy
            form_login_ldap:
                login_path: login
                check_path: login
                service: SymfonyComponentLdapLdap
                dn_string: 'ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=de'
                query_string: '(&(cn={username})(memberOf=cn=xxx,ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xxx))' 
                search_dn: 'uid=adminUser,ou=xxx,ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xx' 
                search_password: 'xxx' 

Am I missing something?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *