|
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\Component\AuthorizationCodeGrant\Command; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCode; |
|
17
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeRepository; |
|
18
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\Event\AuthorizationCodeCreatedEvent; |
|
19
|
|
|
use SimpleBus\SymfonyBridge\Bus\EventBus; |
|
20
|
|
|
|
|
21
|
|
|
class CreateAuthorizationCodeHandler |
|
22
|
|
|
{ |
|
23
|
|
|
private $authorizationCodeRepository; |
|
24
|
|
|
private $eventBus; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(AuthorizationCodeRepository $authorizationCodeRepository, EventBus $eventBus) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->authorizationCodeRepository = $authorizationCodeRepository; |
|
29
|
|
|
$this->eventBus = $eventBus; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function handle(CreateAuthorizationCode $command): void |
|
33
|
|
|
{ |
|
34
|
|
|
$authorizationCode = $this->authorizationCodeRepository->find($command->getAuthorizationCodeId()); |
|
35
|
|
|
if ($authorizationCode) { |
|
36
|
|
|
throw new \InvalidArgumentException(\sprintf('The authorization code/ with ID "%s" already exist.', $command->getAuthorizationCodeId()->getValue())); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$authorizationCode = new AuthorizationCode( |
|
40
|
|
|
$command->getAuthorizationCodeId(), |
|
41
|
|
|
$command->getQueryParameter(), |
|
42
|
|
|
$command->getRedirectUri(), |
|
43
|
|
|
$command->getUserAccountId(), |
|
44
|
|
|
$command->getClientId(), |
|
45
|
|
|
$command->getParameter(), |
|
46
|
|
|
$command->getMetadata(), |
|
47
|
|
|
$command->getExpiresAt(), |
|
48
|
|
|
$command->getResourceServerId() |
|
49
|
|
|
); |
|
50
|
|
|
$this->authorizationCodeRepository->save($authorizationCode); |
|
51
|
|
|
$event = new AuthorizationCodeCreatedEvent( |
|
52
|
|
|
$command->getAuthorizationCodeId(), |
|
53
|
|
|
$command->getQueryParameter(), |
|
54
|
|
|
$command->getRedirectUri(), |
|
55
|
|
|
$command->getUserAccountId(), |
|
56
|
|
|
$command->getClientId(), |
|
57
|
|
|
$command->getParameter(), |
|
58
|
|
|
$command->getMetadata(), |
|
59
|
|
|
$command->getExpiresAt(), |
|
60
|
|
|
$command->getResourceServerId() |
|
61
|
|
|
); |
|
62
|
|
|
$this->eventBus->handle($event); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|