Skip to content

Commit

Permalink
Merge pull request #292 from shadowhand/hotfix/288-quote-grant-as-par…
Browse files Browse the repository at this point in the history
…ameter

Ensure that grant_type is the expected value
  • Loading branch information
ramsey committed May 8, 2015
2 parents ff1d77b + bdc78ee commit a839846
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function getAccessToken($grant = 'authorization_code', array $params = []
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $this->redirectUri,
'grant_type' => $grant,
'grant_type' => (string) $grant,
];

$requestParams = $grant->prepRequestParams($defaultParams, $params);
Expand Down
45 changes: 45 additions & 0 deletions test/src/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,51 @@ public function testRandomGeneratorCreatesRandomState()
$this->assertRegExp('/^[a-zA-Z0-9\/+]{32}$/', $qs['state']);
}

public function testGetAccessToken()
{
$provider = new MockProvider([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
]);

$grant_name = 'mock';
$raw_response = ['access_token' => 'okay', 'expires_in' => 3600];
$token = new AccessToken($raw_response);

$contains_correct_grant_type = function ($params) use ($grant_name) {
return is_array($params) && $params['grant_type'] === $grant_name;
};

$grant = m::mock('League\OAuth2\Client\Grant\GrantInterface');
$grant->shouldReceive('__toString')
->times(1)
->andReturn($grant_name);
$grant->shouldReceive('prepRequestParams')
->with(
m::on($contains_correct_grant_type),
m::type('array')
)
->andReturn([]);
$grant->shouldReceive('handleResponse')
->with($raw_response)
->andReturn($token);

$response = m::mock('Ivory\HttpAdapter\Message\ResponseInterface');
$response->shouldReceive('getBody')
->times(1)
->andReturn(json_encode($raw_response));

$client = m::mock('Ivory\HttpAdapter\HttpAdapterInterface');
$client->shouldReceive('post')->times(1)->andReturn($response);

$provider->setHttpClient($client);

$result = $provider->getAccessToken($grant, ['code' => 'mock_authorization_code']);

$this->assertSame($result, $token);
}

public function testErrorResponsesCanBeCustomizedAtTheProvider()
{
$provider = new MockProvider([
Expand Down

0 comments on commit a839846

Please sign in to comment.