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