Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix anonymous access by removing the AuthenticationCredentialsNotFoundException #159

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}