Completed
Push — master ( 6e52f0...d9a404 )
by Alexandre
02:29
created

AuthorizationResponse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
ccs 0
cts 23
cp 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getCode() 0 3 1
A getRedirectUri() 0 3 1
A getState() 0 3 1
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $redirectUri of type string is incompatible with the declared type Psr\Http\Message\UriInterface of property $redirectUri.

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..

Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->code returns the type OAuth2OLD\Credential\AuthorizationCode which is incompatible with the type-hinted return string.
Loading history...
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
}