AbstractJwtAuth::createRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient\AuthMethod;
6
7
use function array_merge;
8
use function http_build_query;
9
use Psr\Http\Message\RequestInterface;
10
use TMV\OpenIdClient\Client\ClientInterface as OpenIDClient;
11
12
abstract class AbstractJwtAuth implements AuthMethodInterface
13
{
14
    abstract protected function createAuthJwt(OpenIDClient $client, array $claims = []): string;
15
16 4
    public function createRequest(
17
        RequestInterface $request,
18
        OpenIDClient $client,
19
        array $claims
20
    ): RequestInterface {
21 4
        $clientId = $client->getMetadata()->getClientId();
22
23 4
        $claims = array_merge([
24 4
            'client_id' => $clientId,
25 4
            'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
26 4
            'client_assertion' => $this->createAuthJwt($client, $claims),
27 3
        ], $claims);
28
29 3
        $request->getBody()->write(http_build_query($claims));
30
31 3
        return $request;
32
    }
33
}
34