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