Passed
Push — master ( 9a636e...af59f2 )
by Alexandre
03:34
created

ClientCredentialsFlow::handleAccessTokenRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: GCC-MED
5
 * Date: 12/03/2018
6
 * Time: 15:41
7
 */
8
9
namespace OAuth2\Flows;
10
11
12
use OAuth2\Endpoints\AuthorizationEndpoint;
13
use OAuth2\Endpoints\TokenEndpoint;
14
use OAuth2\Exceptions\OAuthException;
15
use OAuth2\GrantTypes\AbstractGrantType;
16
use OAuth2\GrantTypes\GrantTypeInterface;
17
use OAuth2\ResponseTypes\ResponseTypeInterface;
18
use OAuth2\Roles\Clients\ConfidentialClientInterface;
19
use OAuth2\ScopePolicy\ScopePolicyManager;
20
use OAuth2\Storages\AccessTokenStorageInterface;
21
use OAuth2\Storages\RefreshTokenStorageInterface;
22
23
class ClientCredentialsFlow extends AbstractGrantType implements FlowInterface
24
{
25
    /**
26
     * @var ScopePolicyManager
27
     */
28
    private $scopePolicyManager;
29
30
    public function __construct(ScopePolicyManager $scopePolicyManager,
31
                                AccessTokenStorageInterface $accessTokenStorage,
32
                                RefreshTokenStorageInterface $refreshTokenStorage)
33
    {
34
        parent::__construct($accessTokenStorage, $refreshTokenStorage);
35
        $this->scopePolicyManager = $scopePolicyManager;
36
    }
37
38
    /**
39
     * @return ResponseTypeInterface[]
40
     */
41
    function getResponseTypes(): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
42
    {
43
        return [];
44
    }
45
46
    /**
47
     * @return GrantTypeInterface[]
48
     */
49
    function getGrantTypes(): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
    {
51
        return ['client_credentials'];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('client_credentials') returns the type array<integer,string> which is incompatible with the documented return type OAuth2\GrantTypes\GrantTypeInterface[].
Loading history...
52
    }
53
54
    function handleAccessTokenRequest(TokenEndpoint $tokenEndpoint, array $requestData): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
    {
56
        if (!$tokenEndpoint->getClient() instanceof ConfidentialClientInterface) {
57
            throw new OAuthException('unauthorized_client',
58
                'The authenticated client is not authorized to use this authorization grant type. 
59
                The client credentials grant type MUST only be used by confidential clients.',
60
                'https://tools.ietf.org/html/rfc6749#section-4.4');
61
        }
62
63
        $scopes = $this->scopePolicyManager->getScopes($tokenEndpoint->getClient(), $requestData['scope'] ?? null);
64
        $this->scopePolicyManager->verifyScopes($tokenEndpoint->getClient(), $scopes);
65
66
        return $this->issueAccessToken(implode(' ', $scopes), $tokenEndpoint->getClient()->getIdentifier(), null);
67
    }
68
69
    function handleAuthorizationRequest(AuthorizationEndpoint $authorizationEndpoint, array $requestData): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
70
    {
71
        throw new \BadMethodCallException();
72
    }
73
74
    function getDefaultResponseMode(): string
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
75
    {
76
        throw new \BadMethodCallException();
77
    }
78
79
    function getUnsupportedResponseModes(): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
80
    {
81
        throw new \BadMethodCallException();
82
    }
83
}