passport: Invalid token cause 500 error.
I have simple route which is guarded by auth:api and I haven’t any access tokens in database (oauth_access_tokens) saved in database. I am getting 500 error intstead of 401
➜ curl -i http://127.0.01:8000/api/user -H “Authorization: Bearer fakeToken” HTTP/1.0 500 Internal Server Error
If I make good existing access token it’s works.
Looks like it get infinity loop: Fatal error: Maximum function nesting level of ‘256’ reached, aborting!
[Thu Jul 20 15:33:44 2017] PHP 215. call_user_func:{/Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php:58}() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php:58
[Thu Jul 20 15:33:44 2017] PHP 216. Laravel\Passport\PassportServiceProvider->Laravel\Passport\{closure}() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php:58
[Thu Jul 20 15:33:44 2017] PHP 217. Laravel\Passport\Guards\TokenGuard->user() /Users/vaidas/develop/project/vendor/laravel/passport/src/PassportServiceProvider.php:251
[Thu Jul 20 15:33:44 2017] PHP 218. Laravel\Passport\Guards\TokenGuard->authenticateViaBearerToken() /Users/vaidas/develop/project/vendor/laravel/passport/src/Guards/TokenGuard.php:90
[Thu Jul 20 15:33:44 2017] PHP 219. App\Exceptions\Handler->report() /Users/vaidas/develop/project/vendor/laravel/passport/src/Guards/TokenGuard.php:143
[Thu Jul 20 15:33:44 2017] PHP 220. App\Exceptions\Handler->report() /Users/vaidas/develop/project/app/Exceptions/Handler.php:31
[Thu Jul 20 15:33:44 2017] PHP 221. App\Exceptions\Handler->context() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:112
[Thu Jul 20 15:33:44 2017] PHP 222. Illuminate\Support\Facades\Facade::id() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:151
[Thu Jul 20 15:33:44 2017] PHP 223. Illuminate\Support\Facades\Facade::__callStatic() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:151
[Thu Jul 20 15:33:44 2017] PHP 224. Illuminate\Auth\AuthManager->id() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:221
[Thu Jul 20 15:33:44 2017] PHP 225. Illuminate\Auth\AuthManager->__call() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:221
[Thu Jul 20 15:33:44 2017] PHP 226. Illuminate\Auth\RequestGuard->id() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:294
[Thu Jul 20 15:33:44 2017] PHP 227. Illuminate\Auth\RequestGuard->user() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Auth/GuardHelpers.php:70
[Thu Jul 20 15:33:44 2017] PHP 228. call_user_func:{/Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php:58}() /Users/vaidas/develop/project/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php:58
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Fix hanging due to invalid token... https://github.com/laravel/passport/issues/440#issuecomment-328053552 — committed to amcsi/jogging by amcsi 6 years ago
- Use improved solution for reporting OAuthServerException... https://github.com/laravel/passport/issues/440#issuecomment-355499747 — committed to amcsi/jogging by amcsi 6 years ago
You can add OAuthServerException to $dontReport :
I think this error is caused by Xdebug. It’s not an error with this library.
Instead of ignoring all
OAuthServerExceptionexceptions I just remove user from context forOAuthServerException:app\Exceptions\Handler.phpBut IMO right solution should be removing user from logger context, because
Auth::user()depends on some Guards, Providers etc and even these might be coded by developer. Indeed I don’t remember I need to know which user caused the exceptions. I am sure in some cases it might be critical but for me I didn’t use it so far.After a little bit of digging I found out that the issue arises in the Laravel Exception Handler (
framework/src/Illuminate/Foundation/Exceptions/Handler.php), functioncontext()where it reaches forAuth. Quick workaround is to override that function in your ownapp/Exceptions/Handler.php:Just be aware that in this case anywhere else your context (userId and email address of the user making the request) will not be logged when exception is thrown.
same problem here,the workaround did the job. instead of infinite loop i get a 401 “unauthenticated” exception
@terdia you solution didn’t worked for me