delboy1978uk /
oauth2-api
| 1 | <?php |
||
| 2 | |||
| 3 | namespace OAuth; |
||
| 4 | |||
| 5 | use DateTime; |
||
| 6 | use Doctrine\Common\Collections\ArrayCollection; |
||
| 7 | use Doctrine\ORM\Mapping as ORM; |
||
| 8 | use League\OAuth2\Server\Entities\AuthCodeEntityInterface; |
||
| 9 | use League\OAuth2\Server\Entities\ClientEntityInterface; |
||
| 10 | use League\OAuth2\Server\Entities\ScopeEntityInterface; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @ORM\Entity(repositoryClass="OAuth\Repository\AuthCodeRepository") |
||
| 14 | * @ORM\Table(name="AuthCode") |
||
| 15 | */ |
||
| 16 | class AuthCode implements AuthCodeEntityInterface |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var null|string |
||
| 21 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 22 | */ |
||
| 23 | protected $redirectUri; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var ArrayCollection $scopes |
||
| 27 | */ |
||
| 28 | protected $scopes; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var DateTime |
||
| 32 | * @ORM\Column(type="datetime",nullable=true) |
||
| 33 | */ |
||
| 34 | protected $expiryDateTime; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var OAuthUser |
||
| 38 | * @ORM\OneToOne(targetEntity="OAuth\OAuthUser") |
||
| 39 | * @ORM\JoinColumn(name="user", referencedColumnName="id") |
||
| 40 | */ |
||
| 41 | protected $userIdentifier; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var ClientEntityInterface |
||
| 45 | * @ORM\ManyToOne(targetEntity="OAuth\Client") |
||
| 46 | * @ORM\JoinColumn(name="client", referencedColumnName="id") |
||
| 47 | */ |
||
| 48 | protected $client; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | * @ORM\Column(type="text", nullable=false) |
||
| 53 | */ |
||
| 54 | protected $identifier; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var int |
||
| 58 | * @ORM\Id |
||
| 59 | * @ORM\Column(type="integer", nullable=false) |
||
| 60 | * @ORM\GeneratedValue |
||
| 61 | */ |
||
| 62 | protected $id; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var bool |
||
| 66 | * @ORM\Column(type="boolean") |
||
| 67 | */ |
||
| 68 | protected $revoked = false; |
||
| 69 | |||
| 70 | 7 | public function __construct() |
|
| 71 | { |
||
| 72 | 7 | $this->scopes = new ArrayCollection(); |
|
| 73 | 7 | } |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | 2 | public function getIdentifier() |
|
| 79 | { |
||
| 80 | 2 | return $this->identifier; |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param string $identifier |
||
| 85 | */ |
||
| 86 | 2 | public function setIdentifier($identifier) |
|
| 87 | { |
||
| 88 | 2 | $this->identifier = $identifier; |
|
| 89 | 2 | } |
|
| 90 | |||
| 91 | /** |
||
| 92 | * @param ScopeEntityInterface $scope |
||
| 93 | * @return $this |
||
| 94 | */ |
||
| 95 | 2 | public function addScope(ScopeEntityInterface $scope) |
|
| 96 | { |
||
| 97 | 2 | $this->scopes->add($scope); |
|
| 98 | 2 | return $this; |
|
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Return an array of scopes associated with the token. |
||
| 103 | * |
||
| 104 | * @return ScopeEntityInterface[] |
||
| 105 | */ |
||
| 106 | 2 | public function getScopes() |
|
| 107 | { |
||
| 108 | 2 | return $this->scopes->toArray(); |
|
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Get the token's expiry date time. |
||
| 113 | * |
||
| 114 | * @return DateTime |
||
| 115 | */ |
||
| 116 | 2 | public function getExpiryDateTime() |
|
| 117 | { |
||
| 118 | 2 | return $this->expiryDateTime; |
|
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Set the date time when the token expires. |
||
| 123 | * |
||
| 124 | * @param DateTime $dateTime |
||
| 125 | */ |
||
| 126 | 2 | public function setExpiryDateTime(DateTime $dateTime) |
|
| 127 | { |
||
| 128 | 2 | $this->expiryDateTime = $dateTime; |
|
| 129 | 2 | } |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Set the identifier of the user associated with the token. |
||
| 133 | * |
||
| 134 | * @param OAuthUser $identifier The identifier of the user |
||
| 135 | */ |
||
| 136 | 2 | public function setUserIdentifier($identifier) |
|
| 137 | { |
||
| 138 | 2 | $this->userIdentifier = $identifier; |
|
| 139 | 2 | } |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Get the token user's identifier. |
||
| 143 | * |
||
| 144 | * @return OAuthUser |
||
| 145 | */ |
||
| 146 | 2 | public function getUserIdentifier() |
|
| 147 | { |
||
| 148 | 2 | return $this->userIdentifier; |
|
|
0 ignored issues
–
show
|
|||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Get the client that the token was issued to. |
||
| 153 | * |
||
| 154 | * @return ClientEntityInterface |
||
| 155 | */ |
||
| 156 | 2 | public function getClient() |
|
| 157 | { |
||
| 158 | 2 | return $this->client; |
|
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Set the client that the token was issued to. |
||
| 163 | * |
||
| 164 | * @param ClientEntityInterface $client |
||
| 165 | */ |
||
| 166 | 2 | public function setClient(ClientEntityInterface $client) |
|
| 167 | { |
||
| 168 | 2 | $this->client = $client; |
|
| 169 | 2 | } |
|
| 170 | |||
| 171 | /** |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | 2 | public function getRedirectUri() |
|
| 175 | { |
||
| 176 | 2 | return $this->redirectUri; |
|
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param string $uri |
||
| 181 | */ |
||
| 182 | 2 | public function setRedirectUri($uri) |
|
| 183 | { |
||
| 184 | 2 | $this->redirectUri = $uri; |
|
| 185 | 2 | } |
|
| 186 | |||
| 187 | /** |
||
| 188 | * @return bool |
||
| 189 | */ |
||
| 190 | 1 | public function isRevoked(): bool |
|
| 191 | { |
||
| 192 | 1 | return $this->revoked; |
|
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param bool $revoked |
||
| 197 | */ |
||
| 198 | 1 | public function setRevoked(bool $revoked): void |
|
| 199 | { |
||
| 200 | 1 | $this->revoked = $revoked; |
|
| 201 | } |
||
| 202 | } |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: