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