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

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
}