@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | interface ExceptionInterface |
14 | 14 | { |
15 | - /* |
|
15 | + /* |
|
16 | 16 | ExceptionInterface |
17 | 17 | Exception extends \Exception implements ExceptionInterface |
18 | 18 | | RuntimeException extends Exception |
@@ -14,37 +14,37 @@ |
||
14 | 14 | */ |
15 | 15 | class Psr3LoggerWrapper implements LoggerInterface |
16 | 16 | { |
17 | - use LoggerAwareTrait; |
|
17 | + use LoggerAwareTrait; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @inheritdoc |
|
21 | - */ |
|
22 | - public function info($message, array $context = []) |
|
23 | - { |
|
24 | - $this->logger->info($message, $context); |
|
25 | - } |
|
19 | + /** |
|
20 | + * @inheritdoc |
|
21 | + */ |
|
22 | + public function info($message, array $context = []) |
|
23 | + { |
|
24 | + $this->logger->info($message, $context); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @inheritdoc |
|
29 | - */ |
|
30 | - public function debug($message, array $context = []) |
|
31 | - { |
|
32 | - $this->logger->debug($message, $context); |
|
33 | - } |
|
27 | + /** |
|
28 | + * @inheritdoc |
|
29 | + */ |
|
30 | + public function debug($message, array $context = []) |
|
31 | + { |
|
32 | + $this->logger->debug($message, $context); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - public function error($message, array $context = []) |
|
39 | - { |
|
40 | - $this->logger->error($message, $context); |
|
41 | - } |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + public function error($message, array $context = []) |
|
39 | + { |
|
40 | + $this->logger->error($message, $context); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @inheritdoc |
|
45 | - */ |
|
46 | - public function log($level, $message, array $context = []) |
|
47 | - { |
|
48 | - $this->logger->log($level, $message, $context); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @inheritdoc |
|
45 | + */ |
|
46 | + public function log($level, $message, array $context = []) |
|
47 | + { |
|
48 | + $this->logger->log($level, $message, $context); |
|
49 | + } |
|
50 | 50 | } |
@@ -10,7 +10,6 @@ |
||
10 | 10 | use Hybridauth\Adapter\OpenID; |
11 | 11 | use Hybridauth\Exception\UnexpectedApiResponseException; |
12 | 12 | use Hybridauth\Data; |
13 | -use Hybridauth\User; |
|
14 | 13 | |
15 | 14 | /** |
16 | 15 | * Steam OpenID provider adapter. |
@@ -35,116 +35,116 @@ |
||
35 | 35 | */ |
36 | 36 | class Steam extends OpenID |
37 | 37 | { |
38 | - /** |
|
39 | - * {@inheritdoc} |
|
40 | - */ |
|
41 | - protected $openidIdentifier = 'http://steamcommunity.com/openid'; |
|
42 | - |
|
43 | - /** |
|
44 | - * {@inheritdoc} |
|
45 | - */ |
|
46 | - protected $apiDocumentation = 'https://steamcommunity.com/dev'; |
|
47 | - |
|
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - public function authenticateFinish() |
|
52 | - { |
|
53 | - parent::authenticateFinish(); |
|
54 | - |
|
55 | - $userProfile = $this->storage->get($this->providerId . '.user'); |
|
56 | - |
|
57 | - $userProfile->identifier = str_ireplace([ |
|
58 | - 'http://steamcommunity.com/openid/id/', |
|
59 | - 'https://steamcommunity.com/openid/id/', |
|
60 | - ], '', $userProfile->identifier); |
|
61 | - |
|
62 | - if (!$userProfile->identifier) { |
|
63 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
64 | - } |
|
65 | - |
|
66 | - try { |
|
67 | - $apiKey = $this->config->filter('keys')->get('secret'); |
|
68 | - |
|
69 | - // if api key is provided, we attempt to use steam web api |
|
70 | - if ($apiKey) { |
|
71 | - $result = $this->getUserProfileWebAPI($apiKey, $userProfile->identifier); |
|
72 | - } else { |
|
73 | - // otherwise we fallback to community data |
|
74 | - $result = $this->getUserProfileLegacyAPI($userProfile->identifier); |
|
75 | - } |
|
76 | - |
|
77 | - // fetch user profile |
|
78 | - foreach ($result as $k => $v) { |
|
79 | - $userProfile->$k = $v ?: $userProfile->$k; |
|
80 | - } |
|
81 | - } catch (\Exception $e) { |
|
82 | - } |
|
83 | - |
|
84 | - // store user profile |
|
85 | - $this->storage->set($this->providerId . '.user', $userProfile); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Fetch user profile on Steam web API |
|
90 | - * |
|
91 | - * @param $apiKey |
|
92 | - * @param $steam64 |
|
93 | - * |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function getUserProfileWebAPI($apiKey, $steam64) |
|
97 | - { |
|
98 | - $q = http_build_query(['key' => $apiKey, 'steamids' => $steam64]); |
|
99 | - $apiUrl = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' . $q; |
|
100 | - |
|
101 | - $response = $this->httpClient->request($apiUrl); |
|
102 | - |
|
103 | - $data = json_decode($response); |
|
104 | - |
|
105 | - $data = isset($data->response->players[0]) ? $data->response->players[0] : null; |
|
106 | - |
|
107 | - $data = new Data\Collection($data); |
|
108 | - |
|
109 | - $userProfile = []; |
|
110 | - |
|
111 | - $userProfile['displayName'] = (string)$data->get('personaname'); |
|
112 | - $userProfile['firstName'] = (string)$data->get('realname'); |
|
113 | - $userProfile['photoURL'] = (string)$data->get('avatarfull'); |
|
114 | - $userProfile['profileURL'] = (string)$data->get('profileurl'); |
|
115 | - $userProfile['country'] = (string)$data->get('loccountrycode'); |
|
116 | - |
|
117 | - return $userProfile; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Fetch user profile on community API |
|
122 | - * @param $steam64 |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function getUserProfileLegacyAPI($steam64) |
|
126 | - { |
|
127 | - libxml_use_internal_errors(false); |
|
128 | - |
|
129 | - $apiUrl = 'http://steamcommunity.com/profiles/' . $steam64 . '/?xml=1'; |
|
130 | - |
|
131 | - $response = $this->httpClient->request($apiUrl); |
|
132 | - |
|
133 | - $data = new \SimpleXMLElement($response); |
|
134 | - |
|
135 | - $data = new Data\Collection($data); |
|
136 | - |
|
137 | - $userProfile = []; |
|
138 | - |
|
139 | - $userProfile['displayName'] = (string)$data->get('steamID'); |
|
140 | - $userProfile['firstName'] = (string)$data->get('realname'); |
|
141 | - $userProfile['photoURL'] = (string)$data->get('avatarFull'); |
|
142 | - $userProfile['description'] = (string)$data->get('summary'); |
|
143 | - $userProfile['region'] = (string)$data->get('location'); |
|
144 | - $userProfile['profileURL'] = (string)$data->get('customURL') |
|
145 | - ? 'http://steamcommunity.com/id/' . (string)$data->get('customURL') |
|
146 | - : 'http://steamcommunity.com/profiles/' . $steam64; |
|
147 | - |
|
148 | - return $userProfile; |
|
149 | - } |
|
38 | + /** |
|
39 | + * {@inheritdoc} |
|
40 | + */ |
|
41 | + protected $openidIdentifier = 'http://steamcommunity.com/openid'; |
|
42 | + |
|
43 | + /** |
|
44 | + * {@inheritdoc} |
|
45 | + */ |
|
46 | + protected $apiDocumentation = 'https://steamcommunity.com/dev'; |
|
47 | + |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + public function authenticateFinish() |
|
52 | + { |
|
53 | + parent::authenticateFinish(); |
|
54 | + |
|
55 | + $userProfile = $this->storage->get($this->providerId . '.user'); |
|
56 | + |
|
57 | + $userProfile->identifier = str_ireplace([ |
|
58 | + 'http://steamcommunity.com/openid/id/', |
|
59 | + 'https://steamcommunity.com/openid/id/', |
|
60 | + ], '', $userProfile->identifier); |
|
61 | + |
|
62 | + if (!$userProfile->identifier) { |
|
63 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
64 | + } |
|
65 | + |
|
66 | + try { |
|
67 | + $apiKey = $this->config->filter('keys')->get('secret'); |
|
68 | + |
|
69 | + // if api key is provided, we attempt to use steam web api |
|
70 | + if ($apiKey) { |
|
71 | + $result = $this->getUserProfileWebAPI($apiKey, $userProfile->identifier); |
|
72 | + } else { |
|
73 | + // otherwise we fallback to community data |
|
74 | + $result = $this->getUserProfileLegacyAPI($userProfile->identifier); |
|
75 | + } |
|
76 | + |
|
77 | + // fetch user profile |
|
78 | + foreach ($result as $k => $v) { |
|
79 | + $userProfile->$k = $v ?: $userProfile->$k; |
|
80 | + } |
|
81 | + } catch (\Exception $e) { |
|
82 | + } |
|
83 | + |
|
84 | + // store user profile |
|
85 | + $this->storage->set($this->providerId . '.user', $userProfile); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Fetch user profile on Steam web API |
|
90 | + * |
|
91 | + * @param $apiKey |
|
92 | + * @param $steam64 |
|
93 | + * |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function getUserProfileWebAPI($apiKey, $steam64) |
|
97 | + { |
|
98 | + $q = http_build_query(['key' => $apiKey, 'steamids' => $steam64]); |
|
99 | + $apiUrl = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' . $q; |
|
100 | + |
|
101 | + $response = $this->httpClient->request($apiUrl); |
|
102 | + |
|
103 | + $data = json_decode($response); |
|
104 | + |
|
105 | + $data = isset($data->response->players[0]) ? $data->response->players[0] : null; |
|
106 | + |
|
107 | + $data = new Data\Collection($data); |
|
108 | + |
|
109 | + $userProfile = []; |
|
110 | + |
|
111 | + $userProfile['displayName'] = (string)$data->get('personaname'); |
|
112 | + $userProfile['firstName'] = (string)$data->get('realname'); |
|
113 | + $userProfile['photoURL'] = (string)$data->get('avatarfull'); |
|
114 | + $userProfile['profileURL'] = (string)$data->get('profileurl'); |
|
115 | + $userProfile['country'] = (string)$data->get('loccountrycode'); |
|
116 | + |
|
117 | + return $userProfile; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Fetch user profile on community API |
|
122 | + * @param $steam64 |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function getUserProfileLegacyAPI($steam64) |
|
126 | + { |
|
127 | + libxml_use_internal_errors(false); |
|
128 | + |
|
129 | + $apiUrl = 'http://steamcommunity.com/profiles/' . $steam64 . '/?xml=1'; |
|
130 | + |
|
131 | + $response = $this->httpClient->request($apiUrl); |
|
132 | + |
|
133 | + $data = new \SimpleXMLElement($response); |
|
134 | + |
|
135 | + $data = new Data\Collection($data); |
|
136 | + |
|
137 | + $userProfile = []; |
|
138 | + |
|
139 | + $userProfile['displayName'] = (string)$data->get('steamID'); |
|
140 | + $userProfile['firstName'] = (string)$data->get('realname'); |
|
141 | + $userProfile['photoURL'] = (string)$data->get('avatarFull'); |
|
142 | + $userProfile['description'] = (string)$data->get('summary'); |
|
143 | + $userProfile['region'] = (string)$data->get('location'); |
|
144 | + $userProfile['profileURL'] = (string)$data->get('customURL') |
|
145 | + ? 'http://steamcommunity.com/id/' . (string)$data->get('customURL') |
|
146 | + : 'http://steamcommunity.com/profiles/' . $steam64; |
|
147 | + |
|
148 | + return $userProfile; |
|
149 | + } |
|
150 | 150 | } |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | { |
53 | 53 | parent::authenticateFinish(); |
54 | 54 | |
55 | - $userProfile = $this->storage->get($this->providerId . '.user'); |
|
55 | + $userProfile = $this->storage->get($this->providerId.'.user'); |
|
56 | 56 | |
57 | 57 | $userProfile->identifier = str_ireplace([ |
58 | 58 | 'http://steamcommunity.com/openid/id/', |
59 | 59 | 'https://steamcommunity.com/openid/id/', |
60 | 60 | ], '', $userProfile->identifier); |
61 | 61 | |
62 | - if (!$userProfile->identifier) { |
|
62 | + if ( ! $userProfile->identifier) { |
|
63 | 63 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
64 | 64 | } |
65 | 65 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | // store user profile |
85 | - $this->storage->set($this->providerId . '.user', $userProfile); |
|
85 | + $this->storage->set($this->providerId.'.user', $userProfile); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public function getUserProfileWebAPI($apiKey, $steam64) |
97 | 97 | { |
98 | 98 | $q = http_build_query(['key' => $apiKey, 'steamids' => $steam64]); |
99 | - $apiUrl = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' . $q; |
|
99 | + $apiUrl = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?'.$q; |
|
100 | 100 | |
101 | 101 | $response = $this->httpClient->request($apiUrl); |
102 | 102 | |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | |
109 | 109 | $userProfile = []; |
110 | 110 | |
111 | - $userProfile['displayName'] = (string)$data->get('personaname'); |
|
112 | - $userProfile['firstName'] = (string)$data->get('realname'); |
|
113 | - $userProfile['photoURL'] = (string)$data->get('avatarfull'); |
|
114 | - $userProfile['profileURL'] = (string)$data->get('profileurl'); |
|
115 | - $userProfile['country'] = (string)$data->get('loccountrycode'); |
|
111 | + $userProfile['displayName'] = (string) $data->get('personaname'); |
|
112 | + $userProfile['firstName'] = (string) $data->get('realname'); |
|
113 | + $userProfile['photoURL'] = (string) $data->get('avatarfull'); |
|
114 | + $userProfile['profileURL'] = (string) $data->get('profileurl'); |
|
115 | + $userProfile['country'] = (string) $data->get('loccountrycode'); |
|
116 | 116 | |
117 | 117 | return $userProfile; |
118 | 118 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | libxml_use_internal_errors(false); |
128 | 128 | |
129 | - $apiUrl = 'http://steamcommunity.com/profiles/' . $steam64 . '/?xml=1'; |
|
129 | + $apiUrl = 'http://steamcommunity.com/profiles/'.$steam64.'/?xml=1'; |
|
130 | 130 | |
131 | 131 | $response = $this->httpClient->request($apiUrl); |
132 | 132 | |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | |
137 | 137 | $userProfile = []; |
138 | 138 | |
139 | - $userProfile['displayName'] = (string)$data->get('steamID'); |
|
140 | - $userProfile['firstName'] = (string)$data->get('realname'); |
|
141 | - $userProfile['photoURL'] = (string)$data->get('avatarFull'); |
|
142 | - $userProfile['description'] = (string)$data->get('summary'); |
|
143 | - $userProfile['region'] = (string)$data->get('location'); |
|
144 | - $userProfile['profileURL'] = (string)$data->get('customURL') |
|
145 | - ? 'http://steamcommunity.com/id/' . (string)$data->get('customURL') |
|
146 | - : 'http://steamcommunity.com/profiles/' . $steam64; |
|
139 | + $userProfile['displayName'] = (string) $data->get('steamID'); |
|
140 | + $userProfile['firstName'] = (string) $data->get('realname'); |
|
141 | + $userProfile['photoURL'] = (string) $data->get('avatarFull'); |
|
142 | + $userProfile['description'] = (string) $data->get('summary'); |
|
143 | + $userProfile['region'] = (string) $data->get('location'); |
|
144 | + $userProfile['profileURL'] = (string) $data->get('customURL') |
|
145 | + ? 'http://steamcommunity.com/id/'.(string) $data->get('customURL') |
|
146 | + : 'http://steamcommunity.com/profiles/'.$steam64; |
|
147 | 147 | |
148 | 148 | return $userProfile; |
149 | 149 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | $data = new Data\Collection($response); |
49 | 49 | |
50 | - if (!$data->exists('id')) { |
|
50 | + if ( ! $data->exists('id')) { |
|
51 | 51 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
52 | 52 | } |
53 | 53 | |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | { |
76 | 76 | $result = (new Data\Parser())->parseBirthday($birthday, '-'); |
77 | 77 | |
78 | - $userProfile->birthDay = (int)$result[0]; |
|
79 | - $userProfile->birthMonth = (int)$result[1]; |
|
80 | - $userProfile->birthYear = (int)$result[2]; |
|
78 | + $userProfile->birthDay = (int) $result[0]; |
|
79 | + $userProfile->birthMonth = (int) $result[1]; |
|
80 | + $userProfile->birthYear = (int) $result[2]; |
|
81 | 81 | |
82 | 82 | return $userProfile; |
83 | 83 | } |
@@ -17,77 +17,77 @@ |
||
17 | 17 | */ |
18 | 18 | class Spotify extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'user-read-email'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - public $apiBaseUrl = 'https://api.spotify.com/v1/'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public $authorizeUrl = 'https://accounts.spotify.com/authorize'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://accounts.spotify.com/api/token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://developer.spotify.com/documentation/general/guides/authorization-guide/'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getUserProfile() |
|
49 | - { |
|
50 | - $response = $this->apiRequest('me'); |
|
51 | - |
|
52 | - $data = new Data\Collection($response); |
|
53 | - |
|
54 | - if (!$data->exists('id')) { |
|
55 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | - } |
|
57 | - |
|
58 | - $userProfile = new User\Profile(); |
|
59 | - |
|
60 | - $userProfile->identifier = $data->get('id'); |
|
61 | - $userProfile->displayName = $data->get('display_name'); |
|
62 | - $userProfile->email = $data->get('email'); |
|
63 | - $userProfile->emailVerified = $data->get('email'); |
|
64 | - $userProfile->profileURL = $data->filter('external_urls')->get('spotify'); |
|
65 | - $userProfile->photoURL = $data->filter('images')->get('url'); |
|
66 | - $userProfile->country = $data->get('country'); |
|
67 | - |
|
68 | - if ($data->exists('birthdate')) { |
|
69 | - $this->fetchBirthday($userProfile, $data->get('birthdate')); |
|
70 | - } |
|
71 | - |
|
72 | - return $userProfile; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Fetch use birthday |
|
77 | - * |
|
78 | - * @param User\Profile $userProfile |
|
79 | - * @param $birthday |
|
80 | - * |
|
81 | - * @return User\Profile |
|
82 | - */ |
|
83 | - protected function fetchBirthday(User\Profile $userProfile, $birthday) |
|
84 | - { |
|
85 | - $result = (new Data\Parser())->parseBirthday($birthday, '-'); |
|
86 | - |
|
87 | - $userProfile->birthDay = (int)$result[0]; |
|
88 | - $userProfile->birthMonth = (int)$result[1]; |
|
89 | - $userProfile->birthYear = (int)$result[2]; |
|
90 | - |
|
91 | - return $userProfile; |
|
92 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'user-read-email'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + public $apiBaseUrl = 'https://api.spotify.com/v1/'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public $authorizeUrl = 'https://accounts.spotify.com/authorize'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://accounts.spotify.com/api/token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://developer.spotify.com/documentation/general/guides/authorization-guide/'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getUserProfile() |
|
49 | + { |
|
50 | + $response = $this->apiRequest('me'); |
|
51 | + |
|
52 | + $data = new Data\Collection($response); |
|
53 | + |
|
54 | + if (!$data->exists('id')) { |
|
55 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | + } |
|
57 | + |
|
58 | + $userProfile = new User\Profile(); |
|
59 | + |
|
60 | + $userProfile->identifier = $data->get('id'); |
|
61 | + $userProfile->displayName = $data->get('display_name'); |
|
62 | + $userProfile->email = $data->get('email'); |
|
63 | + $userProfile->emailVerified = $data->get('email'); |
|
64 | + $userProfile->profileURL = $data->filter('external_urls')->get('spotify'); |
|
65 | + $userProfile->photoURL = $data->filter('images')->get('url'); |
|
66 | + $userProfile->country = $data->get('country'); |
|
67 | + |
|
68 | + if ($data->exists('birthdate')) { |
|
69 | + $this->fetchBirthday($userProfile, $data->get('birthdate')); |
|
70 | + } |
|
71 | + |
|
72 | + return $userProfile; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Fetch use birthday |
|
77 | + * |
|
78 | + * @param User\Profile $userProfile |
|
79 | + * @param $birthday |
|
80 | + * |
|
81 | + * @return User\Profile |
|
82 | + */ |
|
83 | + protected function fetchBirthday(User\Profile $userProfile, $birthday) |
|
84 | + { |
|
85 | + $result = (new Data\Parser())->parseBirthday($birthday, '-'); |
|
86 | + |
|
87 | + $userProfile->birthDay = (int)$result[0]; |
|
88 | + $userProfile->birthMonth = (int)$result[1]; |
|
89 | + $userProfile->birthYear = (int)$result[2]; |
|
90 | + |
|
91 | + return $userProfile; |
|
92 | + } |
|
93 | 93 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | $data = new Data\Collection($response); |
53 | 53 | |
54 | - if (!$data->exists('data')) { |
|
54 | + if ( ! $data->exists('data')) { |
|
55 | 55 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
56 | 56 | } |
57 | 57 |
@@ -17,66 +17,66 @@ |
||
17 | 17 | */ |
18 | 18 | class TwitchTV extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'user:read:email'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://api.twitch.tv/helix/'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://id.twitch.tv/oauth2/authorize'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://id.twitch.tv/oauth2/token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://dev.twitch.tv/docs/authentication/'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - protected function initialize() |
|
49 | - { |
|
50 | - parent::initialize(); |
|
51 | - |
|
52 | - $this->apiRequestHeaders['Client-ID'] = $this->clientId; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * {@inheritdoc} |
|
57 | - */ |
|
58 | - public function getUserProfile() |
|
59 | - { |
|
60 | - $response = $this->apiRequest('users'); |
|
61 | - |
|
62 | - $data = new Data\Collection($response); |
|
63 | - |
|
64 | - if (!$data->exists('data')) { |
|
65 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
66 | - } |
|
67 | - |
|
68 | - $users = $data->filter('data')->values(); |
|
69 | - $user = new Data\Collection($users[0]); |
|
70 | - |
|
71 | - $userProfile = new User\Profile(); |
|
72 | - |
|
73 | - $userProfile->identifier = $user->get('id'); |
|
74 | - $userProfile->displayName = $user->get('display_name'); |
|
75 | - $userProfile->photoURL = $user->get('profile_image_url'); |
|
76 | - $userProfile->email = $user->get('email'); |
|
77 | - $userProfile->description = strip_tags($user->get('description')); |
|
78 | - $userProfile->profileURL = "https://www.twitch.tv/{$userProfile->displayName}"; |
|
79 | - |
|
80 | - return $userProfile; |
|
81 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'user:read:email'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://api.twitch.tv/helix/'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://id.twitch.tv/oauth2/authorize'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://id.twitch.tv/oauth2/token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://dev.twitch.tv/docs/authentication/'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + protected function initialize() |
|
49 | + { |
|
50 | + parent::initialize(); |
|
51 | + |
|
52 | + $this->apiRequestHeaders['Client-ID'] = $this->clientId; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * {@inheritdoc} |
|
57 | + */ |
|
58 | + public function getUserProfile() |
|
59 | + { |
|
60 | + $response = $this->apiRequest('users'); |
|
61 | + |
|
62 | + $data = new Data\Collection($response); |
|
63 | + |
|
64 | + if (!$data->exists('data')) { |
|
65 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
66 | + } |
|
67 | + |
|
68 | + $users = $data->filter('data')->values(); |
|
69 | + $user = new Data\Collection($users[0]); |
|
70 | + |
|
71 | + $userProfile = new User\Profile(); |
|
72 | + |
|
73 | + $userProfile->identifier = $user->get('id'); |
|
74 | + $userProfile->displayName = $user->get('display_name'); |
|
75 | + $userProfile->photoURL = $user->get('profile_image_url'); |
|
76 | + $userProfile->email = $user->get('email'); |
|
77 | + $userProfile->description = strip_tags($user->get('description')); |
|
78 | + $userProfile->profileURL = "https://www.twitch.tv/{$userProfile->displayName}"; |
|
79 | + |
|
80 | + return $userProfile; |
|
81 | + } |
|
82 | 82 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | $data = new Data\Collection($response); |
53 | 53 | |
54 | - if (!$data->exists('id')) { |
|
54 | + if ( ! $data->exists('id')) { |
|
55 | 55 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
56 | 56 | } |
57 | 57 |
@@ -17,49 +17,49 @@ |
||
17 | 17 | */ |
18 | 18 | class Blizzard extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = ''; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = ''; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://us.battle.net/'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://us.battle.net/'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://us.battle.net/oauth/authorize'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://us.battle.net/oauth/authorize'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://us.battle.net/oauth/token'; |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://us.battle.net/oauth/token'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://develop.battle.net/documentation'; |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://develop.battle.net/documentation'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getUserProfile() |
|
49 | - { |
|
50 | - $response = $this->apiRequest('oauth/userinfo'); |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getUserProfile() |
|
49 | + { |
|
50 | + $response = $this->apiRequest('oauth/userinfo'); |
|
51 | 51 | |
52 | - $data = new Data\Collection($response); |
|
52 | + $data = new Data\Collection($response); |
|
53 | 53 | |
54 | - if (!$data->exists('id')) { |
|
55 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | - } |
|
54 | + if (!$data->exists('id')) { |
|
55 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | + } |
|
57 | 57 | |
58 | - $userProfile = new User\Profile(); |
|
58 | + $userProfile = new User\Profile(); |
|
59 | 59 | |
60 | - $userProfile->identifier = $data->get('id'); |
|
61 | - $userProfile->displayName = $data->get('battletag') ?: $data->get('login'); |
|
60 | + $userProfile->identifier = $data->get('id'); |
|
61 | + $userProfile->displayName = $data->get('battletag') ?: $data->get('login'); |
|
62 | 62 | |
63 | - return $userProfile; |
|
64 | - } |
|
63 | + return $userProfile; |
|
64 | + } |
|
65 | 65 | } |
@@ -17,18 +17,18 @@ |
||
17 | 17 | */ |
18 | 18 | class BlizzardAPAC extends Blizzard |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $apiBaseUrl = 'https://apac.battle.net/'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $apiBaseUrl = 'https://apac.battle.net/'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $authorizeUrl = 'https://apac.battle.net/oauth/authorize'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $authorizeUrl = 'https://apac.battle.net/oauth/authorize'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $accessTokenUrl = 'https://apac.battle.net/oauth/token'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $accessTokenUrl = 'https://apac.battle.net/oauth/token'; |
|
34 | 34 | } |
@@ -17,18 +17,18 @@ |
||
17 | 17 | */ |
18 | 18 | class BlizzardEU extends Blizzard |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $apiBaseUrl = 'https://eu.battle.net/'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $apiBaseUrl = 'https://eu.battle.net/'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $authorizeUrl = 'https://eu.battle.net/oauth/authorize'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $authorizeUrl = 'https://eu.battle.net/oauth/authorize'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $accessTokenUrl = 'https://eu.battle.net/oauth/token'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $accessTokenUrl = 'https://eu.battle.net/oauth/token'; |
|
34 | 34 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | $data = new Data\Collection($response); |
53 | 53 | |
54 | - if (!$data->exists('user_id')) { |
|
54 | + if ( ! $data->exists('user_id')) { |
|
55 | 55 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
56 | 56 | } |
57 | 57 |
@@ -17,50 +17,50 @@ |
||
17 | 17 | */ |
18 | 18 | class Amazon extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'profile'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'profile'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://api.amazon.com/'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://api.amazon.com/'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://www.amazon.com/ap/oa'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://www.amazon.com/ap/oa'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://api.amazon.com/auth/o2/token'; |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://api.amazon.com/auth/o2/token'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html'; |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getUserProfile() |
|
49 | - { |
|
50 | - $response = $this->apiRequest('user/profile'); |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getUserProfile() |
|
49 | + { |
|
50 | + $response = $this->apiRequest('user/profile'); |
|
51 | 51 | |
52 | - $data = new Data\Collection($response); |
|
52 | + $data = new Data\Collection($response); |
|
53 | 53 | |
54 | - if (!$data->exists('user_id')) { |
|
55 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | - } |
|
54 | + if (!$data->exists('user_id')) { |
|
55 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | + } |
|
57 | 57 | |
58 | - $userProfile = new User\Profile(); |
|
58 | + $userProfile = new User\Profile(); |
|
59 | 59 | |
60 | - $userProfile->identifier = $data->get('user_id'); |
|
61 | - $userProfile->displayName = $data->get('name'); |
|
62 | - $userProfile->email = $data->get('email'); |
|
60 | + $userProfile->identifier = $data->get('user_id'); |
|
61 | + $userProfile->displayName = $data->get('name'); |
|
62 | + $userProfile->email = $data->get('email'); |
|
63 | 63 | |
64 | - return $userProfile; |
|
65 | - } |
|
64 | + return $userProfile; |
|
65 | + } |
|
66 | 66 | } |