2

I've been working a RESTful API for a while now in Symfony 2. Everything seemed to be OK until last night when I created new entity classes. I'm getting an error when trying to request an access token. I get the following error message:

Catchable Fatal Error: Argument 2 passed to
FOS\OAuthServerBundle\Event\OAuthEvent::__construct() must be an
instance of FOS\OAuthServerBundle\Model\ClientInterface, instance of
TeamGraduate\APIBundle\Entity\Client given, called in /Volumes/SK Repo
1.0/Projects/Stalin Kay/Web Development/htdocs/TeamGraduate/tg-api/vendor/friendsofsymfony/oauth-server-bundle/FOS/OAuthServerBundle/Controller/AuthorizeController.php
on line 57 and defined 500 Internal Server Error -
ContextErrorException

Please help. My s2 project uses the FOSOauthServerBundle as described in the documentation. If I override the constructor in Client it throws a fatal error: cannot call constructor.

Edit:

NB: Just to be clear everything was working fine until I generated new entities based on an updated database. I also did an update of the project's dependencies using composer update.

AccessToken.php

<?php
// src/Acme/DemoBundle/Entity/AccessToken.php

namespace TeamGraduate\APIBundle\Entity;

use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class AccessToken extends BaseAccessToken
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Client")
     * @ORM\JoinColumn(nullable=false)
     */
    protected $client;

    /**
     * @ORM\ManyToOne(targetEntity="User")
     */
    protected $user;
}

AuthCode.php

<?php
// src/Acme/DemoBundle/Entity/AuthCode.php

namespace TeamGraduate\APIBundle\Entity;

use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class AuthCode extends BaseAuthCode
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Client")
     * @ORM\JoinColumn(nullable=false)
     */
    protected $client;

    /**
     * @ORM\ManyToOne(targetEntity="User")
     */
    protected $user;
}

Client.php

<?php
// src/Acme/DemoBundle/Entity/Client.php

namespace TeamGraduate\APIBundle\Entity;

use FOS\OAuthServerBundle\Entity\Client as BaseClient;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Client extends BaseClient
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

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

RefreshToken.php

<?php
// src/Acme/DemoBundle/Entity/RefreshToken.php

namespace TeamGraduate\APIBundle\Entity;

use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class RefreshToken extends BaseRefreshToken
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Client")
     * @ORM\JoinColumn(nullable=false)
     */
    protected $client;

    /**
     * @ORM\ManyToOne(targetEntity="User")
     */
    protected $user;
}
Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
Stalin Kay
  • 577
  • 8
  • 18
  • Does your `Client` entity implement `ClientInterface`? Can you post it as well? – chapay Nov 06 '15 at 15:24
  • @chapay, I didn't implement ClientInterface. I'm using the prescribed way from [link](https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md) – Stalin Kay Nov 06 '15 at 17:40
  • extend FOS\OAuthServerBundle\Model\Client not Entity\Client – Udan Nov 06 '15 at 17:45
  • @udan, that did it for me although another problem popped up but I'll try to fix that. Thanks guys. – Stalin Kay Nov 06 '15 at 18:54
  • @udan, when I use FOS\OAuthServerBundle\Model\\* and issue php app/console doctrine:schema:update --force this removes all the columns that are added by FOSOauthServerBundle in my database. I get **Unrecognized field: randomId** when trying to authorize a client. – Stalin Kay Nov 07 '15 at 10:03

1 Answers1

0

I believe I have found a solution.

Using the command below creates an FOS directory is created under src

php app/console doctrine:mapping:import --force TeamGraduateAPIBundle xml

Solution:

Delete the directory and all should be OK.

Stalin Kay
  • 577
  • 8
  • 18