|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OAuth2Framework\ServerBundle\Tests\TestBundle\Entity; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; |
|
17
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
18
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCode as CoreAuthorizationCode; |
|
19
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeId; |
|
20
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeRepository as AuthorizationCodeRepositoryInterface; |
|
21
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
|
22
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
|
23
|
|
|
use OAuth2Framework\Component\Core\ResourceServer\ResourceServerId; |
|
24
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
|
25
|
|
|
|
|
26
|
|
|
final class AuthorizationCodeRepository implements AuthorizationCodeRepositoryInterface, ServiceEntityRepositoryInterface |
|
27
|
|
|
{ |
|
28
|
|
|
private $entityRepository; |
|
29
|
|
|
private $entityManager; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(ManagerRegistry $managerRegistry) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->entityManager = $managerRegistry->getManagerForClass(AuthorizationCode::class); |
|
34
|
|
|
$this->entityRepository = $this->entityManager->getRepository(AuthorizationCode::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function find(AuthorizationCodeId $authorizationCodeId): ?CoreAuthorizationCode |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
return $this->entityRepository->find($authorizationCodeId); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function save(CoreAuthorizationCode $accessToken): void |
|
43
|
|
|
{ |
|
44
|
|
|
if (!$accessToken instanceof AuthorizationCode) { |
|
45
|
|
|
throw new \InvalidArgumentException('Unsupported authorization code class'); |
|
46
|
|
|
} |
|
47
|
|
|
$this->entityManager->persist($accessToken); |
|
48
|
|
|
$this->entityManager->flush(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function create(ClientId $clientId, UserAccountId $userAccountId, array $queryParameters, string $redirectUri, \DateTimeImmutable $expiresAt, DataBag $parameter, DataBag $metadata, ?ResourceServerId $resourceServerId): CoreAuthorizationCode |
|
52
|
|
|
{ |
|
53
|
|
|
return new AuthorizationCode( |
|
54
|
|
|
new AuthorizationCodeId(\bin2hex(\random_bytes(32))), |
|
55
|
|
|
$clientId, |
|
56
|
|
|
$userAccountId, |
|
57
|
|
|
$queryParameters, |
|
58
|
|
|
$redirectUri, |
|
59
|
|
|
$expiresAt, |
|
60
|
|
|
$parameter, |
|
61
|
|
|
$metadata, |
|
62
|
|
|
$resourceServerId |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.