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\AccessTokenEntityInterface; |
9
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
10
|
|
|
use League\OAuth2\Server\Entities\ScopeEntityInterface; |
11
|
|
|
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @ORM\Entity(repositoryClass="OAuth\Repository\AccessTokenRepository") |
15
|
|
|
* @ORM\Table(name="AccessToken") |
16
|
|
|
*/ |
17
|
|
|
class AccessToken implements AccessTokenEntityInterface |
18
|
|
|
{ |
19
|
|
|
use AccessTokenTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ArrayCollection $scopes |
23
|
|
|
* @ORM\ManyToMany(targetEntity="Scope", inversedBy="accessTokens") |
24
|
|
|
* @ORM\JoinTable(name="AccessToken_Scope", |
25
|
|
|
* joinColumns={@ORM\JoinColumn(name="token_id", referencedColumnName="identifier")}, |
26
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="identifier")} |
27
|
|
|
* ) |
28
|
|
|
*/ |
29
|
|
|
protected $scopes; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var DateTime |
33
|
|
|
* @ORM\Column(type="date",nullable=true) |
34
|
|
|
*/ |
35
|
|
|
protected $expiryDateTime; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var int |
39
|
|
|
* @ORM\Column(type="integer", length=11) |
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\Id |
53
|
|
|
* @ORM\Column(type="string", length=40) |
54
|
|
|
*/ |
55
|
|
|
protected $identifier; |
56
|
|
|
|
57
|
6 |
|
/** |
58
|
|
|
* @var bool |
59
|
6 |
|
* @ORM\Column(type="boolean", default=false) |
60
|
6 |
|
*/ |
61
|
|
|
protected $revoked; |
62
|
|
|
|
63
|
|
|
public function __construct() |
64
|
|
|
{ |
65
|
|
|
$this->scopes = new ArrayCollection(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Set token |
70
|
|
|
* |
71
|
|
|
* @param string $token |
72
|
|
|
* @return AccessToken |
73
|
|
|
*/ |
74
|
|
|
public function setToken($token) |
75
|
|
|
{ |
76
|
|
|
$this->token = $token; |
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
2 |
|
|
80
|
|
|
/** |
81
|
2 |
|
* Get token |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getIdentifier() |
86
|
|
|
{ |
87
|
2 |
|
return $this->identifier; |
88
|
|
|
} |
89
|
2 |
|
|
90
|
2 |
|
/** |
91
|
|
|
* @param string $identifier |
92
|
|
|
*/ |
93
|
|
|
public function setIdentifier($identifier) |
94
|
|
|
{ |
95
|
|
|
$this->identifier = $identifier; |
96
|
1 |
|
} |
97
|
|
|
|
98
|
1 |
|
/** |
99
|
1 |
|
* @param ScopeEntityInterface $scope |
100
|
|
|
* @return $this |
101
|
|
|
*/ |
102
|
|
|
public function addScope(ScopeEntityInterface $scope) |
103
|
|
|
{ |
104
|
|
|
$this->scopes->add($scope); |
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
1 |
|
|
108
|
|
|
/** |
109
|
1 |
|
* Return an array of scopes associated with the token. |
110
|
|
|
* |
111
|
|
|
* @return ScopeEntityInterface[] |
112
|
|
|
*/ |
113
|
|
|
public function getScopes() |
114
|
|
|
{ |
115
|
|
|
return $this->scopes->toArray(); |
116
|
|
|
} |
117
|
1 |
|
|
118
|
|
|
/** |
119
|
1 |
|
* Get the token's expiry date time. |
120
|
|
|
* |
121
|
|
|
* @return DateTime |
122
|
|
|
*/ |
123
|
|
|
public function getExpiryDateTime() |
124
|
|
|
{ |
125
|
|
|
return $this->expiryDateTime; |
126
|
|
|
} |
127
|
1 |
|
|
128
|
|
|
/** |
129
|
1 |
|
* Set the date time when the token expires. |
130
|
1 |
|
* |
131
|
|
|
* @param DateTime $dateTime |
132
|
|
|
*/ |
133
|
|
|
public function setExpiryDateTime(DateTime $dateTime) |
134
|
|
|
{ |
135
|
|
|
$this->expiryDateTime = $dateTime; |
136
|
1 |
|
} |
137
|
|
|
|
138
|
1 |
|
/** |
139
|
1 |
|
* @param int $identifier |
140
|
|
|
* @return $this |
141
|
|
|
*/ |
142
|
|
|
public function setUserIdentifier($identifier) |
143
|
|
|
{ |
144
|
|
|
$this->userIdentifier = $identifier; |
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
1 |
|
|
148
|
|
|
/** |
149
|
1 |
|
* Get the token user's identifier. |
150
|
|
|
* |
151
|
|
|
* @return int |
152
|
|
|
*/ |
153
|
|
|
public function getUserIdentifier() |
154
|
|
|
{ |
155
|
|
|
return $this->userIdentifier; |
156
|
|
|
} |
157
|
1 |
|
|
158
|
|
|
/** |
159
|
1 |
|
* Get the client that the token was issued to. |
160
|
|
|
* |
161
|
|
|
* @return ClientEntityInterface |
162
|
|
|
*/ |
163
|
|
|
public function getClient() |
164
|
|
|
{ |
165
|
|
|
return $this->client; |
166
|
|
|
} |
167
|
1 |
|
|
168
|
|
|
/** |
169
|
1 |
|
* Set the client that the token was issued to. |
170
|
1 |
|
* |
171
|
|
|
* @param ClientEntityInterface $client |
172
|
|
|
*/ |
173
|
|
|
public function setClient(ClientEntityInterface $client) |
174
|
|
|
{ |
175
|
|
|
$this->client = $client; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return bool |
180
|
|
|
*/ |
181
|
|
|
public function isRevoked(): bool |
182
|
|
|
{ |
183
|
|
|
return $this->revoked; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param bool $revoked |
188
|
|
|
*/ |
189
|
|
|
public function setRevoked(bool $revoked): void |
190
|
|
|
{ |
191
|
|
|
$this->revoked = $revoked; |
192
|
|
|
} |
193
|
|
|
} |