1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use League\OAuth2\Server\Entities\AuthCodeEntityInterface; |
8
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
9
|
|
|
use League\OAuth2\Server\Entities\ScopeEntityInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @Entity(repositoryClass="OAuth\Repository\AuthCodeRepository") |
13
|
|
|
* @Table(name="AuthCode") |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class AuthCode implements AuthCodeEntityInterface |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var null|string |
20
|
|
|
* @Column(type="string", length=255, nullable=true) |
21
|
|
|
*/ |
22
|
|
|
protected $redirectUri; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ArrayCollection $scopes |
26
|
|
|
* @ManyToMany(targetEntity="OAuth\Scope") |
27
|
|
|
* @JoinTable(name="AuthTokenScope", |
28
|
|
|
* joinColumns={@JoinColumn(name="scopeId", referencedColumnName="identifier")}, |
29
|
|
|
* inverseJoinColumns={@JoinColumn(name="authTokenId", referencedColumnName="identifier")}) |
30
|
|
|
*/ |
31
|
|
|
protected $scopes; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var DateTime |
35
|
|
|
* @Column(type="date",nullable=true) |
36
|
|
|
*/ |
37
|
|
|
protected $expiryDateTime; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var User |
41
|
|
|
* @OneToOne(targetEntity="OAuth\User") |
42
|
|
|
* @JoinColumn(name="client", referencedColumnName="id") |
43
|
|
|
*/ |
44
|
|
|
protected $userIdentifier; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var ClientEntityInterface |
48
|
|
|
* @ManyToOne(targetEntity="OAuth\Client") |
49
|
|
|
* @JoinColumn(name="client", referencedColumnName="identifier") |
50
|
|
|
*/ |
51
|
|
|
protected $client; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
* @Id |
56
|
|
|
* @Column(type="string", length=40) |
57
|
|
|
*/ |
58
|
|
|
protected $identifier; |
59
|
|
|
|
60
|
6 |
|
public function __construct() |
61
|
|
|
{ |
62
|
6 |
|
$this->scopes = new ArrayCollection(); |
63
|
6 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
1 |
|
public function getIdentifier() |
69
|
|
|
{ |
70
|
1 |
|
return $this->identifier; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $identifier |
75
|
|
|
*/ |
76
|
1 |
|
public function setIdentifier($identifier) |
77
|
|
|
{ |
78
|
1 |
|
$this->identifier = $identifier; |
79
|
1 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param ScopeEntityInterface $scope |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
1 |
|
public function addScope(ScopeEntityInterface $scope) |
86
|
|
|
{ |
87
|
1 |
|
$this->scopes->add($scope); |
88
|
1 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Return an array of scopes associated with the token. |
93
|
|
|
* |
94
|
|
|
* @return ScopeEntityInterface[] |
95
|
|
|
*/ |
96
|
1 |
|
public function getScopes() |
97
|
|
|
{ |
98
|
1 |
|
return $this->scopes->toArray(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the token's expiry date time. |
103
|
|
|
* |
104
|
|
|
* @return DateTime |
105
|
|
|
*/ |
106
|
1 |
|
public function getExpiryDateTime() |
107
|
|
|
{ |
108
|
1 |
|
return $this->expiryDateTime; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set the date time when the token expires. |
113
|
|
|
* |
114
|
|
|
* @param DateTime $dateTime |
115
|
|
|
*/ |
116
|
1 |
|
public function setExpiryDateTime(DateTime $dateTime) |
117
|
|
|
{ |
118
|
1 |
|
$this->expiryDateTime = $dateTime; |
119
|
1 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set the identifier of the user associated with the token. |
123
|
|
|
* |
124
|
|
|
* @param User $identifier The identifier of the user |
125
|
|
|
*/ |
126
|
1 |
|
public function setUserIdentifier($identifier) |
127
|
|
|
{ |
128
|
1 |
|
$this->userIdentifier = $identifier; |
129
|
1 |
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get the token user's identifier. |
133
|
|
|
* |
134
|
|
|
* @return User |
135
|
|
|
*/ |
136
|
1 |
|
public function getUserIdentifier() |
137
|
|
|
{ |
138
|
1 |
|
return $this->userIdentifier; |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get the client that the token was issued to. |
143
|
|
|
* |
144
|
|
|
* @return ClientEntityInterface |
145
|
|
|
*/ |
146
|
1 |
|
public function getClient() |
147
|
|
|
{ |
148
|
1 |
|
return $this->client; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Set the client that the token was issued to. |
153
|
|
|
* |
154
|
|
|
* @param ClientEntityInterface $client |
155
|
|
|
*/ |
156
|
1 |
|
public function setClient(ClientEntityInterface $client) |
157
|
|
|
{ |
158
|
1 |
|
$this->client = $client; |
159
|
1 |
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
1 |
|
public function getRedirectUri() |
165
|
|
|
{ |
166
|
1 |
|
return $this->redirectUri; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $uri |
171
|
|
|
*/ |
172
|
1 |
|
public function setRedirectUri($uri) |
173
|
|
|
{ |
174
|
1 |
|
$this->redirectUri = $uri; |
175
|
|
|
} |
176
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.