Symfony4 - Basic Auth looping while using DB provi

2019-07-27 13:08发布

问题:

I'm desperate : I'm using Symfony for years, and today I'm stuck on a basic stuff. As FOSUserBundle is not implemented for Sf4 yet, I decided to create a really basic User entity in DB to load user.

But when I enter my username/password in the BasicAuth windows in my web browser (chrome) it's not logging me and loops over and over.

Here is my security file :

security:
    encoders:
        App\Entity\User:
            algorithm: bcrypt

    providers:
        native_provider:
            entity:
                class: App\Entity\User
                property: username
                manager_name: native_users

    firewalls:
        main:
            pattern:    ^/
            http_basic: ~
            provider: native_provider

    access_control:
        - { path: ^/, roles: ROLE_USER }

    role_hierarchy:
        ROLE_ADMIN: ROLE_USER

And my User class is exactly the same as the one in the symfony example : https://symfony.com/doc/current/security/entity_provider.html#create-your-user-entity

Finally I created some User fixtures using [nelmio/alice][1] :

App\Entity\User:
    user_1:
        id: '<uuid()>'
        username: 'admin'
        password: '\$2y\$10\$574w3EitCqOaHmhu4ER49.KPG2EMtcQlYrO0vdPyYW/EuqTHMCB0C'
        email: 'admin@test.com'
        isActive: true

Where '\$2y\$10\$574w3EitCqOaHmhu4ER49.KPG2EMtcQlYrO0vdPyYW/EuqTHMCB0C' reprensent the "admin" word coded in bcrypt.

Despite all these things, basic auth won't work. Any Idea ?

Thanks !