0
votes

I am working on an authentication with FpOpenIdBundle but i get this error

Catchable Fatal Error: Argument 1 passed to Fp\OpenIdBundle\Model\UserIdentity::setUser() must implement interface Symfony\Component\Security\Core\User\UserInterface, instance of Doctrine\ODM\MongoDB\DocumentRepository given, called in C:\xampp\htdocs\project\src\AppBundle\Security\User\OpenIdUserManager.php on line 64 and defined

I followed the doc (https://github.com/formapro/FpOpenIdBundle/blob/master/Resources/doc/configure_user_manager.md)

I have made a manager

namespace AppBundle\Security\User;

use AppBundle\Document\User;
use AppBundle\Document\OpenIdIdentity;
use Doctrine\ODM\MongoDB\DocumentManager;
use Fp\OpenIdBundle\Model\UserManager;
use Fp\OpenIdBundle\Model\IdentityManagerInterface;

class OpenIdUserManager extends UserManager
{
   /**
   * @var DocumentManager
   */
   private $documentManager;

    /**
    * OpenIdUserManager constructor.
    *
    * @param IdentityManagerInterface $identityManager
    * @param DocumentManager $documentManager
    */
    public function __construct(IdentityManagerInterface $identityManager, DocumentManager $documentManager)
    {
        parent::__construct($identityManager);

        $this->documentManager = $documentManager;
    }

    /**
     * @param string $identity
     * @param array $attributes
     *
     * @return \Doctrine\ODM\MongoDB\DocumentRepository
     */
     public function createUserFromIdentity($identity, array $attributes = array())
    {

        $user = $this->documentManager->getRepository('AppBundle:User');

        $openIdIdentity = new OpenIdIdentity();
        $openIdIdentity->setIdentity($identity);
        $openIdIdentity->setAttributes($attributes);
        $openIdIdentity->setUser($user);

        $this->documentManager->persist($openIdIdentity);
        $this->documentManager->flush();

        return $user;

    }
}

The error is returned because of this line

$openIdIdentity->setUser($user);

I use this manager as the service like this

services:
fp_openid.manager:
    class: AppBundle\Security\User\OpenIdUserManager
    arguments: [ '@fp_openid.identity_manager', '@doctrine.odm.mongodb.document_manager' ]

Who's called by my security.yml

security:
    firewalls:
       main:
           fp_openid:
               create_user_if_not_exists: true
               provider: openid_user_manager
    providers:
        openid_user_manager:
            id: fp_openid.manager
        main:
            entity:
                { class: AppBundle:User, property: personaName }

I finally made a MongoDB document as they said

namespace AppBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Security\Core\User\UserInterface;

use Fp\OpenIdBundle\Document\UserIdentity as BaseUserIdentity;

/**
 * @MongoDB\Document(collection="openid_identities")
 */
class OpenIdIdentity extends BaseUserIdentity
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;

    /**
     * {@inheritdoc}
     * @MongoDB\String
     */
     protected $identity;

    /**
     * {@inheritdoc}
     * @MongoDB\Hash
     */
     protected $attributes;

    /**
     * @var UserInterface
     *
     * @MongoDB\ReferenceOne(targetDocument="AppBundle\Document\User", simple=true)
     */
     protected $user;

    public function __construct()
    {
        parent::__construct();
    }
}

Everythings is working well except this problem, i don't understand why this is not working whereas i do the same as the doc said. I must implement UserInterface instead of instance of DocumentRepository but they use their user document instead.

Does some already use this bundle and had this issue ?

Thanks for helping

1

1 Answers

2
votes

Please carefully read the doc again, in the doc it's:

$user = $this->entityManager->getRepository('AcmeDemoBundle:User')->findOneBy(array(
    'email' => $attributes['contact/email']
));