Added authentication failure events

This commit is contained in:
Alex Bilbie 2014-09-30 22:16:26 +01:00
parent 643c3493c4
commit b68a5c2abb
6 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,51 @@
<?php
/**
* OAuth 2.0 client authentication failed event
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Event;
use League\Event\AbstractEvent;
use Symfony\Component\HttpFoundation\Request;
class ClientAuthenticationFailedEvent extends AbstractEvent
{
/**
* Request
* @var \Symfony\Component\HttpFoundation\Request
*/
private $request;
/**
* Init the event with a request
* @param \Symfony\Component\HttpFoundation\Requesty $request
*/
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* The name of the event
* @return string
*/
public function getName()
{
return 'error.auth.client';
}
/**
* Return session
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getSession()
{
return $this->request;
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* OAuth 2.0 user authentication failed event
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Event;
use League\Event\AbstractEvent;
use Symfony\Component\HttpFoundation\Request;
class UserAuthenticationFailedEvent extends AbstractEvent
{
/**
* Request
* @var \Symfony\Component\HttpFoundation\Request
*/
private $request;
/**
* Init the event with a request
* @param \Symfony\Component\HttpFoundation\Requesty $request
*/
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* The name of the event
* @return string
*/
public function getName()
{
return 'error.auth.user';
}
/**
* Return session
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getSession()
{
return $this->request;
}
}

View File

@ -19,6 +19,7 @@ use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Auth code grant class
@ -92,6 +93,7 @@ class AuthCodeGrant extends AbstractGrant
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}
@ -192,6 +194,7 @@ class AuthCodeGrant extends AbstractGrant
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}

View File

@ -16,6 +16,7 @@ use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Client credentials grant class
@ -79,6 +80,7 @@ class ClientCredentialsGrant extends AbstractGrant
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}

View File

@ -17,6 +17,7 @@ use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Password grant class
@ -102,6 +103,7 @@ class PasswordGrant extends AbstractGrant
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}
@ -119,6 +121,7 @@ class PasswordGrant extends AbstractGrant
$userId = call_user_func($this->getVerifyCredentialsCallback(), $username, $password);
if ($userId === false) {
$this->server->getEventEmitter()->emit(new Event\UserAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidCredentialsException();
}

View File

@ -17,6 +17,7 @@ use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Event;
/**
* Referesh token grant
@ -83,6 +84,7 @@ class RefreshTokenGrant extends AbstractGrant
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}