1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Lookyman\NetteOAuth2Server\Storage\Doctrine\AuthCode; |
5
|
|
|
|
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
use League\OAuth2\Server\Entities\AuthCodeEntityInterface; |
10
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
11
|
|
|
use League\OAuth2\Server\Entities\ScopeEntityInterface; |
12
|
|
|
use Lookyman\NetteOAuth2Server\Storage\Doctrine\Client\ClientEntity; |
13
|
|
|
use Lookyman\NetteOAuth2Server\Storage\Doctrine\Scope\ScopeEntity; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @ORM\Entity() |
17
|
|
|
* @ORM\Table(name="auth_code") |
18
|
|
|
*/ |
19
|
|
|
class AuthCodeEntity implements AuthCodeEntityInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @ORM\Id() |
23
|
|
|
* @ORM\GeneratedValue() |
24
|
|
|
* @ORM\Column(type="integer") |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
private $id; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @ORM\Column(type="boolean") |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
private $revoked = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @ORM\Column(type="text") |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $redirectUri; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @ORM\Column(type="string", length=80, unique=true) |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $identifier; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\Column(type="datetimetz") |
49
|
|
|
* @var \DateTime |
50
|
|
|
*/ |
51
|
|
|
private $expiryDateTime; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\Column(type="text") |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
private $userIdentifier; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @ORM\ManyToOne(targetEntity="Lookyman\NetteOAuth2Server\Storage\Doctrine\Client\ClientEntity") |
61
|
|
|
* @ORM\JoinColumn(nullable=false) |
62
|
|
|
* @var ClientEntity |
63
|
|
|
*/ |
64
|
|
|
private $client; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @ORM\ManyToMany(targetEntity="Lookyman\NetteOAuth2Server\Storage\Doctrine\Scope\ScopeEntity") |
68
|
|
|
* @ORM\JoinTable(name="auth_code_scope") |
69
|
|
|
* @var Collection of ScopeEntity |
70
|
|
|
*/ |
71
|
|
|
private $scopes; |
72
|
|
|
|
73
|
|
|
public function __construct() |
74
|
|
|
{ |
75
|
|
|
$this->scopes = new ArrayCollection(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return int|null |
80
|
|
|
*/ |
81
|
|
|
public function getId() |
82
|
|
|
{ |
83
|
|
|
return $this->id; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function __clone() |
87
|
|
|
{ |
88
|
|
|
$this->id = null; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
|
|
public function isRevoked(): bool |
95
|
|
|
{ |
96
|
|
|
return $this->revoked; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param bool $revoked |
101
|
|
|
*/ |
102
|
|
|
public function setRevoked(bool $revoked) |
103
|
|
|
{ |
104
|
|
|
$this->revoked = $revoked; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function getRedirectUri() |
111
|
|
|
{ |
112
|
|
|
return $this->redirectUri; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $uri |
117
|
|
|
*/ |
118
|
|
|
public function setRedirectUri($uri) |
119
|
|
|
{ |
120
|
|
|
$this->redirectUri = (string) $uri; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getIdentifier() |
127
|
|
|
{ |
128
|
|
|
return $this->identifier; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $identifier |
133
|
|
|
*/ |
134
|
|
|
public function setIdentifier($identifier) |
135
|
|
|
{ |
136
|
|
|
$this->identifier = $identifier; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return \DateTime |
141
|
|
|
*/ |
142
|
|
|
public function getExpiryDateTime() |
143
|
|
|
{ |
144
|
|
|
return $this->expiryDateTime; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param \DateTime $dateTime |
149
|
|
|
*/ |
150
|
|
|
public function setExpiryDateTime(\DateTime $dateTime) |
151
|
|
|
{ |
152
|
|
|
$this->expiryDateTime = $dateTime; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param string $identifier |
157
|
|
|
*/ |
158
|
|
|
public function setUserIdentifier($identifier) |
159
|
|
|
{ |
160
|
|
|
$this->userIdentifier = $identifier; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function getUserIdentifier() |
167
|
|
|
{ |
168
|
|
|
return $this->userIdentifier; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return ClientEntityInterface |
173
|
|
|
*/ |
174
|
|
|
public function getClient() |
175
|
|
|
{ |
176
|
|
|
return $this->client; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param ClientEntityInterface $client |
181
|
|
|
*/ |
182
|
|
|
public function setClient(ClientEntityInterface $client) |
183
|
|
|
{ |
184
|
|
|
if ($client instanceof ClientEntity) { |
185
|
|
|
$this->client = $client; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param ScopeEntityInterface $scope |
191
|
|
|
*/ |
192
|
|
|
public function addScope(ScopeEntityInterface $scope) |
193
|
|
|
{ |
194
|
|
|
if ($scope instanceof ScopeEntity && !$this->scopes->contains($scope)) { |
195
|
|
|
$this->scopes->add($scope); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return ScopeEntityInterface[] |
201
|
|
|
*/ |
202
|
|
|
public function getScopes() |
203
|
|
|
{ |
204
|
|
|
return $this->scopes->toArray(); |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|