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
|
|
|
|