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 |
|
public function __construct() |
58
|
|
|
{ |
59
|
6 |
|
$this->scopes = new ArrayCollection(); |
60
|
6 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set token |
64
|
|
|
* |
65
|
|
|
* @param string $token |
66
|
|
|
* @return AccessToken |
67
|
|
|
*/ |
68
|
|
|
public function setToken($token) |
69
|
|
|
{ |
70
|
|
|
$this->token = $token; |
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get token |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
2 |
|
public function getIdentifier() |
80
|
|
|
{ |
81
|
2 |
|
return $this->identifier; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $identifier |
86
|
|
|
*/ |
87
|
2 |
|
public function setIdentifier($identifier) |
88
|
|
|
{ |
89
|
2 |
|
$this->identifier = $identifier; |
90
|
2 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param ScopeEntityInterface $scope |
94
|
|
|
* @return $this |
95
|
|
|
*/ |
96
|
1 |
|
public function addScope(ScopeEntityInterface $scope) |
97
|
|
|
{ |
98
|
1 |
|
$this->scopes->add($scope); |
99
|
1 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Return an array of scopes associated with the token. |
104
|
|
|
* |
105
|
|
|
* @return ScopeEntityInterface[] |
106
|
|
|
*/ |
107
|
1 |
|
public function getScopes() |
108
|
|
|
{ |
109
|
1 |
|
return $this->scopes->toArray(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get the token's expiry date time. |
114
|
|
|
* |
115
|
|
|
* @return DateTime |
116
|
|
|
*/ |
117
|
1 |
|
public function getExpiryDateTime() |
118
|
|
|
{ |
119
|
1 |
|
return $this->expiryDateTime; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Set the date time when the token expires. |
124
|
|
|
* |
125
|
|
|
* @param DateTime $dateTime |
126
|
|
|
*/ |
127
|
1 |
|
public function setExpiryDateTime(DateTime $dateTime) |
128
|
|
|
{ |
129
|
1 |
|
$this->expiryDateTime = $dateTime; |
130
|
1 |
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param int $identifier |
134
|
|
|
* @return $this |
135
|
|
|
*/ |
136
|
1 |
|
public function setUserIdentifier($identifier) |
137
|
|
|
{ |
138
|
1 |
|
$this->userIdentifier = $identifier; |
139
|
1 |
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get the token user's identifier. |
144
|
|
|
* |
145
|
|
|
* @return int |
146
|
|
|
*/ |
147
|
1 |
|
public function getUserIdentifier() |
148
|
|
|
{ |
149
|
1 |
|
return $this->userIdentifier; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Get the client that the token was issued to. |
154
|
|
|
* |
155
|
|
|
* @return ClientEntityInterface |
156
|
|
|
*/ |
157
|
1 |
|
public function getClient() |
158
|
|
|
{ |
159
|
1 |
|
return $this->client; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Set the client that the token was issued to. |
164
|
|
|
* |
165
|
|
|
* @param ClientEntityInterface $client |
166
|
|
|
*/ |
167
|
1 |
|
public function setClient(ClientEntityInterface $client) |
168
|
|
|
{ |
169
|
1 |
|
$this->client = $client; |
170
|
|
|
} |
171
|
|
|
} |