Passed
Push — master ( c97e91...9a636e )
by Alexandre
01:52
created

ClientSecretPostAuthenticationMethod   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A authenticate() 0 7 3
A support() 0 3 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: GCC-MED
5
 * Date: 09/03/2018
6
 * Time: 16:59
7
 */
8
9
namespace OAuth2\ClientAuthentication;
10
11
12
use OAuth2\Roles\ClientInterface;
13
use OAuth2\Roles\Clients\ConfidentialClient;
14
use OAuth2\Storages\ClientStorageInterface;
15
use Psr\Http\Message\ServerRequestInterface;
16
17
class ClientSecretPostAuthenticationMethod implements ClientAuthenticationMethodInterface
18
{
19
    /**
20
     * @var ClientStorageInterface
21
     */
22
    private $clientStorage;
23
24
    public function __construct(ClientStorageInterface $clientStorage)
25
{
26
    $this->clientStorage = $clientStorage;
27
}
28
29
    function support(ServerRequestInterface $request, array $requestData): bool
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...
30
    {
31
        return !empty($requestData['client_id']) && !empty($requestData['client_secret']);
32
    }
33
34
    function authenticate(ServerRequestInterface $request, array $requestData): ?ClientInterface
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...
35
    {
36
        $client = $this->clientStorage->get($requestData['client_id']);
37
        if($client instanceof ConfidentialClient && $client->getPassword() == $requestData['client_secret']) {
38
            return $client;
39
        }
40
        return null;
41
    }
42
}