ClientSecretBasic::getSupportedMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\AuthMethod;
6
7
use function base64_encode;
8
use Facile\OpenIDClient\Client\ClientInterface as OpenIDClient;
9
use Facile\OpenIDClient\Exception\InvalidArgumentException;
10
use function http_build_query;
11
use Psr\Http\Message\RequestInterface;
12
13
final class ClientSecretBasic implements AuthMethodInterface
14
{
15 3
    public function getSupportedMethod(): string
16
    {
17 3
        return 'client_secret_basic';
18
    }
19
20 2
    public function createRequest(
21
        RequestInterface $request,
22
        OpenIDClient $client,
23
        array $claims
24
    ): RequestInterface {
25 2
        $clientId = $client->getMetadata()->getClientId();
26 2
        $clientSecret = $client->getMetadata()->getClientSecret();
27
28 2
        if (null === $clientSecret) {
29 1
            throw new InvalidArgumentException($this->getSupportedMethod() . ' cannot be used without client_secret metadata');
30
        }
31
32 1
        $request = $request->withHeader(
33 1
            'Authorization',
34 1
            'Basic ' . base64_encode(urlencode($clientId) . ':' . urlencode($clientSecret))
35
        );
36
37 1
        $request->getBody()->write(http_build_query($claims));
38
39 1
        return $request;
40
    }
41
}
42