Passed
Pull Request — master (#1316)
by
unknown
32:07
created

IdTokenRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\OAuth2\Server\Repositories;
6
7
use DateTimeImmutable;
8
use Lcobucci\JWT\Encoding\ChainedFormatter;
9
use Lcobucci\JWT\Encoding\JoseEncoder;
10
use Lcobucci\JWT\Token\Builder;
11
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
12
13
/**
14
 * Exmaple implemnation of IdTokenRepositoryInterface
15
 *
16
 * @author Marc Riemer <[email protected]>
17
 * @license http://opensource.org/licenses/MIT MIT
18
 */
19
class IdTokenRepository implements IdTokenRepositoryInterface
20
{
21
    public function __construct(private string $issuedBy, private ?string $nonce = null)
22
    {
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getBuilder(AccessTokenEntityInterface $accessToken): Builder
29
    {
30
        $builder = (new Builder(new JoseEncoder(), ChainedFormatter::withUnixTimestampDates()))
31
            ->permittedFor($accessToken->getClient()->getIdentifier())
32
            ->issuedBy($this->issuedBy)
33
            ->issuedAt(new DateTimeImmutable())
34
            ->expiresAt($accessToken->getExpiryDateTime())
35
            ->relatedTo($accessToken->getUserIdentifier());
0 ignored issues
show
Bug introduced by
It seems like $accessToken->getUserIdentifier() can also be of type null; however, parameter $subject of Lcobucci\JWT\Token\Builder::relatedTo() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            ->relatedTo(/** @scrutinizer ignore-type */ $accessToken->getUserIdentifier());
Loading history...
36
37
        if ($this->nonce) {
38
            $builder->withClaim('nonce', $this->nonce);
39
        }
40
41
        return $builder;
42
    }
43
}
44