1

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: '[email protected]'
        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 !

9
  • 1
    Master branch of FOSUserBundle actually supports Symfony4. For sure there might still be things to fix/improve but basic usage should be fine. Commented Jan 28, 2018 at 7:36
  • About your problem can you check that the value you have in the database for the password field is equal to the one you pasted above? Is it setPassword doing the encrypt or just setting the plain value? Because in first case you're encrypting the password twice (manually and then through Alice). Commented Jan 28, 2018 at 7:49
  • Her dlondero, thanks for your help. No I encoded the password mysel using a bcrypt encryption website. I juste check and the password in the DB is the same as in my fixture file. No additionnal encryption there. I also tried to store a plain text password and remove the encoder from my security YAML file and the problem is also there... Commented Jan 28, 2018 at 7:57
  • And do you actually have an entity manager called native_users in config/packages/doctrine.yaml? Commented Jan 28, 2018 at 8:15
  • Also I would suggest you to encrypt the password locally and set that as value, not what you get from a 3rd party site. See symfony.com/doc/current/security/password_encoding.html. Commented Jan 28, 2018 at 8:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.