Skip to content

Commit

Permalink
Merge pull request hwi#45 from stloyd/infinity_loop
Browse files Browse the repository at this point in the history
Throw exception in security listener when `code` is missing
  • Loading branch information
asm89 committed Jun 29, 2012
2 parents 7d76be0 + fefc54a commit 7a90bbe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
4 changes: 0 additions & 4 deletions OAuth/ResourceOwner/GenericOAuth1ResourceOwner.php
Expand Up @@ -103,10 +103,6 @@ public function getAuthorizationUrl($redirectUri, array $extraParameters = array
*/
public function getAccessToken(Request $request, $redirectUri, array $extraParameters = array())
{
if (null === $oauthToken = $request->query->has('oauth_token')) {
throw new \RuntimeException('No oauth_token provided in the request.');
}

if (null === $requestToken = $this->storage->fetch($this, $request->query->get('oauth_token'))) {
throw new \RuntimeException('No request token found in the storage.');
}
Expand Down
4 changes: 0 additions & 4 deletions OAuth/ResourceOwner/GenericOAuth2ResourceOwner.php
Expand Up @@ -69,10 +69,6 @@ public function getAuthorizationUrl($redirectUri, array $extraParameters = array
*/
public function getAccessToken(Request $request, $redirectUri, array $extraParameters = array())
{
if (null === $code = $request->query->get('code')) {
throw new \RuntimeException('No code provided in the request.');
}

$parameters = array_merge($extraParameters, array(
'code' => $code,
'grant_type' => 'authorization_code',
Expand Down
6 changes: 5 additions & 1 deletion Security/Http/Firewall/OAuthListener.php
Expand Up @@ -15,7 +15,6 @@
Symfony\Component\HttpFoundation\Request,
Symfony\Component\Security\Core\Exception\AuthenticationException;


use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken,
HWI\Bundle\OAuthBundle\Security\Http\ResourceOwnerMap;

Expand Down Expand Up @@ -75,6 +74,11 @@ protected function attemptAuthentication(Request $request)
{
list($resourceOwner, $checkPath) = $this->resourceOwnerMap->getResourceOwnerByRequest($request);

if (!$resourceOwner->handles($request)) {
// Can't use AuthenticationException below, as it leads to infinity loop
throw new \RuntimeException('No oauth code in the request.');
}

$accessToken = $resourceOwner->getAccessToken(
$request,
$this->httpUtils->createRequest($request, $checkPath)->getUri()
Expand Down

0 comments on commit 7a90bbe

Please sign in to comment.