Skip to content

Commit

Permalink
Merge pull request #448 from derekmd/remove-guzzle-5-workaround
Browse files Browse the repository at this point in the history
[4.x] Remove guzzlehttp/guzzle ~5.0 workaround
  • Loading branch information
taylorotwell authored May 29, 2020
2 parents 8e68834 + 2b53429 commit fbba587
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
5 changes: 1 addition & 4 deletions src/Two/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laravel\Socialite\Two;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -258,11 +257,9 @@ protected function hasInvalidState()
*/
public function getAccessTokenResponse($code)
{
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';

$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'headers' => ['Accept' => 'application/json'],
$postKey => $this->getTokenFields($code),
'form_params' => $this->getTokenFields($code),
]);

return json_decode($response->getBody(), true);
Expand Down
5 changes: 1 addition & 4 deletions src/Two/BitbucketProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laravel\Socialite\Two;

use Exception;
use GuzzleHttp\ClientInterface;
use Illuminate\Support\Arr;

class BitbucketProvider extends AbstractProvider implements ProviderInterface
Expand Down Expand Up @@ -103,12 +102,10 @@ protected function mapUserToObject(array $user)
*/
public function getAccessToken($code)
{
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';

$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'auth' => [$this->clientId, $this->clientSecret],
'headers' => ['Accept' => 'application/json'],
$postKey => $this->getTokenFields($code),
'form_params' => $this->getTokenFields($code),
]);

return json_decode($response->getBody(), true)['access_token'];
Expand Down
5 changes: 1 addition & 4 deletions src/Two/FacebookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Socialite\Two;

use GuzzleHttp\ClientInterface;
use Illuminate\Support\Arr;

class FacebookProvider extends AbstractProvider implements ProviderInterface
Expand Down Expand Up @@ -70,10 +69,8 @@ protected function getTokenUrl()
*/
public function getAccessTokenResponse($code)
{
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';

$response = $this->getHttpClient()->post($this->getTokenUrl(), [
$postKey => $this->getTokenFields($code),
'form_params' => $this->getTokenFields($code),
]);

$data = json_decode($response->getBody(), true);
Expand Down
7 changes: 2 additions & 5 deletions tests/OAuthTwoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Socialite\Tests;

use GuzzleHttp\ClientInterface;
use Illuminate\Contracts\Session\Session;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -45,9 +44,8 @@ public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
$session->shouldReceive('pull')->once()->with('state')->andReturn(str_repeat('A', 40));
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect_uri');
$provider->http = m::mock(stdClass::class);
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
$provider->http->shouldReceive('post')->once()->with('http://token.url', [
'headers' => ['Accept' => 'application/json'], $postKey => ['client_id' => 'client_id', 'client_secret' => 'client_secret', 'code' => 'code', 'redirect_uri' => 'redirect_uri'],
'headers' => ['Accept' => 'application/json'], 'form_params' => ['client_id' => 'client_id', 'client_secret' => 'client_secret', 'code' => 'code', 'redirect_uri' => 'redirect_uri'],
])->andReturn($response = m::mock(stdClass::class));
$response->shouldReceive('getBody')->once()->andReturn('{ "access_token" : "access_token", "refresh_token" : "refresh_token", "expires_in" : 3600 }');
$user = $provider->user();
Expand All @@ -66,9 +64,8 @@ public function testUserReturnsAUserInstanceForTheAuthenticatedFacebookRequest()
$session->shouldReceive('pull')->once()->with('state')->andReturn(str_repeat('A', 40));
$provider = new FacebookTestProviderStub($request, 'client_id', 'client_secret', 'redirect_uri');
$provider->http = m::mock(stdClass::class);
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
$provider->http->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.3/oauth/access_token', [
$postKey => ['client_id' => 'client_id', 'client_secret' => 'client_secret', 'code' => 'code', 'redirect_uri' => 'redirect_uri'],
'form_params' => ['client_id' => 'client_id', 'client_secret' => 'client_secret', 'code' => 'code', 'redirect_uri' => 'redirect_uri'],
])->andReturn($response = m::mock(stdClass::class));
$response->shouldReceive('getBody')->once()->andReturn(json_encode(['access_token' => 'access_token', 'expires' => 5183085]));
$user = $provider->user();
Expand Down

0 comments on commit fbba587

Please sign in to comment.