Completed
Pull Request — master (#823)
by Martin
32:46
created

AbstractJwtAwareAccessToken::setPrivateKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * @author      Alex Bilbie <[email protected]>
4
 * @copyright   Copyright (c) Alex Bilbie
5
 * @license     http://mit-license.org/
6
 *
7
 * @link        https://github.com/thephpleague/oauth2-server
8
 */
9
10
namespace League\OAuth2\Server\Entities;
11
12
use Lcobucci\JWT\Builder;
13
use Lcobucci\JWT\Signer\Key;
14
use Lcobucci\JWT\Signer\Rsa\Sha256;
15
use League\OAuth2\Server\CryptKey;
16
17
abstract class AbstractJwtAwareAccessToken implements AccessTokenEntityInterface {
18
19
    /**
20
     * @var CryptKey
21
     */
22
    private $privateKey;
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function convertToEncryptedAccessToken()
28
    {
29
        return (new Builder())
30
            ->setAudience($this->getClient()->getIdentifier())
31
            ->setId($this->getIdentifier(), true)
32
            ->setIssuedAt(time())
33
            ->setNotBefore(time())
34
            ->setExpiration($this->getExpiryDateTime()->getTimestamp())
35
            ->setSubject($this->getUserIdentifier())
36
            ->set('scopes', $this->getScopes())
37
            ->sign(new Sha256(), new Key($this->privateKey->getKeyPath(), $this->privateKey->getPassPhrase()))
38
            ->getToken();
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function setPrivateKey(CryptKey $privateKey)
45
    {
46
        $this->privateKey = $privateKey;
47
    }
48
}
49