Passed
Push — master ( 17dcf4...4f23c3 )
by Max van der
05:40
created

OAuth2Controller   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 5
dl 0
loc 71
ccs 13
cts 17
cp 0.7647
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A accessToken() 0 11 2
A revokeAccessToken() 0 8 2
A authorize() 0 4 1
A completeAuthorization() 0 4 1
1
<?php
2
3
4
namespace Mvdstam\Oauth2ServerLaravel\Http\Controllers;
5
6
7
use Illuminate\Http\Request;
8
use Illuminate\Routing\Controller;
9
use League\OAuth2\Server\AuthorizationServer;
10
use League\OAuth2\Server\Exception\OAuthServerException;
11
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
12
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
13
use Psr\Http\Message\ResponseInterface;
14
use Psr\Http\Message\ServerRequestInterface;
15
use RuntimeException;
16
17
class OAuth2Controller extends Controller
18
{
19
20
    /**
21
     * @var AuthorizationServer
22
     */
23
    protected $authorizationServer;
24
25
    /**
26
     * @var AccessTokenRepositoryInterface
27
     */
28
    protected $accessTokens;
29
30
    /**
31
     * OAuth2Controller constructor.
32
     * @param AuthorizationServer $authorizationServer
33
     * @param AccessTokenRepositoryInterface $accessTokens
34
     */
35 16
    public function __construct(AuthorizationServer $authorizationServer, AccessTokenRepositoryInterface $accessTokens)
36
    {
37 16
        $this->authorizationServer = $authorizationServer;
38 16
        $this->accessTokens = $accessTokens;
39 16
    }
40
41 13
    public function accessToken(ServerRequestInterface $request, ResponseInterface $response)
42
    {
43
        try {
44 13
            return $this->authorizationServer->respondToAccessTokenRequest(
45
                $request,
46
                $response
47
            );
48 3
        } catch (OAuthServerException $e) {
49 3
            return $e->generateHttpResponse($response);
50
        }
51
    }
52
53 3
    public function revokeAccessToken(ServerRequestInterface $request, ResponseInterface $response)
54
    {
55
        try {
56 3
            $this->accessTokens->revokeAccessToken($request->getAttribute('oauth_access_token_id'));
57 1
        } catch (OAuthServerException $e) {
58 1
            return $e->generateHttpResponse($response);
59
        }
60 2
    }
61
62
    /**
63
     * Validates the authorization request and stores it in the session during authentication
64
     * of the user.
65
     *
66
     * @param ServerRequestInterface $request
67
     * @param ResponseInterface $response
68
     * @return ResponseInterface
69
     */
70
    public function authorize(ServerRequestInterface $request, ResponseInterface $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        throw new RuntimeException('Not implemented');
73
    }
74
75
    /**
76
     * Finalizes the authorization process and returns an access code.
77
     *
78
     * @param UserRepositoryInterface $users
79
     * @param Request $request
80
     * @param ResponseInterface $response
81
     * @return ResponseInterface
82
     */
83
    public function completeAuthorization(UserRepositoryInterface $users, Request $request, ResponseInterface $response)
0 ignored issues
show
Unused Code introduced by
The parameter $users is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
    {
85
        throw new RuntimeException('Not implemented');
86
    }
87
}
88