Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YAML error when using FOSUserBundle with Symfony 3.3

I'm running in to a weird error when setting up FOSUserBundle in Symfony. I get this error message:

A colon cannot be used in an unquoted mapping value at line 30 (near " csrf_token_generator: security.csrf.token_manager").

Here is my security.yml, can anyone tell me what I've done wrong?

# To get started with security, check out the documentation:
# https://symfony.com/doc/current/security.html
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
#        in_memory:
#            memory: ~
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager

            logout:       true
            anonymous:    true
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

I have tried commenting out the line that's mentioned in the error message (csrf_token_generator) but the error persists, now pointing to the line above it.

like image 556
Fabian Avatar asked Dec 31 '25 10:12

Fabian


1 Answers

I think It's a problem of indentation,

try to change this:

pattern: ^/
    form_login:
         provider: fos_userbundle
         csrf_token_generator: security.csrf.token_manager

    logout:       true
    anonymous:    true

to this:

pattern: ^/
form_login:
    provider: fos_userbundle
    csrf_token_generator: security.csrf.token_manager

logout:       true
anonymous:    true
like image 167
Alessandro Minoccheri Avatar answered Jan 03 '26 20:01

Alessandro Minoccheri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!