Passed
Pull Request — master (#1316)
by
unknown
34:21
created

IdTokenRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getBuilder() 0 14 2
1
<?php
2
3
namespace League\OAuth2\Server\Repositories;
4
5
use Lcobucci\JWT\Encoding\ChainedFormatter;
6
use Lcobucci\JWT\Encoding\JoseEncoder;
7
use Lcobucci\JWT\Token\Builder;
8
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
9
10
/**
11
 * Exmaple implemnation of IdTokenRepositoryInterface
12
 *
13
 * @author Marc Riemer <[email protected]>
14
 * @license http://opensource.org/licenses/MIT MIT
15
 */
16
class IdTokenRepository implements IdTokenRepositoryInterface
17
{
18
    public function __construct(private string $issuedBy, private ?string $nonce = null)
19
    {
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getBuilder(AccessTokenEntityInterface $accessToken): Builder
26
    {
27
        $builder = (new Builder(new JoseEncoder(), ChainedFormatter::withUnixTimestampDates()))
28
            ->permittedFor($accessToken->getClient()->getIdentifier())
29
            ->issuedBy($this->issuedBy)
30
            ->issuedAt(new \DateTimeImmutable())
31
            ->expiresAt($accessToken->getExpiryDateTime())
32
            ->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

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