OAuth2Controller   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 78.95%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 5
dl 0
loc 70
ccs 15
cts 19
cp 0.7895
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A revokeAccessToken() 0 8 2
A authorize() 0 4 1
A completeAuthorization() 0 4 1
A accessToken() 0 11 2
1
<?php
2
3
4
namespace Mvdstam\Oauth2ServerLaravel\Http\Controllers;
5
6
7
use Illuminate\Routing\Controller;
8
use League\OAuth2\Server\AuthorizationServer;
9
use League\OAuth2\Server\Exception\OAuthServerException;
10
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
11
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
12
use Psr\Http\Message\ResponseInterface;
13
use Psr\Http\Message\ServerRequestInterface;
14
use RuntimeException;
15
16
class OAuth2Controller extends Controller
17
{
18
19
    /**
20
     * @var AuthorizationServer
21
     */
22
    protected $authorizationServer;
23
24
    /**
25
     * @var AccessTokenRepositoryInterface
26
     */
27
    protected $accessTokens;
28
29
    /**
30
     * OAuth2Controller constructor.
31
     * @param AuthorizationServer $authorizationServer
32
     * @param AccessTokenRepositoryInterface $accessTokens
33
     */
34 16
    public function __construct(AuthorizationServer $authorizationServer, AccessTokenRepositoryInterface $accessTokens)
35
    {
36 16
        $this->authorizationServer = $authorizationServer;
37 16
        $this->accessTokens = $accessTokens;
38 16
    }
39
40 13
    public function accessToken(ServerRequestInterface $request, ResponseInterface $response)
41
    {
42
        try {
43 13
            return $this->authorizationServer->respondToAccessTokenRequest(
44 13
                $request,
45 13
                $response
46
            );
47 3
        } catch (OAuthServerException $e) {
48 3
            return $e->generateHttpResponse($response);
49
        }
50
    }
51
52 3
    public function revokeAccessToken(ServerRequestInterface $request, ResponseInterface $response)
53
    {
54
        try {
55 3
            $this->accessTokens->revokeAccessToken($request->getAttribute('oauth_access_token_id'));
56 1
        } catch (OAuthServerException $e) {
57 1
            return $e->generateHttpResponse($response);
58
        }
59 2
    }
60
61
    /**
62
     * Validates the authorization request and stores it in the session during authentication
63
     * of the user.
64
     *
65
     * @param ServerRequestInterface $request
66
     * @param ResponseInterface $response
67
     * @return ResponseInterface
68
     */
69
    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...
70
    {
71
        throw new RuntimeException('Not implemented');
72
    }
73
74
    /**
75
     * Finalizes the authorization process and returns an access code.
76
     *
77
     * @param UserRepositoryInterface $users
78
     * @param ServerRequestInterface $response
79
     * @return ResponseInterface
80
     */
81
    public function completeAuthorization(UserRepositoryInterface $users, ServerRequestInterface $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...
82
    {
83
        throw new RuntimeException('Not implemented');
84
    }
85
}
86