Skip to content

Commit

Permalink
Merge branch '3.0' into v3-google-plus-api-closed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dharma Saputra authored Dec 21, 2018
2 parents 4d24de3 + bc29c2b commit c2272a3
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 63 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ php:
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false

before_install:
- phpenv config-rm xdebug.ini || true

install: travis_retry composer install --no-interaction --prefer-dist --no-suggest

script: vendor/bin/phpunit --verbose
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Laravel Socialite provides an expressive, fluent interface to OAuth authenticati

**We are not accepting new adapters.**

**If you are using Laravel 5.3 or below, please use [Socialite 2.0](https://github.com/laravel/socialite/tree/2.0).**

Adapters for other platforms are listed at the community driven [Socialite Providers](https://socialiteproviders.github.io/) website.

## Official Documentation
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"Laravel\\Socialite\\Tests\\": "tests/"
}
},
"extra": {
Expand Down
14 changes: 10 additions & 4 deletions src/One/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ public function user()
->setToken($token->getIdentifier(), $token->getSecret());

return $instance->map([
'id' => $user->uid, 'nickname' => $user->nickname,
'name' => $user->name, 'email' => $user->email, 'avatar' => $user->imageUrl,
'id' => $user->uid,
'nickname' => $user->nickname,
'name' => $user->name,
'email' => $user->email,
'avatar' => $user->imageUrl,
]);
}

Expand All @@ -108,8 +111,11 @@ public function userFromTokenAndSecret($token, $secret)
->setToken($tokenCredentials->getIdentifier(), $tokenCredentials->getSecret());

return $instance->map([
'id' => $user->uid, 'nickname' => $user->nickname,
'name' => $user->name, 'email' => $user->email, 'avatar' => $user->imageUrl,
'id' => $user->uid,
'nickname' => $user->nickname,
'name' => $user->name,
'email' => $user->email,
'avatar' => $user->imageUrl,
]);
}

Expand Down
7 changes: 5 additions & 2 deletions src/One/TwitterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public function user()
->setToken($token->getIdentifier(), $token->getSecret());

return $instance->map([
'id' => $user->uid, 'nickname' => $user->nickname,
'name' => $user->name, 'email' => $user->email, 'avatar' => $user->imageUrl,
'id' => $user->uid,
'nickname' => $user->nickname,
'name' => $user->name,
'email' => $user->email,
'avatar' => $user->imageUrl,
'avatar_original' => str_replace('_normal', '', $user->imageUrl),
]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/SocialiteManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use Illuminate\Support\Manager;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Two\GitlabProvider;
use Laravel\Socialite\Two\GoogleProvider;
use Laravel\Socialite\One\TwitterProvider;
use Laravel\Socialite\Two\FacebookProvider;
Expand Down Expand Up @@ -107,7 +108,7 @@ protected function createGitlabDriver()
$config = $this->app['config']['services.gitlab'];

return $this->buildProvider(
\Laravel\Socialite\Two\GitlabProvider::class, $config
GitlabProvider::class, $config
);
}

Expand Down
9 changes: 6 additions & 3 deletions src/Two/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ protected function buildAuthUrlFromBase($url, $state)
protected function getCodeFields($state = null)
{
$fields = [
'client_id' => $this->clientId, 'redirect_uri' => $this->redirectUrl,
'client_id' => $this->clientId,
'redirect_uri' => $this->redirectUrl,
'scope' => $this->formatScopes($this->getScopes(), $this->scopeSeparator),
'response_type' => 'code',
];
Expand Down Expand Up @@ -276,8 +277,10 @@ public function getAccessTokenResponse($code)
protected function getTokenFields($code)
{
return [
'client_id' => $this->clientId, 'client_secret' => $this->clientSecret,
'code' => $code, 'redirect_uri' => $this->redirectUrl,
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'code' => $code,
'redirect_uri' => $this->redirectUrl,
];
}

Expand Down
6 changes: 4 additions & 2 deletions src/Two/BitbucketProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ protected function getEmailByToken($token)
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['uuid'], 'nickname' => $user['username'],
'name' => Arr::get($user, 'display_name'), 'email' => Arr::get($user, 'email'),
'id' => $user['uuid'],
'nickname' => $user['username'],
'name' => Arr::get($user, 'display_name'),
'email' => Arr::get($user, 'email'),
'avatar' => Arr::get($user, 'links.avatar.href'),
]);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Two/FacebookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ protected function mapUserToObject(array $user)
$avatarUrl = $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture';

