Symfony 5.4 – Expected "scalar", but got "array" in security.yml

After setting up login form authentication in a fresh Symfony 5.4 app, I got this error when specifying login provider.

Invalid type for path "security.firewalls.main.provider". Expected
"scalar", but got "array".

Here is my security.yml:

security:
    enable_authenticator_manager: true
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
            algorithm: auto
            cost: 4
            time_cost: 3
            memory_cost: 10
    providers:
        users_in_memory: { memory: null }
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            lazy: true
            provider:
                app_user_provider:
                    entity:
                        class: App\Entity\User
                        property: email
            custom_authenticator: App\Security\AppAuthAuthenticator
            logout:
                path: app_logout
            form_login:
                login_path: app_login
                check_path: app_login
                enable_csrf: true
            login_throttling:
                max_attempts: 3
            switch_user: true
    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }
        - { path: ^/dashboard, roles: ROLE_USER }

I’m Using PHP 8.1 on a macOS 13 system. As a side note, switching to PHP 7.4 didn’t solve the issue.

>Solution :

I think you need to relocate your app_user_provider definition:


security:
    enable_authenticator_manager: true
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
            algorithm: auto
            cost: 4
            time_cost: 3
            memory_cost: 10
    providers:
        # users_in_memory: { memory: null }
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            lazy: true
            provider:
                app_user_provider
    ...

There is more information in the docs

Leave a Reply