|
|
@ -1,5 +1,7 @@ |
|
|
|
<?php namespace SocialNorm\StackOverflow; |
|
|
|
<?php namespace SocialNorm\StackOverflow; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use SocialNorm\Exceptions\AuthNotUsableException; |
|
|
|
|
|
|
|
use SocialNorm\Exceptions\InvalidAuthorizationCodeException; |
|
|
|
use SocialNorm\Providers\OAuth2Provider; |
|
|
|
use SocialNorm\Providers\OAuth2Provider; |
|
|
|
use GuzzleHttp\Client as HttpClient; |
|
|
|
use GuzzleHttp\Client as HttpClient; |
|
|
|
use SocialNorm\Request; |
|
|
|
use SocialNorm\Request; |
|
|
@ -21,6 +23,7 @@ class StackOverflowProvider extends OAuth2Provider |
|
|
|
protected $headers = [ |
|
|
|
protected $headers = [ |
|
|
|
'authorize' => [], |
|
|
|
'authorize' => [], |
|
|
|
'access_token' => [ |
|
|
|
'access_token' => [ |
|
|
|
|
|
|
|
'Accept' => 'application/json', |
|
|
|
'Content-Type' => 'application/x-www-form-urlencoded' |
|
|
|
'Content-Type' => 'application/x-www-form-urlencoded' |
|
|
|
], |
|
|
|
], |
|
|
|
'user_details' => [], |
|
|
|
'user_details' => [], |
|
|
@ -65,12 +68,21 @@ class StackOverflowProvider extends OAuth2Provider |
|
|
|
|
|
|
|
|
|
|
|
protected function parseTokenResponse($response) |
|
|
|
protected function parseTokenResponse($response) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->parseJsonTokenResponse($response); |
|
|
|
return explode('=', $response, 2)[1]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function parseUserDataResponse($response) |
|
|
|
protected function parseUserDataResponse($response) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return json_decode($response, true); |
|
|
|
$decoded = (array)json_decode($response, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($decoded === false || json_last_error()) |
|
|
|
|
|
|
|
throw new InvalidAuthorizationCodeException('Corrupt response json: ' . $response . ", error " . json_last_error_msg()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (0 == count(array_get($decoded, 'items'))) { |
|
|
|
|
|
|
|
throw new AuthNotUsableException('No profile on StackOverflow. Resp: '.$response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $decoded; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function userId() |
|
|
|
protected function userId() |
|
|
|