Methods

Source

LineCode
1
<?php
2
3
/**
4
    The authorization code is obtained by using an authorization server
5
    as an intermediary between the client and resource owner.  Instead of
6
    requesting authorization directly from the resource owner, the client
7
    directs the resource owner to an authorization server (via its
8
    user-agent as defined in [RFC2616]), which in turn directs the
9
    resource owner back to the client with the authorization code.
10
11
    Before directing the resource owner back to the client with the
12
    authorization code, the authorization server authenticates the
13
    resource owner and obtains authorization.  Because the resource owner
14
    only authenticates with the authorization server, the resource
15
    owner's credentials are never shared with the client.
16
17
    The authorization code provides a few important security benefits,
18
    such as the ability to authenticate the client, as well as the
19
    transmission of the access token directly to the client without
20
    passing it through the resource owner's user-agent and potentially
21
    exposing it to others, including the resource owner.
22
23
 * Flow:
24
 *
25
 * 1.) Make an Authorization request
26
 * 2.) Server replies with Authorization response
27
 * 3.) Make an Access Token request
28
 * 4.) Server replies with Access Token Response
29
 *
30
 */
31
32
namespace AuthStack\OAuth2\Model\Protocol\Grant;
33
34
use Illuminate\Http\Request;
35
use AuthStack\OAuth2\Model\Protocol\Request\AuthorizationCode\{AuthorizationRequest, TokenRequest};
36
use AuthStack\OAuth2\Model\Protocol\Response\AuthorizationCode\{AuthorizationResponse, TokenResponse};
37
38
class AuthorizationCode implements GrantInterface
39
{
40
    /**
41
     * @param array $model
42
     * @return AuthorizationRequest
43
     */
44
    public function authorizationRequest(array $model = []): AuthorizationRequest
45
    {
46
        $result = new AuthorizationRequest();
47
48
        return !empty($model) ? $result->setModel($model) : $result;
49
    }
50
51
    /**
52
     * @param Request|null $request
53
     * @return AuthorizationResponse
54
     */
55
    public function authorizationResponse(Request $request = null): AuthorizationResponse
56
    {
57
        $response = new AuthorizationResponse();
58
59
        $request = $request ?? Request::createFromGlobals();
60
61
        if($request->has('state')) $response->setState($request->input('state'));
62
63
        return $response;
64
    }
65
66
    /**
67
     * @return TokenRequest
68
     */
69
    public function tokenRequest(): TokenRequest
70
    {
71
        return new TokenRequest();
72
    }
73
74
    /**
75
     * @return TokenResponse
76
     */
77
    public function tokenResponse(): TokenResponse
78
    {
79
        return new TokenResponse();
80
    }
81
}