working on ms
parent
f6823336b9
commit
4a843af711
|
@ -24,7 +24,14 @@ class Microsoft extends IdentityProvider
|
||||||
|
|
||||||
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
|
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
|
||||||
{
|
{
|
||||||
$imageHeaders = get_headers('https://apis.live.net/v5.0/'.$response->id.'/picture', 1);
|
$client = $this->getHttpClient();
|
||||||
|
$client->setBaseUrl('https://apis.live.net/v5.0/' . $response->id . '/picture');
|
||||||
|
$request = $client->get()->send();
|
||||||
|
$info = $request->getInfo();
|
||||||
|
|
||||||
|
print_r($info);die();
|
||||||
|
|
||||||
|
$imageUrl = $info['url'];
|
||||||
|
|
||||||
$user = new User;
|
$user = new User;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LeagueTest\OAuth2\Client\Provider;
|
||||||
|
|
||||||
|
use \Mockery as m;
|
||||||
|
|
||||||
|
class MicrosoftTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected $provider;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->provider = new \League\OAuth2\Client\Provider\Microsoft(array(
|
||||||
|
'clientId' => 'mock_client_id',
|
||||||
|
'clientSecret' => 'mock_secret',
|
||||||
|
'redirectUri' => 'none',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
# m::close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAuthorizationUrl()
|
||||||
|
{
|
||||||
|
$url = $this->provider->getAuthorizationUrl();
|
||||||
|
$uri = parse_url($url);
|
||||||
|
parse_str($uri['query'], $query);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('client_id', $query);
|
||||||
|
$this->assertArrayHasKey('redirect_uri', $query);
|
||||||
|
$this->assertArrayHasKey('state', $query);
|
||||||
|
$this->assertArrayHasKey('scope', $query);
|
||||||
|
$this->assertArrayHasKey('response_type', $query);
|
||||||
|
$this->assertArrayHasKey('approval_prompt', $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUrlAccessToken()
|
||||||
|
{
|
||||||
|
$url = $this->provider->urlAccessToken();
|
||||||
|
$uri = parse_url($url);
|
||||||
|
|
||||||
|
$this->assertEquals('/token', $uri['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAccessToken()
|
||||||
|
{
|
||||||
|
$response = m::mock('Guzzle\Http\Message\Response');
|
||||||
|
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
|
|
||||||
|
$client = m::mock('Guzzle\Service\Client');
|
||||||
|
$client->shouldReceive('setBaseUrl')->times(1);
|
||||||
|
$client->shouldReceive('post->send')->times(1)->andReturn($response);
|
||||||
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
|
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
|
||||||
|
|
||||||
|
# print_r($token);die();
|
||||||
|
|
||||||
|
$this->assertEquals('mock_access_token', $token->accessToken);
|
||||||
|
$this->assertLessThanOrEqual(time() + 3600, $token->expires);
|
||||||
|
$this->assertGreaterThanOrEqual(time(), $token->expires);
|
||||||
|
$this->assertEquals('mock_refresh_token', $token->refreshToken);
|
||||||
|
$this->assertEquals('1', $token->uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScopes()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array('wl.basic', 'wl.emails'), $this->provider->getScopes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserData()
|
||||||
|
{
|
||||||
|
$postResponse = m::mock('Guzzle\Http\Message\Response');
|
||||||
|
$postResponse->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
|
|
||||||
|
$getResponse = m::mock('Guzzle\Http\Message\Response');
|
||||||
|
$getResponse->shouldReceive('getBody')->times(1)->andReturn('{"id": 12345, "name": "mock_name", "first_name": "mock_first_name", "last_name": "mock_last_name", "emails": {"preferred": "mock_email"}, "link": "mock_link"}');
|
||||||
|
|
||||||
|
$client = m::mock('Guzzle\Service\Client');
|
||||||
|
$client->shouldReceive('setBaseUrl')->times(1);
|
||||||
|
$client->shouldReceive('post->send')->times(1)->andReturn($postResponse);
|
||||||
|
$client->shouldReceive('get->send')->times(1)->andReturn($getResponse);
|
||||||
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
|
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
|
||||||
|
$user = $this->provider->getUserDetails($token);
|
||||||
|
|
||||||
|
$this->assertEquals(12345, $this->provider->getUserUid($token));
|
||||||
|
$this->assertEquals(array('mock_first_name', 'mock_last_name'), $this->provider->getUserScreenName($token));
|
||||||
|
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
|
||||||
|
$this->assertEquals('mock_email', $user->email);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue