Merge branch 'master' into 1.0
commit
a5c1ce821f
|
@ -125,12 +125,11 @@ These providers allow integration with other providers not supported by `oauth2-
|
|||
so please help them out with a pull request if you notice this.
|
||||
|
||||
- [Battle.net](https://packagist.org/packages/depotwarehouse/oauth2-bnet)
|
||||
- [Mail.ru](https://packagist.org/packages/aego/oauth2-mailru)
|
||||
- [Meetup](https://github.com/howlowck/meetup-oauth2-provider)
|
||||
- [Odnoklassniki](https://packagist.org/packages/aego/oauth2-odnoklassniki)
|
||||
- [Yandex](https://packagist.org/packages/aego/oauth2-yandex)
|
||||
- [Mail.ru](https://packagist.org/packages/aego/oauth2-mailru)
|
||||
- [QQ](https://github.com/tlikai/oauth2-client)
|
||||
- [Weibo](https://github.com/tlikai/oauth2-client)
|
||||
- [Meetup](https://github.com/howlowck/meetup-oauth2-provider)
|
||||
- [Vkontakte](https://packagist.org/packages/j4k/oauth2-vkontakte)
|
||||
|
||||
### Implementing your own provider
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"mockery/mockery": "~0.9",
|
||||
"squizlabs/php_codesniffer": "~1.5"
|
||||
"squizlabs/php_codesniffer": "~2.0"
|
||||
},
|
||||
"keywords": [
|
||||
"oauth",
|
||||
|
|
|
@ -33,14 +33,17 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
|
||||
public $headers = null;
|
||||
|
||||
/**
|
||||
* @var GuzzleClient
|
||||
*/
|
||||
protected $httpClient;
|
||||
|
||||
protected $redirectHandler;
|
||||
|
||||
/**
|
||||
* @var int This represents: PHP_QUERY_RFC1738, which is the default value for php 5.4
|
||||
* and the default encryption type for the http_build_query setup
|
||||
*/
|
||||
/**
|
||||
* @var int This represents: PHP_QUERY_RFC1738, which is the default value for php 5.4
|
||||
* and the default encryption type for the http_build_query setup
|
||||
*/
|
||||
protected $httpBuildEncType = 1;
|
||||
|
||||
public function __construct($options = [])
|
||||
|
@ -93,7 +96,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
* @param AccessToken $token
|
||||
* @return string
|
||||
*/
|
||||
abstract public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token);
|
||||
abstract public function urlUserDetails(AccessToken $token);
|
||||
|
||||
/**
|
||||
* Given an object response from the server, process the user details into a format expected by the user
|
||||
|
@ -103,7 +106,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
* @param AccessToken $token
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token);
|
||||
abstract public function userDetails($response, AccessToken $token);
|
||||
|
||||
public function getScopes()
|
||||
{
|
||||
|
@ -131,6 +134,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
return $this->urlAuthorize().'?'.$this->httpBuildQuery($params, '', '&');
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
public function authorize($options = [])
|
||||
{
|
||||
$url = $this->getAuthorizationUrl($options);
|
||||
|
@ -174,8 +178,8 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
// @codeCoverageIgnoreStart
|
||||
// No providers included with this library use get but 3rd parties may
|
||||
$client = $this->getHttpClient();
|
||||
$client->setBaseUrl($this->urlAccessToken().'?'.$this->httpBuildQuery($requestParams, '', '&'));
|
||||
$request = $client->send();
|
||||
$client->setBaseUrl($this->urlAccessToken() . '?' . $this->httpBuildQuery($requestParams, '', '&'));
|
||||
$request = $client->get(null, null, $requestParams)->send();
|
||||
$response = $request->getBody();
|
||||
break;
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
@ -267,6 +271,21 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
return $this->userScreenName(json_decode($response), $token);
|
||||
}
|
||||
|
||||
public function userUid($response, AccessToken $token)
|
||||
{
|
||||
return isset($response->id) && $response->id ? $response->id : null;
|
||||
}
|
||||
|
||||
public function userEmail($response, AccessToken $token)
|
||||
{
|
||||
return isset($response->email) && $response->email ? $response->email : null;
|
||||
}
|
||||
|
||||
public function userScreenName($response, AccessToken $token)
|
||||
{
|
||||
return isset($response->name) && $response->name ? $response->name : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build HTTP the HTTP query, handling PHP version control options
|
||||
*
|
||||
|
@ -274,6 +293,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
* @param integer $numeric_prefix
|
||||
* @param string $arg_separator
|
||||
* @param null|integer $enc_type
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnoreStart
|
||||
*/
|
||||
|
|
|
@ -13,10 +13,10 @@ class Google extends AbstractProvider
|
|||
'https://www.googleapis.com/auth/userinfo.email',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string If set, this will be sent to google as the "hd" parameter.
|
||||
* @link https://developers.google.com/accounts/docs/OAuth2Login#hd-param
|
||||
*/
|
||||
/**
|
||||
* @var string If set, this will be sent to google as the "hd" parameter.
|
||||
* @link https://developers.google.com/accounts/docs/OAuth2Login#hd-param
|
||||
*/
|
||||
public $hostedDomain = '';
|
||||
|
||||
public function setHostedDomain($hd)
|
||||
|
|
|
@ -2,10 +2,15 @@
|
|||
|
||||
namespace League\OAuth2\Client\Test\Provider;
|
||||
|
||||
use League\OAuth2\Client\Provider\AbstractProvider;
|
||||
use League\OAuth2\Client\Token\AccessToken;
|
||||
use Mockery as m;
|
||||
|
||||
class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var AbstractProvider
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
protected function setUp()
|
||||
|
@ -87,6 +92,56 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertNotFalse($this->testFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $response
|
||||
*
|
||||
* @dataProvider userPropertyProvider
|
||||
*/
|
||||
public function testGetUserProperties($response, $name = null, $email = null, $id = null)
|
||||
{
|
||||
$token = new AccessToken(['access_token' => 'abc', 'expires_in' => 3600]);
|
||||
|
||||
$provider = $this->getMockForAbstractClass(
|
||||
'\League\OAuth2\Client\Provider\AbstractProvider',
|
||||
[
|
||||
[
|
||||
'clientId' => 'mock_client_id',
|
||||
'clientSecret' => 'mock_secret',
|
||||
'redirectUri' => 'none',
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
/**
|
||||
* @var $provider AbstractProvider
|
||||
*/
|
||||
|
||||
$this->assertEquals($name, $provider->userScreenName($response, $token));
|
||||
$this->assertEquals($email, $provider->userEmail($response, $token));
|
||||
$this->assertEquals($id, $provider->userUid($response, $token));
|
||||
}
|
||||
|
||||
public function userPropertyProvider()
|
||||
{
|
||||
$response = new \stdClass();
|
||||
$response->id = 1;
|
||||
$response->email = 'test@example.com';
|
||||
$response->name = 'test';
|
||||
|
||||
$response2 = new \stdClass();
|
||||
$response2->id = null;
|
||||
$response2->email = null;
|
||||
$response2->name = null;
|
||||
|
||||
$response3 = new \stdClass();
|
||||
|
||||
return [
|
||||
[$response, 'test', 'test@example.com', 1],
|
||||
[$response2],
|
||||
[$response3],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class MockProvider extends \League\OAuth2\Client\Provider\AbstractProvider
|
||||
|
|
Loading…
Reference in New Issue