issue with providers and chain_provider in symfony

2019-08-09 03:09发布

问题:

I am getting the following error, with the code below:

ServiceNotFoundException: The service "security.firewall.map.context.main" has a dependency on a non-existent service "security.user.provider.concrete.fos_user_bundle".

This happened after I added the chain_provider: provider in it, if I remove it, it just works out fine. Any idea why?

security: 
    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email
        my_fos_facebook_provider:
            id: my.facebook.user
        chain_provider:
            chain:
                providers: [fos_user_bundle, my_fos_facebook_provider]
        in_memory:
            memory:
                users:
                    user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                    admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }

    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    firewalls:
        main:
            pattern: ^/.*
            form_login:
                login_path: fos_user_security_login
                check_path: fos_user_security_check   
                provider: fos_userbundle
            fos_facebook:
                app_url: "http://apps.facebook.com/myapp/"
                server_url: "http://localhost/Symfony/web/app_dev.php"
                login_path: fos_user_security_login
                check_path: fos_user_security_check
                default_target_path: /
                provider: my_fos_facebook_provider
            anonymous: true
            logout: 
                path:   /logout
                target: / 
                handlers: ["fos_facebook.logout_handler"]
            #http_basic:
            #    realm: "Secured Demo Area"
        login:
            pattern:  ^/login$
            security: false

回答1:

It's a bug in FOSFacebookBundle docs. You must use fos_userbundle and NOT fos_user_bundle (notice the underscore) as provider name.



回答2:

Did you add 'my_fos_facebook_provider'? You have to bind it to 'my.facebook.user service'(last 2 lines):

    providers:
        chainprovider:
            chain:
                providers: [fos_userbundle, my_fos_facebook_provider]
    fos_userbundle:
        id: fos_user.user_provider.username
    my_fos_facebook_provider:
        id: my.facebook.user