This is my code for logging the user in using Laravel Passport:
public function login(LoginRequest $request)
{
$email = $request->email;
$password = $request->password;
$request->request->add([
'username' => $email,
'password' => $password,
'grant_type' => 'password',
'client_id' => env('PASSWORD_GRANT_CLIENT_ID'),
'client_secret' => env('PASSWORD_GRANT_CLIENT_SECRET'),
'scope' => '*',
]);
$tokenRequest = Request::create(
env('APP_URL') . '/oauth/token',
'post'
);
$response = Route::dispatch($tokenRequest);
return $response;
}
The LoginRequest class:
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|string|email|max:255',
'password' => 'required|min:6',
];
}
When I try to login using Insomnia
client, the following is returned:
{
"error": "unsupported_grant_type",
"message": "The authorization grant type is not supported by the
authorization server.",
"hint": "Check that all required parameters have been provided"
}
I have tried returning the $request
from the login function instead of $response
, yet what it returns is what's exactly sent from the function so I know the problem is not that.
What was more confusing is that if I replace the LoginRequest injection inside the login method with the default Request
, the function works fine.
Anyone know how this could be resolved?