Passed
Pull Request — master (#1473)
by
unknown
35:05
created

TokenRevocationHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A respondToRequest() 0 19 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\OAuth2\Server\Handlers;
6
7
use League\OAuth2\Server\Exception\OAuthServerException;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
class TokenRevocationHandler extends AbstractTokenHandler
12
{
13
    public function respondToRequest(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
14
    {
15
        $client = $this->validateClient($request);
16
        $token = $this->validateToken($request, $client);
17
18
        if ($token !== null) {
19
            if ($token['type'] === 'refresh_token') {
20
                $this->refreshTokenRepository->revokeRefreshToken($token['data']['refresh_token_id']);
21
                $this->accessTokenRepository->revokeAccessToken($token['data']['access_token_id']);
22
            } elseif ($token['type'] === 'access_token') {
23
                $this->accessTokenRepository->revokeAccessToken($token['data']['jti']);
24
            } else {
25
                throw OAuthServerException::unsupportedTokenType();
26
            }
27
        }
28
29
        return $response
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->withSt...e-control', 'no-store') returns the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\ResponseInterface.
Loading history...
30
            ->withStatus(200)
31
            ->withHeader('cache-control', 'no-store');
32
    }
33
}
34