質問

I'm trying to set up HWIOAuthBundle to work with FOSUserBundle.

While making my own User Provider that extends FOSUBUserProvider, I did the following:

namespace Naroga\Reader\CommonBundle\Service\Security;

use HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;

class NarogaUserProvider extends FOSUBUserProvider {

    public function loadUserByOAuthUserResponse(UserResponseInterface $response) {

        [...]

    }

}

My services.yml is as follows:

naroga.reader.common.security.user_provider:
    class: Naroga\Reader\CommonBundle\Service\Security\NarogaUserProvider
    arguments: [ @fos_user.user_manager ]

Whenever I run the program, I get the following error:

Argument 2 passed to HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider::__construct() must be of the type array, none given, called in

This makes great sense, because FOSUBUserProvider::__construct's signature is public function __construct(UserManagerInterface $userManager, array $properties).

I have no idea what to define as being my second parameter to my service so it can override FOSUBUserProvider. I've been googling it and all I find is people with the same question, no answers.

I'd be forever grateful to the gentle soul that tells me what the second parameter must be in order to comply with FOSUBUserProvider's signature.

Thank you.

役に立ちましたか?

解決

The second argument is used for mapping. As I understand, this is the name corresponding OAuth service and name of field in your entity.

For example, you can send them as follows:

naroga.reader.common.security.user_provider:
    class: Naroga\Reader\CommonBundle\Service\Security\NarogaUserProvider
    arguments: [ @fos_user.user_manager, { facebook: facebookId, twitter: twitterId } ]

他のヒント

In case you would like to pass also some additional arguments, let's say fire an event using dispatcher which was my case, just overwrite the constructor.

use HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider as BaseClass;

FOSUBUserProvider extends BaseClass
{
    /**
     * @var EventDispatcherInterface
     */
    private $eventDispatcher;

    /**
     * Constructor.
     *
     * @param UserManagerInterface $userManager FOSUB user provider.
     * @param array $properties Property mapping.
     * @param EventDispatcherInterface $eventDispatcher
     */
    public function __construct(
        UserManagerInterface $userManager,
        array $properties,
        EventDispatcherInterface $eventDispatcher)
    {
        $this->userManager     = $userManager;
        $this->properties      = array_merge($this->properties, $properties);
        $this->accessor        = PropertyAccess::createPropertyAccessor();
        $this->eventDispatcher = $eventDispatcher;
    }

And the service definition:

tb_user_provider:
    class: "%tb_user_provider.class%"
    arguments: [@fos_user.user_manager, { facebook: facebook_id }, @event_dispatcher]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top