Completed
Push — master ( 704578...e88511 )
by Alex
32:19
created

AccessTokenRepository::getNewToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 3
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 OAuth2ServerExamples\Repositories;
11
12
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
13
use League\OAuth2\Server\Entities\ClientEntityInterface;
14
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
15
use OAuth2ServerExamples\Entities\AccessTokenEntity;
16
17
class AccessTokenRepository implements AccessTokenRepositoryInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity)
23
    {
24
        // Some logic here to save the access token to a database
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function revokeAccessToken($tokenId)
31
    {
32
        // Some logic here to revoke the access token
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function isAccessTokenRevoked($tokenId)
39
    {
40
        return false; // Access token hasn't been revoked
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
47
    {
48
        $accessToken = new AccessTokenEntity();
49
        $accessToken->setClient($clientEntity);
50
        foreach ($scopes as $scope) {
51
            $accessToken->addScope($scope);
52
        }
53
        $accessToken->setUserIdentifier($userIdentifier);
54
55
        return $accessToken;
56
    }
57
}
58