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