return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => null, 'name' => isset($user['name']) ? $user['name'] : null,
'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $avatarUrl.'?type=normal',
'id' => $user['id'],
'nickname' => null,
'name' => isset($user['name']) ? $user['name'] : null,
'email' => isset($user['email']) ? $user['email'] : null,
'avatar' => $avatarUrl.'?type=normal',
'avatar_original' => $avatarUrl.'?width=1920',
'profileUrl' => isset($user['link']) ? $user['link'] : null,
]);
Expand Down
7 changes: 5 additions & 2 deletions src/Two/GithubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ protected function getEmailByToken($token)
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => $user['login'], 'name' => Arr::get($user, 'name'),
'email' => Arr::get($user, 'email'), 'avatar' => $user['avatar_url'],
'id' => $user['id'],
'nickname' => $user['login'],
'name' => Arr::get($user, 'name'),
'email' => Arr::get($user, 'email'),
'avatar' => $user['avatar_url'],
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Two/GoogleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function getTokenUrl()
*/
protected function getTokenFields($code)
{
return array_add(
return Arr::add(
parent::getTokenFields($code), 'grant_type', 'authorization_code'
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Two/LinkedInProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ protected function getUserByToken($token)
protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['id'], 'nickname' => null, 'name' => Arr::get($user, 'formattedName'),
'email' => Arr::get($user, 'emailAddress'), 'avatar' => Arr::get($user, 'pictureUrl'),
'id' => $user['id'],
'nickname' => null,
'name' => Arr::get($user, 'formattedName'),
'email' => Arr::get($user, 'emailAddress'),
'avatar' => Arr::get($user, 'pictureUrl'),
'avatar_original' => Arr::get($user, 'pictureUrls.values.0'),
]);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Fixtures/FacebookTestProviderStub.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Tests\Fixtures;
namespace Laravel\Socialite\Tests\Fixtures;

use stdClass;
use Mockery as m;
use Laravel\Socialite\Two\FacebookProvider;

Expand All @@ -28,6 +29,6 @@ protected function getHttpClient()
return $this->http;
}

return $this->http = m::mock(\stdClass::class);
return $this->http = m::mock(stdClass::class);
}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/OAuthOneTestProviderStub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Fixtures;
namespace Laravel\Socialite\Tests\Fixtures;

use Laravel\Socialite\One\AbstractProvider;

Expand Down
5 changes: 3 additions & 2 deletions tests/Fixtures/OAuthTwoTestProviderStub.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Tests\Fixtures;
namespace Laravel\Socialite\Tests\Fixtures;

use stdClass;
use Mockery as m;
use Laravel\Socialite\Two\User;
use Laravel\Socialite\Two\AbstractProvider;
Expand Down Expand Up @@ -44,6 +45,6 @@ protected function getHttpClient()
return $this->http;
}

return $this->http = m::mock(\stdClass::class);
return $this->http = m::mock(stdClass::class);
}
}
44 changes: 27 additions & 17 deletions tests/OAuthOneTest.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,66 @@
<?php

namespace Tests;
namespace Laravel\Socialite\Tests;

use Mockery as m;
use Illuminate\Http\Request;
use PHPUnit_Framework_TestCase;
use Tests\Fixtures\OAuthOneTestProviderStub;
use PHPUnit\Framework\TestCase;
use Illuminate\Http\RedirectResponse;
use League\OAuth1\Client\Server\User;
use League\OAuth1\Client\Server\Twitter;
use Illuminate\Contracts\Session\Session;
use Laravel\Socialite\One\User as SocialiteUser;
use League\OAuth1\Client\Credentials\TokenCredentials;
use League\OAuth1\Client\Credentials\TemporaryCredentials;
use Laravel\Socialite\Tests\Fixtures\OAuthOneTestProviderStub;
use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirectResponse;

