Skip to content

Commit

Permalink
Merge pull request #159 from chalasr/bugfix_no_jwt_found
Browse files Browse the repository at this point in the history
Fix anonymous access by removing the AuthenticationCredentialsNotFoundException
  • Loading branch information
slashfan committed Apr 11, 2016
2 parents 49f53fa + 811ec7d commit 3631b62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Resources/doc/2-data-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function onAuthenticationFailureResponse(AuthenticationFailureEvent $even

#### Events::JWT_INVALID - customize the invalid token response

By default, if the token is invalid or not set, the response is just a json containing the corresponding error message and a 401 status code, but you can set a custom response.
By default, if the token is invalid, the response is just a json containing the corresponding error message and a 401 status code, but you can set a custom response.

``` yaml
# services.yml
Expand Down
9 changes: 5 additions & 4 deletions Security/Firewall/JWTListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -74,9 +73,11 @@ public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();

try {
if (!$requestToken = $this->getRequestToken($request)) {
return;
}

$requestToken = $this->getRequestToken($request);
try {

$token = new JWTUserToken();
$token->setRawToken($requestToken);
Expand Down Expand Up @@ -137,6 +138,6 @@ protected function getRequestToken(Request $request)
}
}

throw new AuthenticationCredentialsNotFoundException('No JWT token found');
return false;
}
}

0 comments on commit 3631b62

Please sign in to comment.