Passed
Push — master ( 84f396...090b6c )
by Max van der
12:39
created

OAuth2Controller::revokeAccessToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
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 13
                $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