vendor/datenwerk/ginger-bundle/Entity/ApiClient.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: franzwilding
  5.  * Date: 2019-01-29
  6.  * Time: 09:16
  7.  */
  8. namespace DW\GingerBundle\Entity;
  9. use FOS\OAuthServerBundle\Entity\Client;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use OAuth2\OAuth2;
  12. /**
  13.  * @ORM\Entity
  14.  */
  15. class ApiClient extends Client
  16. {
  17.     const ALLOWED_GRANT_TYPES = [
  18.         OAuth2::GRANT_TYPE_USER_CREDENTIALS,
  19.         OAuth2::GRANT_TYPE_REFRESH_TOKEN,
  20.         OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS,
  21.     ];
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\Column(type="integer")
  25.      * @ORM\GeneratedValue(strategy="AUTO")
  26.      */
  27.     protected $id;
  28.     public function __construct()
  29.     {
  30.         parent::__construct();
  31.         // Per default, set allowed grant types to user and client credentials.
  32.         $this->setAllowedGrantTypes(static::ALLOWED_GRANT_TYPES);
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     public function setAllowedGrantTypes(array $grantTypes)
  38.     {
  39.         $this->allowedGrantTypes = [];
  40.         // Only allow to set grant types to allowed grant types.
  41.         foreach($grantTypes as $grantType) {
  42.             if(in_array($grantType, static::ALLOWED_GRANT_TYPES)) {
  43.                 $this->allowedGrantTypes[] = $grantType;
  44.             }
  45.         }
  46.     }
  47. }