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
nc 1
nop 3
dl 0
loc 16
ccs 9
cts 9
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 array_merge;
8
use Facile\OpenIDClient\Client\ClientInterface as OpenIDClient;
9
use function http_build_query;
10
use Psr\Http\Message\RequestInterface;
11
12
abstract class AbstractJwtAuth implements AuthMethodInterface
13
{
14
    /**
15
     * @param OpenIDClient $client
16
     * @param array<string, mixed> $claims
17
     *
18
     * @return string
19
     */
20
    abstract protected function createAuthJwt(OpenIDClient $client, array $claims = []): string;
21
22 4
    public function createRequest(
23
        RequestInterface $request,
24
        OpenIDClient $client,
25
        array $claims
26
    ): RequestInterface {
27 4
        $clientId = $client->getMetadata()->getClientId();
28
29 4
        $claims = array_merge([
30 4
            'client_id' => $clientId,
31 4
            'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
32 4
            'client_assertion' => $this->createAuthJwt($client, $claims),
33 3
        ], $claims);
34
35 3
        $request->getBody()->write(http_build_query($claims));
36
37 3
        return $request;
38
    }
39
}
40