1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; |
8
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
9
|
|
|
use League\OAuth2\Server\Entities\ScopeEntityInterface; |
10
|
|
|
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @Entity |
14
|
|
|
* @Table(name="AccessToken") |
15
|
|
|
*/ |
16
|
|
|
class AccessToken implements AccessTokenEntityInterface |
17
|
|
|
{ |
18
|
|
|
use AccessTokenTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var ArrayCollection $scopes |
22
|
|
|
* @ManyToMany(targetEntity="OAuth\Scope") |
23
|
|
|
* @JoinTable(name="AccessTokenScope", |
24
|
|
|
* joinColumns={@JoinColumn(name="scopeId", referencedColumnName="identifier")}, |
25
|
|
|
* inverseJoinColumns={@JoinColumn(name="accessTokenId", referencedColumnName="identifier")} |
26
|
|
|
* ) |
27
|
|
|
*/ |
28
|
|
|
protected $scopes; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var DateTime |
32
|
|
|
* @Column(type="date",nullable=true) |
33
|
|
|
*/ |
34
|
|
|
protected $expiryDateTime; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
* @ManyToOne(targetEntity="OAuth\User") |
39
|
|
|
* @JoinColumn(name="userIdentifier", referencedColumnName="id") |
40
|
|
|
*/ |
41
|
|
|
protected $userIdentifier; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var ClientEntityInterface |
45
|
|
|
* @ManyToOne(targetEntity="OAuth\Client") |
46
|
|
|
* @JoinColumn(name="client", referencedColumnName="identifier") |
47
|
|
|
*/ |
48
|
|
|
protected $client; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
* @Id |
53
|
|
|
* @Column(type="string", length=40) |
54
|
|
|
*/ |
55
|
|
|
protected $identifier; |
56
|
|
|
|
57
|
|
|
public function __construct() |
58
|
|
|
{ |
59
|
|
|
$this->scopes = new ArrayCollection(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
|
|
public function getIdentifier() |
66
|
|
|
{ |
67
|
|
|
return $this->identifier; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param mixed $identifier |
72
|
|
|
*/ |
73
|
|
|
public function setIdentifier($identifier) |
74
|
|
|
{ |
75
|
|
|
$this->identifier = $identifier; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Associate a scope with the token. |
80
|
|
|
* |
81
|
|
|
* @param ScopeEntityInterface $scope |
82
|
|
|
*/ |
83
|
|
|
public function addScope(ScopeEntityInterface $scope) |
84
|
|
|
{ |
85
|
|
|
$this->scopes[$scope->getIdentifier()] = $scope; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Return an array of scopes associated with the token. |
90
|
|
|
* |
91
|
|
|
* @return ScopeEntityInterface[] |
92
|
|
|
*/ |
93
|
|
|
public function getScopes() |
94
|
|
|
{ |
95
|
|
|
return array_values($this->scopes); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get the token's expiry date time. |
100
|
|
|
* |
101
|
|
|
* @return DateTime |
102
|
|
|
*/ |
103
|
|
|
public function getExpiryDateTime() |
104
|
|
|
{ |
105
|
|
|
return $this->expiryDateTime; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Set the date time when the token expires. |
110
|
|
|
* |
111
|
|
|
* @param DateTime $dateTime |
112
|
|
|
*/ |
113
|
|
|
public function setExpiryDateTime(DateTime $dateTime) |
114
|
|
|
{ |
115
|
|
|
$this->expiryDateTime = $dateTime; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Set the identifier of the user associated with the token. |
120
|
|
|
* |
121
|
|
|
* @param string|int $identifier The identifier of the user |
122
|
|
|
*/ |
123
|
|
|
public function setUserIdentifier($identifier) |
124
|
|
|
{ |
125
|
|
|
$this->userIdentifier = $identifier; |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get the token user's identifier. |
130
|
|
|
* |
131
|
|
|
* @return string|int |
132
|
|
|
*/ |
133
|
|
|
public function getUserIdentifier() |
134
|
|
|
{ |
135
|
|
|
return $this->userIdentifier; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the client that the token was issued to. |
140
|
|
|
* |
141
|
|
|
* @return ClientEntityInterface |
142
|
|
|
*/ |
143
|
|
|
public function getClient() |
144
|
|
|
{ |
145
|
|
|
return $this->client; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set the client that the token was issued to. |
150
|
|
|
* |
151
|
|
|
* @param ClientEntityInterface $client |
152
|
|
|
*/ |
153
|
|
|
public function setClient(ClientEntityInterface $client) |
154
|
|
|
{ |
155
|
|
|
$this->client = $client; |
156
|
|
|
} |
157
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.