oauth2-bundle icon indicating copy to clipboard operation
oauth2-bundle copied to clipboard

Support for custom entities

Open alyamovsky opened this issue 6 years ago • 1 comments

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.)

alyamovsky avatar Dec 16 '19 11:12 alyamovsky

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

frostieDE avatar Jun 09 '20 09:06 frostieDE