2015-09-29 14:31:52 +02:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 01:30:12 +01:00
|
|
|
namespace Wallabag\Entity\Api;
|
2015-09-29 14:31:52 +02:00
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2015-12-22 10:16:34 +01:00
|
|
|
use FOS\OAuthServerBundle\Entity\Client as BaseClient;
|
2017-06-07 23:23:28 +02:00
|
|
|
use JMS\Serializer\Annotation\Groups;
|
|
|
|
use JMS\Serializer\Annotation\SerializedName;
|
|
|
|
use JMS\Serializer\Annotation\VirtualProperty;
|
2023-07-02 08:27:07 +02:00
|
|
|
use OpenApi\Annotations as OA;
|
2024-02-19 01:30:12 +01:00
|
|
|
use Wallabag\Entity\User;
|
2025-04-05 12:55:51 +02:00
|
|
|
use Wallabag\Repository\Api\ClientRepository;
|
2015-09-29 14:31:52 +02:00
|
|
|
|
2025-04-05 12:55:51 +02:00
|
|
|
#[ORM\Table('oauth2_clients')]
|
|
|
|
#[ORM\Entity(repositoryClass: ClientRepository::class)]
|
2015-09-29 14:31:52 +02:00
|
|
|
class Client extends BaseClient
|
|
|
|
{
|
2025-04-05 12:55:51 +02:00
|
|
|
#[ORM\Id]
|
|
|
|
#[ORM\Column(type: 'integer')]
|
|
|
|
#[ORM\GeneratedValue(strategy: 'AUTO')]
|
2015-09-29 14:31:52 +02:00
|
|
|
protected $id;
|
|
|
|
|
2016-05-21 18:09:38 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
2023-07-02 08:27:07 +02:00
|
|
|
* @OA\Property(
|
|
|
|
* description="Name of the API client",
|
|
|
|
* type="string",
|
|
|
|
* example="Default Client",
|
|
|
|
* )
|
2016-05-21 18:09:38 +02:00
|
|
|
*/
|
2025-04-05 12:55:51 +02:00
|
|
|
#[ORM\Column(name: 'name', type: 'text', nullable: false)]
|
2025-04-05 15:12:30 +02:00
|
|
|
#[Groups(['user_api_with_client'])]
|
2016-05-21 18:09:38 +02:00
|
|
|
protected $name;
|
|
|
|
|
2025-04-05 12:55:51 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: RefreshToken::class, mappedBy: 'client', cascade: ['remove'])]
|
2016-10-03 21:39:01 +02:00
|
|
|
protected $refreshTokens;
|
|
|
|
|
2025-04-05 12:55:51 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: AccessToken::class, mappedBy: 'client', cascade: ['remove'])]
|
2016-10-08 00:02:22 +02:00
|
|
|
protected $accessTokens;
|
|
|
|
|
2017-06-07 23:23:28 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
2023-07-02 08:27:07 +02:00
|
|
|
* @OA\Property(
|
|
|
|
* description="Client secret used for authorization",
|
|
|
|
* type="string",
|
|
|
|
* example="2lmubx2m9vy80ss8c4wwcsg8ok44s88ocwcc8wo0w884oc8440",
|
|
|
|
* )
|
2017-06-07 23:23:28 +02:00
|
|
|
*/
|
2025-04-05 15:12:30 +02:00
|
|
|
#[SerializedName('client_secret')]
|
|
|
|
#[Groups(['user_api_with_client'])]
|
2017-06-07 23:23:28 +02:00
|
|
|
protected $secret;
|
|
|
|
|
2025-04-05 12:55:51 +02:00
|
|
|
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'clients')]
|
2016-10-24 21:56:28 +02:00
|
|
|
private $user;
|
|
|
|
|
|
|
|
public function __construct(User $user)
|
2015-09-29 14:31:52 +02:00
|
|
|
{
|
|
|
|
parent::__construct();
|
2016-10-24 21:56:28 +02:00
|
|
|
$this->user = $user;
|
2015-09-29 14:31:52 +02:00
|
|
|
}
|
2016-05-21 18:09:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get name.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set name.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return Client
|
|
|
|
*/
|
|
|
|
public function setName($name)
|
|
|
|
{
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2016-10-24 21:56:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function getUser()
|
|
|
|
{
|
|
|
|
return $this->user;
|
|
|
|
}
|
2017-06-07 23:23:28 +02:00
|
|
|
|
|
|
|
/**
|
2023-07-02 08:27:07 +02:00
|
|
|
* @OA\Property(
|
|
|
|
* description="Client secret used for authorization",
|
|
|
|
* type="string",
|
|
|
|
* example="3_1lpybsn0od40css4w4ko8gsc8cwwskggs8kgg448ko0owo4c84",
|
|
|
|
* )
|
2017-06-07 23:23:28 +02:00
|
|
|
*/
|
2025-04-05 15:12:30 +02:00
|
|
|
#[VirtualProperty]
|
|
|
|
#[SerializedName('client_id')]
|
|
|
|
#[Groups(['user_api_with_client'])]
|
2017-06-07 23:23:28 +02:00
|
|
|
public function getClientId()
|
|
|
|
{
|
2017-07-01 09:52:38 +02:00
|
|
|
return $this->getId() . '_' . $this->getRandomId();
|
2017-06-07 23:23:28 +02:00
|
|
|
}
|
2015-09-29 14:31:52 +02:00
|
|
|
}
|