Skip to content

Commit

Permalink
Remove setting response after failed authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Jovaišas committed Jun 21, 2018
1 parent e900f85 commit 9db1160
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.0.0
### Changed
- `\Paysera\BearerAuthenticationBundle\Listener\BearerListener` not does not return 403 response after failing to authenticate user
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#Bearer Authentication Bundle
# Bearer Authentication Bundle

##Install
## Install

Add bundle to `AppKernel.php`:
```
```php
$bundles = [
...
new Paysera\BearerAuthenticationBundle\PayseraBearerAuthenticationBundle(),
];
```

##Samples
## Samples

Sample security.yml
```
Sample `security.yml`
```yml
security:
providers:
bearer_user:
Expand All @@ -27,7 +27,7 @@ security:
```
All bearer handlers must be tagged with:
```
```xml
<tag name="paysera_bearer_authentication.handler" />
```
and implement `\Paysera\BearerAuthenticationBundle\Security\User\HandlerInterface`
15 changes: 1 addition & 14 deletions src/Listener/BearerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
namespace Paysera\BearerAuthenticationBundle\Listener;

use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Paysera\BearerAuthenticationBundle\Security\Authentication\Token\BearerToken;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Paysera\BearerAuthenticationBundle\Security\Authentication\Token\BearerTokenInterface;

class BearerListener implements ListenerInterface
{
Expand Down Expand Up @@ -58,20 +56,9 @@ public function handle(GetResponseEvent $event)
try {
$authToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authToken);

return;
} catch (AuthenticationException $e) {
} catch (AuthenticationException $exception) {
$this->logger->debug('authentication failed for token', [$token]);
if ($token instanceof BearerTokenInterface) {
$this->tokenStorage->setToken(null);
}
$response = new Response;
$response->setStatusCode(403);
$event->setResponse($response);
}
$response = new Response;
$response->setStatusCode(403);
$event->setResponse($response);
}

private function fixAuthHeader(HeaderBag $headers)
Expand Down

0 comments on commit 9db1160

Please sign in to comment.