Passed
Push — master ( 904589...078d26 )
by Thomas Mauro
02:52
created

ClientSecretBasic   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedMethod() 0 3 1
A createRequest() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient\AuthMethod;
6
7
use Psr\Http\Message\RequestInterface;
8
use TMV\OpenIdClient\ClientInterface as OpenIDClient;
9
use TMV\OpenIdClient\Exception\InvalidArgumentException;
10
11
final class ClientSecretBasic implements AuthMethodInterface
12
{
13 1
    public function getSupportedMethod(): string
14
    {
15 1
        return 'client_secret_basic';
16
    }
17
18 1
    public function createRequest(
19
        RequestInterface $request,
20
        OpenIDClient $client,
21
        array $claims
22
    ): RequestInterface {
23 1
        $clientId = $client->getMetadata()->getClientId();
24 1
        $clientSecret = $client->getMetadata()->getClientSecret();
25
26 1
        if (! $clientSecret) {
27
            throw new InvalidArgumentException($this->getSupportedMethod() . ' cannot be used without client_secret metadata');
28
        }
29
30 1
        $request = $request->withHeader(
31 1
            'Authentication',
32 1
            'Basic ' . \base64_encode($clientId . ':' . $clientSecret)
33
        );
34
35 1
        $request->getBody()->write(\http_build_query($claims));
36
37 1
        return $request;
38
    }
39
}
40