Code Duplication    Length = 61-61 lines in 2 locations

src/Http/Controllers/AccessTokenController.php 1 location

@@ 9-69 (lines=61) @@
6
use CodexShaper\OAuth2\Server\Http\Responses\ServerResponse;
7
use CodexShaper\OAuth2\Server\Manager;
8
9
class AccessTokenController
10
{
11
    /**
12
     * The server manager.
13
     *
14
     * @var \CodexShaper\OAuth2\Server\Manager
15
     */
16
    protected $manager;
17
18
    /**
19
     * The authorization server.
20
     *
21
     * @var \League\OAuth2\Server\AuthorizationServer
22
     */
23
    protected $server;
24
25
    /**
26
     * The psr7 server request.
27
     *
28
     * @var \CodexShaper\OAuth2\Server\Http\Requests\ServerRequest
29
     */
30
    protected $request;
31
32
    /**
33
     * The psr7 server response.
34
     *
35
     * @var \CodexShaper\OAuth2\Server\Http\Responses\ServerResponse
36
     */
37
    protected $response;
38
39
    /**
40
     * Create a new access token controller instance.
41
     *
42
     * @return void
43
     */
44
    public function __construct()
45
    {
46
        $this->manager = new Manager();
47
        $this->server = $this->manager->makeAuthorizationServer();
48
        $this->request = ServerRequest::getPsrServerRequest();
49
        $this->response = ServerResponse::getPsrServerResponse();
50
    }
51
52
    /**
53
     * Make access token.
54
     *
55
     * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
56
     */
57
    public function issueAccessToken()
58
    {
59
        try {
60
61
            // Try to respond to the request
62
            return $this->server->respondToAccessTokenRequest($this->request, $this->response)->getBody();
63
        } catch (OAuthServerException $exception) {
64
65
            // All instances of OAuthServerException can be formatted into a HTTP response
66
            return $exception->generateHttpResponse($this->response);
67
        }
68
    }
69
}
70

src/Http/Controllers/RefreshTokenController.php 1 location

@@ 9-69 (lines=61) @@
6
use CodexShaper\OAuth2\Server\Http\Responses\ServerResponse;
7
use CodexShaper\OAuth2\Server\Manager;
8
9
class RefreshTokenController
10
{
11
    /**
12
     * The server manager.
13
     *
14
     * @var \CodexShaper\OAuth2\Server\Manager
15
     */
16
    protected $manager;
17
18
    /**
19
     * The authorization server.
20
     *
21
     * @var \League\OAuth2\Server\AuthorizationServer
22
     */
23
    protected $server;
24
25
    /**
26
     * The psr7 server request.
27
     *
28
     * @var \CodexShaper\OAuth2\Server\Http\Requests\ServerRequest
29
     */
30
    protected $request;
31
32
    /**
33
     * The psr7 server response.
34
     *
35
     * @var \CodexShaper\OAuth2\Server\Http\Responses\ServerResponse
36
     */
37
    protected $response;
38
39
    /**
40
     * Create a new refresh token controller instance.
41
     *
42
     * @return void
43
     */
44
    public function __construct()
45
    {
46
        $this->manager = new Manager();
47
        $this->server = $this->manager->makeAuthorizationServer();
48
        $this->request = ServerRequest::getPsrServerRequest();
49
        $this->response = ServerResponse::getPsrServerResponse();
50
    }
51
52
    /**
53
     * Make access token.
54
     *
55
     * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
56
     */
57
    public function issueAccessToken()
58
    {
59
        try {
60
61
            // Try to respond to the request
62
            return $this->server->respondToAccessTokenRequest($this->request, $this->response)->getBody();
63
        } catch (OAuthServerException $exception) {
64
65
            // All instances of OAuthServerException can be formatted into a HTTP response
66
            return $exception->generateHttpResponse($this->response);
67
        }
68
    }
69
}
70