Open JesusGR4 opened 7 years ago
MethodNowAllowed usually means you are sending a GET request to a POST route or vice versa
Same here.
When a pass a valid token everithing is ok. But when a pass a invalid or expired token, MethodNotAllowedHttpException
is throw.
"require": {
"php": ">=7.1.3",
"doctrine/dbal": "^2.6",
"fideloper/proxy": "~4.0",
"laravel/framework": "5.6.*",
"laravel/tinker": "~1.0",
"tymon/jwt-auth": "1.0.0-rc.2"
},
Again I have the same issue that when I make a request without a token, I get MethodNotAllowedException.
I made some research, It seem that the method that parse the token send a JWTException when it failed to catch a response. JWTException is extends from Exception class and thus not showed to user because it seem laravel only show HttpException.
In the parseToken method JWT.php, if you change the JWTException to DomainException and remove authorization header, It will show the proper error "The token could not be parsed from the request" in the response.
However, I don't know if it is the expected behaviour, and I found myself another solution :
You can set the Accept header to application/json, it will return you a 401 unauthorized error that is more appropriate :
{ "message": "Unauthenticated." }
I will search further to understand where the MethodNotAllowedHttpException come from.
for 2.0.1 is same bug, only @mhlsf comment true
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Hello, I'm having troubles when I'm trying to use the 'auth:api' middleware in my routes. With this configuration, the response to the request is 'MethodNotAllowedHttpException in RouteCollection.php' If I don't use the middleware, it works. Where's the problem? I'm using "tymon/jwt-auth": "1.0.*@dev" This is my jwt.php `<?php
/*
return [
];`
This is my kernel.php
`<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel { /**
@var array */ protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\Cors::class, \App\Http\Middleware\VerifyCsrfToken::class, \Barryvdh\Cors\HandleCors::class, ];
/**
@var array */ protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
];
/**
@var array */ protected $routeMiddleware = [ 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
]; }
This is my api.php
<?phpuse Illuminate\Http\Request;
*/
Route::get('/user', function (Request $request) { return $request->user(); })->middleware('auth:api');
Route::group(['middleware' => 'auth:api'], function(){ Route::post('/authenticate', 'AuthController@authenticate'); }); Route::get('/', 'IndexController@getIndex'); Route::post('/login', 'LoginController@loginAction'); Route::post('/register', 'UserController@register'); Route::post('/uploadFiles', 'UserController@uploadFiles'); `
And finally this is my auth.php `<?php
return [
]; `