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
|
6 |
|
public function __construct() |
71
|
|
|
{ |
72
|
6 |
|
$this->scopes = new ArrayCollection(); |
73
|
6 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
1 |
|
public function getIdentifier() |
79
|
|
|
{ |
80
|
1 |
|
return $this->identifier; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $identifier |
85
|
|
|
*/ |
86
|
1 |
|
public function setIdentifier($identifier) |
87
|
|
|
{ |
88
|
1 |
|
$this->identifier = $identifier; |
89
|
1 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param ScopeEntityInterface $scope |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
1 |
|
public function addScope(ScopeEntityInterface $scope) |
96
|
|
|
{ |
97
|
1 |
|
$this->scopes->add($scope); |
98
|
1 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Return an array of scopes associated with the token. |
103
|
|
|
* |
104
|
|
|
* @return ScopeEntityInterface[] |
105
|
|
|
*/ |
106
|
1 |
|
public function getScopes() |
107
|
|
|
{ |
108
|
1 |
|
return $this->scopes->toArray(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the token's expiry date time. |
113
|
|
|
* |
114
|
|
|
* @return DateTime |
115
|
|
|
*/ |
116
|
1 |
|
public function getExpiryDateTime() |
117
|
|
|
{ |
118
|
1 |
|
return $this->expiryDateTime; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set the date time when the token expires. |
123
|
|
|
* |
124
|
|
|
* @param DateTime $dateTime |
125
|
|
|
*/ |
126
|
1 |
|
public function setExpiryDateTime(DateTime $dateTime) |
127
|
|
|
{ |
128
|
1 |
|
$this->expiryDateTime = $dateTime; |
129
|
1 |
|
} |
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
|
1 |
|
public function setUserIdentifier($identifier) |
137
|
|
|
{ |
138
|
1 |
|
$this->userIdentifier = $identifier; |
139
|
1 |
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get the token user's identifier. |
143
|
|
|
* |
144
|
|
|
* @return OAuthUser |
145
|
|
|
*/ |
146
|
1 |
|
public function getUserIdentifier() |
147
|
|
|
{ |
148
|
1 |
|
return $this->userIdentifier; |
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get the client that the token was issued to. |
153
|
|
|
* |
154
|
|
|
* @return ClientEntityInterface |
155
|
|
|
*/ |
156
|
1 |
|
public function getClient() |
157
|
|
|
{ |
158
|
1 |
|
return $this->client; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Set the client that the token was issued to. |
163
|
|
|
* |
164
|
|
|
* @param ClientEntityInterface $client |
165
|
|
|
*/ |
166
|
1 |
|
public function setClient(ClientEntityInterface $client) |
167
|
|
|
{ |
168
|
1 |
|
$this->client = $client; |
169
|
1 |
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
1 |
|
public function getRedirectUri() |
175
|
|
|
{ |
176
|
1 |
|
return $this->redirectUri; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $uri |
181
|
|
|
*/ |
182
|
1 |
|
public function setRedirectUri($uri) |
183
|
|
|
{ |
184
|
1 |
|
$this->redirectUri = $uri; |
185
|
1 |
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return bool |
189
|
|
|
*/ |
190
|
|
|
public function isRevoked(): bool |
191
|
|
|
{ |
192
|
|
|
return $this->revoked; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param bool $revoked |
197
|
|
|
*/ |
198
|
|
|
public function setRevoked(bool $revoked): void |
199
|
|
|
{ |
200
|
|
|
$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: