EpicGames   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 5
dl 0
loc 70
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseAuthorizationUrl() 0 4 1
A getBaseAccessTokenUrl() 0 4 1
A getResourceOwnerDetailsUrl() 0 4 1
A getDefaultScopes() 0 6 1
A getScopeSeparator() 0 4 1
A checkResponse() 0 10 2
A createResourceOwner() 0 4 1
1
<?php
2
3
namespace MrPropre\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
7
use League\OAuth2\Client\Token\AccessToken;
8
use Psr\Http\Message\ResponseInterface;
9
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
10
11
class EpicGames extends AbstractProvider
12
{
13
    use BearerAuthorizationTrait;
14
15
    /**
16
     * Domain
17
     *
18
     * @var string
19
     */
20
    public $domain = 'https://www.epicgames.com';
21
22
    /**
23
     * API domain
24
     *
25
     * @var string
26
     */
27
    public $apiDomain = 'https://api.epicgames.dev';
28
29
    /**
30
     * Get authorization URL to begin OAuth flow
31
     */
32 3
    public function getBaseAuthorizationUrl(): string
33
    {
34 3
        return $this->domain . '/id/authorize';
35
    }
36
37
    /**
38
     * Get access token URL to retrieve token
39
     */
40 4
    public function getBaseAccessTokenUrl(array $params): string
41
    {
42 4
        return $this->apiDomain . '/epic/oauth/v1/token';
43
    }
44
45
    /**
46
     * Get provider URL to request user details
47
     */
48 1
    public function getResourceOwnerDetailsUrl(AccessToken $token): string
49
    {
50 1
        return $this->apiDomain . '/epic/oauth/v1/userInfo';
51
    }
52
53 2
    protected function getDefaultScopes(): array
54
    {
55
        return [
56 2
            'basic_profile'
57
        ];
58
    }
59
60 3
    protected function getScopeSeparator(): string
61
    {
62 3
        return ' ';
63
    }
64
65 3
    protected function checkResponse(ResponseInterface $response, $data): void
66
    {
67 3
        if ($response->getStatusCode() >= 400) {
68 1
            throw new IdentityProviderException(
69 1
                $data['errorMessage'] ?? $response->getReasonPhrase(),
70 1
                $response->getStatusCode(),
71 1
                (string) $response->getBody()
72
            );
73
        }
74 2
    }
75
76 1
    protected function createResourceOwner(array $response, AccessToken $token): EpicGamesResourceOwner
77
    {
78 1
        return new EpicGamesResourceOwner($response);
79
    }
80
}
81