class OAuthOneTest extends PHPUnit_Framework_TestCase
class OAuthOneTest extends TestCase
{
public function tearDown()
protected function tearDown()
{
parent::tearDown();

m::close();
}

public function testRedirectGeneratesTheProperIlluminateRedirectResponse()
{
$server = m::mock(\League\OAuth1\Client\Server\Twitter::class);
$server = m::mock(Twitter::class);
$server->shouldReceive('getTemporaryCredentials')->once()->andReturn('temp');
$server->shouldReceive('getAuthorizationUrl')->once()->with('temp')->andReturn('http://auth.url');
$request = Request::create('foo');
$request->setLaravelSession($session = m::mock(\Illuminate\Contracts\Session\Session::class));
$request->setLaravelSession($session = m::mock(Session::class));
$session->shouldReceive('put')->once()->with('oauth.temp', 'temp');

$provider = new OAuthOneTestProviderStub($request, $server);
$response = $provider->redirect();

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
$this->assertInstanceOf('Illuminate\Http\RedirectResponse', $response);
$this->assertInstanceOf(SymfonyRedirectResponse::class, $response);
$this->assertInstanceOf(RedirectResponse::class, $response);
}

public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
{
$server = m::mock(\League\OAuth1\Client\Server\Twitter::class);
$temp = m::mock(\League\OAuth1\Client\Credentials\TemporaryCredentials::class);
$server = m::mock(Twitter::class);
$temp = m::mock(TemporaryCredentials::class);
$server->shouldReceive('getTokenCredentials')->once()->with($temp, 'oauth_token', 'oauth_verifier')->andReturn(
$token = m::mock(\League\OAuth1\Client\Credentials\TokenCredentials::class)
$token = m::mock(TokenCredentials::class)
);
$server->shouldReceive('getUserDetails')->once()->with($token, false)->andReturn($user = m::mock(\League\OAuth1\Client\Server\User::class));
$server->shouldReceive('getUserDetails')->once()->with($token, false)->andReturn($user = m::mock(User::class));
$token->shouldReceive('getIdentifier')->twice()->andReturn('identifier');
$token->shouldReceive('getSecret')->twice()->andReturn('secret');
$user->uid = 'uid';
$user->email = '[email protected]';
$user->extra = ['extra' => 'extra'];
$request = Request::create('foo', 'GET', ['oauth_token' => 'oauth_token', 'oauth_verifier' => 'oauth_verifier']);
$request->setLaravelSession($session = m::mock(\Illuminate\Contracts\Session\Session::class));
$request->setLaravelSession($session = m::mock(Session::class));
$session->shouldReceive('get')->once()->with('oauth.temp')->andReturn($temp);

$provider = new OAuthOneTestProviderStub($request, $server);
$user = $provider->user();

$this->assertInstanceOf('Laravel\Socialite\One\User', $user);
$this->assertInstanceOf(SocialiteUser::class, $user);
$this->assertSame('uid', $user->id);
$this->assertSame('[email protected]', $user->email);
$this->assertSame(['extra' => 'extra'], $user->user);
Expand All @@ -61,9 +71,9 @@ public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
*/
public function testExceptionIsThrownWhenVerifierIsMissing()
{
$server = m::mock(\League\OAuth1\Client\Server\Twitter::class);
$server = m::mock(Twitter::class);
$request = Request::create('foo');
$request->setLaravelSession($session = m::mock(\Illuminate\Contracts\Session\Session::class));
$request->setLaravelSession($session = m::mock(Session::class));

$provider = new OAuthOneTestProviderStub($request, $server);
$provider->user();
Expand Down
Loading

0 comments on commit c2272a3

Please sign in to comment.