1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Evelabs\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
6
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
7
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
8
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
9
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
|
12
|
|
|
class EveOnline extends AbstractProvider |
13
|
|
|
{ |
14
|
|
|
use BearerAuthorizationTrait; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Default scopes |
19
|
|
|
* |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
public $defaultScopes = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get the string used to separate scopes. |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
9 |
|
protected function getScopeSeparator() |
30
|
|
|
{ |
31
|
9 |
|
return ' '; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the base URL for authorizing a client. |
36
|
|
|
* |
37
|
|
|
* Eg. https://oauth.service.com/authorize |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
9 |
|
public function getBaseAuthorizationUrl() |
42
|
|
|
{ |
43
|
9 |
|
return 'https://login.eveonline.com/oauth/authorize'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns the base URL for requesting an access token. |
48
|
|
|
* |
49
|
|
|
* Eg. https://oauth.service.com/token |
50
|
|
|
* |
51
|
|
|
* @param array $params |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
21 |
|
public function getBaseAccessTokenUrl(array $params) |
55
|
|
|
{ |
56
|
21 |
|
return 'https://login.eveonline.com/oauth/token'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the URL for requesting the resource owner's details. |
61
|
|
|
* |
62
|
|
|
* @param AccessToken $token |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
3 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
66
|
|
|
{ |
67
|
3 |
|
return 'https://login.eveonline.com/oauth/verify'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the default scopes used by this provider. |
72
|
|
|
* |
73
|
|
|
* This should only be the scopes that are required to request the details |
74
|
|
|
* of the resource owner, rather than all the available scopes. |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
6 |
|
protected function getDefaultScopes() |
79
|
|
|
{ |
80
|
6 |
|
return $this->defaultScopes; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Checks a provider response for errors. |
85
|
|
|
* |
86
|
|
|
* @throws IdentityProviderException |
87
|
|
|
* @param ResponseInterface $response |
88
|
|
|
* @param array|string $data Parsed response data |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
21 |
|
protected function checkResponse(ResponseInterface $response, $data) |
92
|
|
|
{ |
93
|
|
|
//not throwing anything for 2xx responses |
94
|
21 |
|
if (intval(substr($response->getStatusCode(), 0, 1)) === 2) { |
95
|
12 |
|
return; |
96
|
|
|
} |
97
|
|
|
|
98
|
9 |
|
$message = $this->safeRead($data, 'error_description') || $this->safeRead($data, 'message'); |
99
|
9 |
|
throw new IdentityProviderException( |
100
|
9 |
|
$message ?: $response->getReasonPhrase(), |
|
|
|
|
101
|
9 |
|
$response->getStatusCode(), |
102
|
|
|
$response |
|
|
|
|
103
|
6 |
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Generates a resource owner object from a successful resource owner |
108
|
|
|
* details request. |
109
|
|
|
* |
110
|
|
|
* @param array $response |
111
|
|
|
* @param AccessToken $token |
112
|
|
|
* @return ResourceOwnerInterface |
113
|
|
|
*/ |
114
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
115
|
|
|
{ |
116
|
3 |
|
return new EveOnlineResourceOwner($response); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Internal helper function to safe read from an array |
121
|
|
|
* @param mixed $array |
122
|
|
|
* @param string|int $key |
123
|
|
|
* @return null |
124
|
|
|
*/ |
125
|
9 |
|
private function safeRead($array, $key) |
126
|
|
|
{ |
127
|
9 |
|
return !empty($array[$key]) ? $array[$key] : null; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.