PersonalAccessGrant   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 12
c 1
b 0
f 1
dl 0
loc 35
rs 10
ccs 0
cts 11
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A respondToAccessTokenRequest() 0 22 1
A getIdentifier() 0 3 1
1
<?php
2
3
namespace ByTIC\Hello\Oauth\Grants;
4
5
use DateInterval;
6
use Psr\Http\Message\ServerRequestInterface;
7
use League\OAuth2\Server\Grant\AbstractGrant;
8
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
9
10
/**
11
 * Class PersonalAccessGrant
12
 * @package ByTIC\Hello\Oauth\Grants
13
 */
14
class PersonalAccessGrant extends AbstractGrant
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function respondToAccessTokenRequest(
20
        ServerRequestInterface $request,
21
        ResponseTypeInterface $responseType,
22
        DateInterval $accessTokenTTL
23
    ) {
24
        // Validate request
25
        $client = $this->validateClient($request);
26
        $scopes = $this->validateScopes($this->getRequestParameter('scope', $request));
27
28
        // Finalize the requested scopes
29
        $scopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client);
30
31
        // Issue and persist access token
32
        $accessToken = $this->issueAccessToken(
33
            $accessTokenTTL,
34
            $client,
35
            $this->getRequestParameter('user_id', $request),
36
            $scopes
37
        );
38
        // Inject access token into response type
39
        $responseType->setAccessToken($accessToken);
40
        return $responseType;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getIdentifier()
47
    {
48
        return 'personal_access';
49
    }
50
}
51