<?php
/**
* Created by PhpStorm.
* User: franzwilding
* Date: 2019-01-29
* Time: 09:16
*/
namespace DW\GingerBundle\Entity;
use FOS\OAuthServerBundle\Entity\Client;
use Doctrine\ORM\Mapping as ORM;
use OAuth2\OAuth2;
/**
* @ORM\Entity
*/
class ApiClient extends Client
{
const ALLOWED_GRANT_TYPES = [
OAuth2::GRANT_TYPE_USER_CREDENTIALS,
OAuth2::GRANT_TYPE_REFRESH_TOKEN,
OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS,
];
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// Per default, set allowed grant types to user and client credentials.
$this->setAllowedGrantTypes(static::ALLOWED_GRANT_TYPES);
}
/**
* {@inheritdoc}
*/
public function setAllowedGrantTypes(array $grantTypes)
{
$this->allowedGrantTypes = [];
// Only allow to set grant types to allowed grant types.
foreach($grantTypes as $grantType) {
if(in_array($grantType, static::ALLOWED_GRANT_TYPES)) {
$this->allowedGrantTypes[] = $grantType;
}
}
}
}