|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Alexandre |
|
5
|
|
|
* Date: 31/12/2017 |
|
6
|
|
|
* Time: 00:29 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace OAuth2OLD\Endpoint\Server\Messages\Authorization; |
|
10
|
|
|
use GuzzleHttp\Psr7\Response; |
|
11
|
|
|
use GuzzleHttp\Psr7\Uri; |
|
12
|
|
|
use OAuth2OLD\Credential\AuthorizationCode; |
|
13
|
|
|
use Psr\Http\Message\UriInterface; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Response |
|
18
|
|
|
* @package OAuth2\Endpoints\Server\Messages\Authorization |
|
19
|
|
|
* |
|
20
|
|
|
* @see https://tools.ietf.org/html/rfc6749#section-4.1.2 |
|
21
|
|
|
* |
|
22
|
|
|
* Authorization Response |
|
23
|
|
|
* |
|
24
|
|
|
* If the resource owner grants the access request, the authorization |
|
25
|
|
|
* server issues an authorization code and delivers it to the client by |
|
26
|
|
|
* adding the following parameters to the query component of the |
|
27
|
|
|
* redirection URI using the "application/x-www-form-urlencoded" format, |
|
28
|
|
|
* per Appendix B: |
|
29
|
|
|
* |
|
30
|
|
|
* code |
|
31
|
|
|
* REQUIRED. The authorization code generated by the |
|
32
|
|
|
* authorization server. The authorization code MUST expire |
|
33
|
|
|
* shortly after it is issued to mitigate the risk of leaks. A |
|
34
|
|
|
* maximum authorization code lifetime of 10 minutes is |
|
35
|
|
|
* RECOMMENDED. The client MUST NOT use the authorization code |
|
36
|
|
|
* more than once. If an authorization code is used more than |
|
37
|
|
|
* once, the authorization server MUST deny the request and SHOULD |
|
38
|
|
|
* revoke (when possible) all tokens previously issued based on |
|
39
|
|
|
* that authorization code. The authorization code is bound to |
|
40
|
|
|
* the client identifier and redirection URI. |
|
41
|
|
|
* |
|
42
|
|
|
* state |
|
43
|
|
|
* REQUIRED if the "state" parameter was present in the client |
|
44
|
|
|
* authorization request. The exact value received from the |
|
45
|
|
|
* client. |
|
46
|
|
|
* |
|
47
|
|
|
* For example, the authorization server redirects the user-agent by |
|
48
|
|
|
* sending the following HTTP response: |
|
49
|
|
|
* |
|
50
|
|
|
* HTTP/1.1 302 Found |
|
51
|
|
|
* Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA |
|
52
|
|
|
* &state=xyz |
|
53
|
|
|
* |
|
54
|
|
|
* The client MUST ignore unrecognized response parameters. The |
|
55
|
|
|
* authorization code string size is left undefined by this |
|
56
|
|
|
* specification. The client should avoid making assumptions about code |
|
57
|
|
|
* value sizes. The authorization server SHOULD document the size of |
|
58
|
|
|
* any value it issues. |
|
59
|
|
|
*/ |
|
60
|
|
|
class AuthorizationResponse extends Response |
|
61
|
|
|
{ |
|
62
|
|
|
/** |
|
63
|
|
|
* @var UriInterface |
|
64
|
|
|
*/ |
|
65
|
|
|
private $redirectUri; |
|
66
|
|
|
/** |
|
67
|
|
|
* @var AuthorizationCode |
|
68
|
|
|
*/ |
|
69
|
|
|
private $code; |
|
70
|
|
|
/** |
|
71
|
|
|
* @var string|null |
|
72
|
|
|
*/ |
|
73
|
|
|
private $state; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Response constructor. |
|
77
|
|
|
* @param UriInterface $redirectUri |
|
78
|
|
|
* @param AuthorizationCode $code |
|
79
|
|
|
* @param string $state |
|
80
|
|
|
*/ |
|
81
|
|
|
public function __construct(UriInterface $redirectUri, AuthorizationCode $code, ?string $state = null) |
|
82
|
|
|
{ |
|
83
|
|
|
$redirectUri = Uri::withQueryValue($redirectUri, 'code', $code->getCode()); |
|
84
|
|
|
if ($state) { |
|
85
|
|
|
$redirectUri = Uri::withQueryValue($redirectUri, 'state', $state); |
|
86
|
|
|
} |
|
87
|
|
|
$redirectUri = $redirectUri->__toString(); |
|
88
|
|
|
parent::__construct(302, ['Location' => $redirectUri]); |
|
89
|
|
|
$this->redirectUri = $redirectUri; |
|
|
|
|
|
|
90
|
|
|
$this->code = $code; |
|
91
|
|
|
$this->state = $state; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getCode(): string |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->code; |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return UriInterface |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getRedirectUri(): UriInterface |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->redirectUri; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return string|null |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getState(): ?string |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->state; |
|
116
|
|
|
} |
|
117
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..