Passed
Push — master ( c97e91...9a636e )
by Alexandre
01:52
created

AbstractGrantType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A issueAccessToken() 0 8 1
A __construct() 0 5 1
A issueRefreshToken() 0 5 1
A issueTokens() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 11/03/2018
6
 * Time: 17:56
7
 */
8
9
namespace OAuth2\GrantTypes;
10
11
12
use OAuth2\Storages\AccessTokenStorageInterface;
13
use OAuth2\Storages\RefreshTokenStorageInterface;
14
15
abstract class AbstractGrantType implements GrantTypeInterface
16
{
17
    /**
18
     * @var AccessTokenStorageInterface
19
     */
20
    private $accessTokenStorage;
21
    /**
22
     * @var RefreshTokenStorageInterface
23
     */
24
    private $refreshTokenStorage;
25
26
    public function __construct(AccessTokenStorageInterface $accessTokenStorage,
27
                                RefreshTokenStorageInterface $refreshTokenStorage)
28
    {
29
        $this->accessTokenStorage = $accessTokenStorage;
30
        $this->refreshTokenStorage = $refreshTokenStorage;
31
    }
32
33
    protected function issueTokens(string $scope, string $clientIdentifier, string $resourceOwnerIdentifier,
34
                                ?string $authorizationCode = null)
35
    {
36
        return array_merge(
37
            $this->issueAccessToken($scope, $clientIdentifier, $resourceOwnerIdentifier, $authorizationCode),
38
            $this->issueRefreshToken($scope, $clientIdentifier, $resourceOwnerIdentifier)
39
        );
40
    }
41
42
    protected function issueAccessToken(string $scope, string $clientIdentifier, string $resourceOwnerIdentifier, ?string $authorizationCode = null): array
43
    {
44
        $accessToken = $this->accessTokenStorage->generate($scope, $clientIdentifier,
45
            $resourceOwnerIdentifier, $authorizationCode);
46
        return [
47
            'access_token' => $accessToken->getToken(),
48
            'token_type' => $accessToken->getType(),
49
            'expires_in' => $this->accessTokenStorage->getLifetime()
50
        ];
51
    }
52
53
    protected function issueRefreshToken(string $scope, string $clientIdentifier, string $resourceOwnerIdentifier)
54
    {
55
        $accessToken = $this->refreshTokenStorage->generate($scope, $clientIdentifier, $resourceOwnerIdentifier);
56
        return [
57
            'refresh_token' => $accessToken->getToken()
58
        ];
59
    }
60
}