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

getTokenFromRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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