Completed
Pull Request — master (#925)
by Steve
01:48
created

BearerTokenIntrospectionResponse   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 38
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validIntrospectionResponse() 0 17 1
A getTokenFromRequest() 0 7 1
1
<?php
2
3
namespace League\OAuth2\Server\ResponseTypes;
4
5
use Lcobucci\JWT\Parser;
6
use Lcobucci\JWT\Token;
7
8
class BearerTokenIntrospectionResponse extends IntrospectionResponse
9
{
10
    /**
11
     * Add the token data to the response.
12
     *
13
     * @return array
14
     */
15 2
    protected function validIntrospectionResponse()
16
    {
17 2
        $token = $this->getTokenFromRequest();
18
19
        $responseParams = [
20 2
            'active' => true,
21 2
            'token_type' => 'access_token',
22 2
            'scope' => $token->getClaim('scopes', ''),
23 2
            'client_id' => $token->getClaim('aud'),
24 2
            'exp' => $token->getClaim('exp'),
25 2
            'iat' => $token->getClaim('iat'),
26 2
            'sub' => $token->getClaim('sub'),
27 2
            'jti' => $token->getClaim('jti'),
28
        ];
29
30 2
        return array_merge($this->getExtraParams(), $responseParams);
31
    }
32
33
    /**
34
     * Gets the token from the request body.
35
     *
36
     * @return Token
37
     */
38
    protected function getTokenFromRequest()
39
    {
40
        $jwt = $this->request->getParsedBody()['token'] ?? null;
41
42
        return (new Parser())
43
            ->parse($jwt);
44
    }
45
}
46