1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; |
8
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
9
|
|
|
use League\OAuth2\Server\Entities\ScopeEntityInterface; |
10
|
|
|
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @Entity(repositoryClass="OAuth\Repository\AccessTokenRepository") |
14
|
|
|
* @Table(name="AccessToken") |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
class AccessToken implements AccessTokenEntityInterface |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
use AccessTokenTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var ArrayCollection $scopes |
22
|
|
|
* @ManyToMany(targetEntity="OAuth\Scope", inversedBy="accessTokens") |
23
|
|
|
* @JoinTable(name="AccessTokenScope", |
24
|
|
|
* joinColumns={@JoinColumn(name="scopeId", referencedColumnName="identifier")}, |
25
|
|
|
* inverseJoinColumns={@JoinColumn(name="accessTokenId", referencedColumnName="identifier")} |
26
|
|
|
* ) |
27
|
|
|
*/ |
28
|
|
|
protected $scopes; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var DateTime |
32
|
|
|
* @Column(type="date",nullable=true) |
33
|
|
|
*/ |
34
|
|
|
protected $expiryDateTime; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var User |
38
|
|
|
* @Column(type="integer", length=11) |
39
|
|
|
*/ |
40
|
|
|
protected $userIdentifier; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ClientEntityInterface |
44
|
|
|
* @ManyToOne(targetEntity="OAuth\Client") |
45
|
|
|
* @JoinColumn(name="client", referencedColumnName="identifier") |
46
|
|
|
*/ |
47
|
|
|
protected $client; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
* @Id |
52
|
|
|
* @Column(type="string", length=40) |
53
|
|
|
*/ |
54
|
|
|
protected $identifier; |
55
|
|
|
|
56
|
6 |
|
public function __construct() |
57
|
|
|
{ |
58
|
6 |
|
$this->scopes = new ArrayCollection(); |
59
|
6 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set token |
63
|
|
|
* |
64
|
|
|
* @param string $token |
65
|
|
|
* @return AccessToken |
66
|
|
|
*/ |
67
|
|
|
public function setToken($token) |
68
|
|
|
{ |
69
|
|
|
$this->token = $token; |
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get token |
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
|
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
|
|
|
* @param int $identifier |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
1 |
|
public function setUserIdentifier($identifier) |
136
|
|
|
{ |
137
|
1 |
|
$this->userIdentifier = $identifier; |
|
|
|
|
138
|
1 |
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get the token user's identifier. |
143
|
|
|
* |
144
|
|
|
* @return int |
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
|
|
|
} |
170
|
|
|
} |
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.