forked from ajgarlag/oauth2-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthorizationRequestResolveEvent.php
115 lines (93 loc) · 2.84 KB
/
AuthorizationRequestResolveEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace Trikoder\Bundle\OAuth2Bundle\Event;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use League\OAuth2\Server\Entities\UserEntityInterface;
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
use LogicException;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\EventDispatcher\Event;
final class AuthorizationRequestResolveEvent extends Event
{
public const AUTHORIZATION_APPROVED = true;
public const AUTHORIZATION_DENIED = false;
/**
* @var AuthorizationRequest
*/
private $authorizationRequest;
/**
* @var ?ResponseInterface
*/
private $response;
/**
* @var bool
*/
private $authorizationResolution = self::AUTHORIZATION_DENIED;
public function __construct(AuthorizationRequest $authorizationRequest)
{
$this->authorizationRequest = $authorizationRequest;
}
public function getAuhorizationResolution(): bool
{
return $this->authorizationResolution;
}
public function resolveAuthorization(bool $authorizationResolution): void
{
$this->authorizationResolution = $authorizationResolution;
$this->response = null;
}
public function hasResponse(): bool
{
return $this->response instanceof ResponseInterface;
}
public function getResponse(): ResponseInterface
{
if (!$this->hasResponse()) {
throw new LogicException('There is no response. You should call "hasResponse" to check if the response exists.');
}
return $this->response;
}
public function setResponse(ResponseInterface $response): void
{
$this->response = $response;
}
public function getGrantTypeId(): string
{
return $this->authorizationRequest->getGrantTypeId();
}
public function getClient(): ClientEntityInterface
{
return $this->authorizationRequest->getClient();
}
public function getUser(): UserEntityInterface
{
return $this->authorizationRequest->getUser();
}
/**
* @return ScopeEntityInterface[]
*/
public function getScopes(): array
{
return $this->authorizationRequest->getScopes();
}
public function isAuthorizationApproved(): bool
{
return $this->authorizationRequest->isAuthorizationApproved();
}
public function getRedirectUri(): ?string
{
return $this->authorizationRequest->getRedirectUri();
}
public function getState(): ?string
{
return $this->authorizationRequest->getState();
}
public function getCodeChallenge(): string
{
return $this->authorizationRequest->getCodeChallenge();
}
public function getCodeChallengeMethod(): string
{
return $this->authorizationRequest->getCodeChallengeMethod();
}
}