oauth2-bundle
oauth2-bundle copied to clipboard
Support for custom entities
Hi!
Is there a way to change the built-in entites from the bundle to custom ones? The reason behind this is to create some additional fields that would implement given business logic (some clients are public, some are default, some are premoderated etc.)
I spend some time digging into the code - I fear that implementing this would be a huge amount of work (please proove me wrong! 😄). At least for me, so I ended up implementing a custom entity that holds all information I need to store additionally:
class OAuthClientInfo {
use IdTrait; // provides an Id field
/**
* @ORM\Column(type="string")
* @Assert\NotBlank()
* @var string|null
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
* @var string|null
*/
private $description;
/**
* @ORM\OneToOne(targetEntity="Trikoder\Bundle\OAuth2Bundle\Model\Client")
* @ORM\JoinColumn(onDelete="CASCADE", referencedColumnName="identifier")
* @Assert\NotNull()
* @var Client|null
*/
private $client;
public function __construct() {
$this->uuid = Uuid::uuid4();
}
/**
* @return string|null
*/
public function getName(): ?string {
return $this->name;
}
/**
* @param string|null $name
* @return OAuthClientInfo
*/
public function setName(?string $name): OAuthClientInfo {
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getDescription(): ?string {
return $this->description;
}
/**
* @param string|null $description
* @return OAuthClientInfo
*/
public function setDescription(?string $description): OAuthClientInfo {
$this->description = $description;
return $this;
}
/**
* @return Client|null
*/
public function getClient(): ?Client {
return $this->client;
}
/**
* @param Client|null $client
* @return OAuthClientInfo
*/
public function setClient(?Client $client): OAuthClientInfo {
$this->client = $client;
return $this;
}
}