mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-01 16:33:07 +05:30
Added authentication failure events
This commit is contained in:
parent
643c3493c4
commit
b68a5c2abb
51
src/Event/ClientAuthenticationFailedEvent.php
Normal file
51
src/Event/ClientAuthenticationFailedEvent.php
Normal 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;
|
||||
}
|
||||
}
|
51
src/Event/UserAuthenticationFailedEvent.php
Normal file
51
src/Event/UserAuthenticationFailedEvent.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user