1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; |
7
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
8
|
|
|
use League\OAuth2\Server\Entities\ScopeEntityInterface; |
9
|
|
|
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class AccessToken implements AccessTokenEntityInterface |
13
|
|
|
{ |
14
|
|
|
use AccessTokenTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var ScopeEntityInterface[] |
18
|
|
|
*/ |
19
|
|
|
protected $scopes = []; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var DateTime |
23
|
|
|
*/ |
24
|
|
|
protected $expiryDateTime; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string|int |
28
|
|
|
*/ |
29
|
|
|
protected $userIdentifier; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ClientEntityInterface |
33
|
|
|
*/ |
34
|
|
|
protected $client; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $identifier; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function getIdentifier() |
45
|
|
|
{ |
46
|
|
|
return $this->identifier; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param mixed $identifier |
51
|
|
|
*/ |
52
|
|
|
public function setIdentifier($identifier) |
53
|
|
|
{ |
54
|
|
|
$this->identifier = $identifier; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Associate a scope with the token. |
59
|
|
|
* |
60
|
|
|
* @param ScopeEntityInterface $scope |
61
|
|
|
*/ |
62
|
|
|
public function addScope(ScopeEntityInterface $scope) |
63
|
|
|
{ |
64
|
|
|
$this->scopes[$scope->getIdentifier()] = $scope; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return an array of scopes associated with the token. |
69
|
|
|
* |
70
|
|
|
* @return ScopeEntityInterface[] |
71
|
|
|
*/ |
72
|
|
|
public function getScopes() |
73
|
|
|
{ |
74
|
|
|
return array_values($this->scopes); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get the token's expiry date time. |
79
|
|
|
* |
80
|
|
|
* @return DateTime |
81
|
|
|
*/ |
82
|
|
|
public function getExpiryDateTime() |
83
|
|
|
{ |
84
|
|
|
return $this->expiryDateTime; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Set the date time when the token expires. |
89
|
|
|
* |
90
|
|
|
* @param DateTime $dateTime |
91
|
|
|
*/ |
92
|
|
|
public function setExpiryDateTime(DateTime $dateTime) |
93
|
|
|
{ |
94
|
|
|
$this->expiryDateTime = $dateTime; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the identifier of the user associated with the token. |
99
|
|
|
* |
100
|
|
|
* @param string|int $identifier The identifier of the user |
101
|
|
|
*/ |
102
|
|
|
public function setUserIdentifier($identifier) |
103
|
|
|
{ |
104
|
|
|
$this->userIdentifier = $identifier; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get the token user's identifier. |
109
|
|
|
* |
110
|
|
|
* @return string|int |
111
|
|
|
*/ |
112
|
|
|
public function getUserIdentifier() |
113
|
|
|
{ |
114
|
|
|
return $this->userIdentifier; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get the client that the token was issued to. |
119
|
|
|
* |
120
|
|
|
* @return ClientEntityInterface |
121
|
|
|
*/ |
122
|
|
|
public function getClient() |
123
|
|
|
{ |
124
|
|
|
return $this->client; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Set the client that the token was issued to. |
129
|
|
|
* |
130
|
|
|
* @param ClientEntityInterface $client |
131
|
|
|
*/ |
132
|
|
|
public function setClient(ClientEntityInterface $client) |
133
|
|
|
{ |
134
|
|
|
$this->client = $client; |
135
|
|
|
} |
136
|
|
|
} |