I've managed to accomplish what i wanted to do, if anyone comes across this issue, here's what i did...
Created a custom AuthController and login method to replace Laravel Passport's default oauth/token:
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Illuminate\Http\Response;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Response;
use \Laravel\Passport\Http\Controllers\AccessTokenController as AccessTokenController;
class AuthController extends AccessTokenController
{
use AuthenticatesUsers;
//custom login method
public function login(Request $request)
{
//...
}
}
Before any other login actions, check if a user has reached the max login attempts:
//custom login method
public function login(Request $request)
{
//check if the max number of login attempts has been reached
if ($this->hasTooManyLoginAttempts($request))
{
$this->fireLockoutEvent($request);
return "To many attempts...";
}
//...
}
Verify user credentials by attempting a login. If a logins succeeds reset the the failed attempts count. If it fails, increment the count:
//check if user has reached the max number of login attempts
//verify user credentials
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
{
//reset failed login attemps
$this->clearLoginAttempts($request);
//...
}
else
{
//count user failed login attempts
$this->incrementLoginAttempts($request);
return "Login failed...";
}
And finally, since Passport (OAuth2) uses PSR-7 requests (Server Request Interface), we need to convert the standard Laravel request to PSR-7 in order to issue the access token:
//Authentication passed...
//convert Laravel Request (Symfony Request) to PSR-7
$psr7Factory = new DiactorosFactory();
$psrRequest = $psr7Factory->createRequest($request);
//generate access token
$tokenResponse = parent::issueToken($psrRequest);
//return issued token
return Response::json($tokenResponse);
Here's the complete login method:
public function login(Request $request)
{
//check if user has reached the max number of login attempts
if ($this->hasTooManyLoginAttempts($request))
{
$this->fireLockoutEvent($request);
return "To many attempts...";
}
//verify user credentials
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
{
//Authentication passed...
//reset failed login attemps
$this->clearLoginAttempts($request);
//convert Laravel Request (Symfony Request) to PSR-7
$psr7Factory = new DiactorosFactory();
$psrRequest = $psr7Factory->createRequest($request);
//generate access token
$tokenResponse = parent::issueToken($psrRequest);
//return issued token
return Response::json($tokenResponse);
}
else
{
//count user failed login attempts
$this->incrementLoginAttempts($request);
return "Login failed...";
}
}