formapro / FpOpenIdBundle

Symfony2 OpenID security extension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenIdUserManager implement interface error

Jerome1337 opened this issue · comments

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 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;

    }
}

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. The doc say I must implement DocumentRepository instead of instance of UserInterface.
How can i solve this error ?

Thanks for helping