vendredi 29 décembre 2017

Laravel passport custom error message and status code when user unauthorized

my project is running on Laravel 5.4 and I use passport to make authentication via api with bearer token. everything works fine, but when unauthorized user tries to reach resource that require authentication, the user gets error message 405 method not allowed enter image description here

but I want response to be 401 unauthorized . how can change this, and send only response with message, instead of exception? I did research, but couldn't find anything. I use standard laravel middleware for authorization auth:api. my routes grouped in middleware

Route::group(['middleware' => 'auth:api'], function () {
  // these routes should return 401 if user not authenticated
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire