1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Explicit Architecture POC, |
7
|
|
|
* which is created on top of the Symfony Demo application. |
8
|
|
|
* |
9
|
|
|
* (c) Herberto Graça <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Acme\App\Infrastructure\Auth\Authentication\Oauth; |
16
|
|
|
|
17
|
|
|
use Acme\App\Core\SharedKernel\Component\User\Domain\User\UserId; |
18
|
|
|
use DateTime; |
19
|
|
|
use DateTimeImmutable; |
20
|
|
|
use DateTimeInterface; |
21
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; |
22
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
23
|
|
|
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait; |
24
|
|
|
use League\OAuth2\Server\Entities\Traits\EntityTrait; |
25
|
|
|
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait; |
26
|
|
|
|
27
|
|
|
class OauthAccessToken implements AccessTokenEntityInterface |
28
|
|
|
{ |
29
|
|
|
use AccessTokenTrait; |
30
|
|
|
use EntityTrait; |
31
|
|
|
use TokenEntityTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
private $revoked = false; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var DateTimeImmutable |
40
|
|
|
*/ |
41
|
|
|
private $createdAt; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var DateTimeImmutable |
45
|
|
|
*/ |
46
|
|
|
private $updatedAt; |
47
|
|
|
|
48
|
|
|
public function __construct( |
49
|
|
|
UserId $userId, |
50
|
|
|
ClientEntityInterface $client, |
51
|
|
|
array $scopes = [], |
52
|
|
|
DateTimeInterface $expiryDate = null |
53
|
|
|
) { |
54
|
|
|
$this->setIdentifier(new OauthAccessTokenId()); |
55
|
|
|
$this->setUserIdentifier($userId); |
|
|
|
|
56
|
|
|
$this->setClient($client); |
57
|
|
|
foreach ($scopes as $scope) { |
58
|
|
|
$this->addScope($scope); |
59
|
|
|
} |
60
|
|
|
if ($expiryDate) { |
61
|
|
|
$this->setExpiryDateTime( |
62
|
|
|
$expiryDate instanceof DateTimeImmutable |
63
|
|
|
? DateTime::createFromImmutable($expiryDate) |
64
|
|
|
: $expiryDate |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function isRevoked(): bool |
70
|
|
|
{ |
71
|
|
|
return $this->revoked; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function revoke(): void |
75
|
|
|
{ |
76
|
|
|
$this->revoked = true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* It will only set the identifier if it's not yet set. |
81
|
|
|
*/ |
82
|
|
|
public function setIdentifier($identifier): void |
83
|
|
|
{ |
84
|
|
|
$this->identifier = $this->identifier ?? $identifier; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: