{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/passport/issues/634","repository_url":"https://api.github.com/repos/laravel/passport","labels_url":"https://api.github.com/repos/laravel/passport/issues/634/labels{/name}","comments_url":"https://api.github.com/repos/laravel/passport/issues/634/comments","events_url":"https://api.github.com/repos/laravel/passport/issues/634/events","html_url":"https://github.com/laravel/passport/pull/634","id":296396467,"number":634,"title":"Fixes infinite recursion on OAuthServerException","user":{"login":"iget-esoares","id":9450290,"avatar_url":"https://avatars2.githubusercontent.com/u/9450290?v=4","gravatar_id":"","url":"https://api.github.com/users/iget-esoares","html_url":"https://github.com/iget-esoares","followers_url":"https://api.github.com/users/iget-esoares/followers","following_url":"https://api.github.com/users/iget-esoares/following{/other_user}","gists_url":"https://api.github.com/users/iget-esoares/gists{/gist_id}","starred_url":"https://api.github.com/users/iget-esoares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iget-esoares/subscriptions","organizations_url":"https://api.github.com/users/iget-esoares/orgs","repos_url":"https://api.github.com/users/iget-esoares/repos","events_url":"https://api.github.com/users/iget-esoares/events{/privacy}","received_events_url":"https://api.github.com/users/iget-esoares/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-02-12T14:37:28Z","updated_at":"2018-02-13T17:50:44Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/laravel/passport/pulls/634","html_url":"https://github.com/laravel/passport/pull/634","diff_url":"https://github.com/laravel/passport/pull/634.diff","patch_url":"https://github.com/laravel/passport/pull/634.patch"},"body":"Hi there,\r\n\r\n## The issue\r\n\r\nAs explained on issue #632, when an `OAuthServerException` occurs, an *infinite recursion* is triggered, causing the script to fail with PHP's `maximum execution time exceeded` error.\r\n\r\n## The reason\r\n\r\nThe reason is that when failed, Laravel Passport [triggers the `ExceptionHandler->report()`](https://github.com/laravel/passport/blob/a04b9193054a8a7c50c26ff4f0519d3f7b5f5a30/src/Guards/TokenGuard.php#L140-L142), that will try to report the error giving the context, [that by the way calls the `Auth::user()` method](https://github.com/laravel/framework/blob/ac2c64ec61192771b106215296e6322a09221974/src/Illuminate/Foundation/Exceptions/Handler.php#L152) again, causing the recursion since `TokenGuard` doesn't keep track of failed authentication, causing multiple unnecessary (and expensive too) calls to the `authenticateViaBearerToken()` guard method.\r\n\r\n## The proposed fix\r\n\r\nMy proposed fix is to [add an `failed` static](https://github.com/iget-master/passport/blob/e1b99f6c6d0ea74450f11b65d06a55b05b0e1f3b/src/Guards/TokenGuard.php#L57-L62) (must be static to work) boolean flag to the `TokenGuard`, and [raise it when the `OAuthServerException` occurs](https://github.com/iget-master/passport/blob/e1b99f6c6d0ea74450f11b65d06a55b05b0e1f3b/src/Guards/TokenGuard.php#L154). \r\n\r\nThis allows that our `user()` method [checks if a failure occured](https://github.com/iget-master/passport/blob/e1b99f6c6d0ea74450f11b65d06a55b05b0e1f3b/src/Guards/TokenGuard.php#L95-L100) and skip the call to the `authenticateViaBearerToken()` since we already know that the authentication failed previously, and anything changed, so the result will be always the same.\r\n\r\nI really expect that this could be fixed, since our application is broken due to this.\r\n\r\n## Breaking impacts\r\n\r\nThis should not have breaking impacts since it just optimizes an failing process."},"comment":{"url":"https://api.github.com/repos/laravel/passport/issues/comments/365347709","html_url":"https://github.com/laravel/passport/pull/634#issuecomment-365347709","issue_url":"https://api.github.com/repos/laravel/passport/issues/634","id":365347709,"user":{"login":"iget-master","id":9434959,"avatar_url":"https://avatars2.githubusercontent.com/u/9434959?v=4","gravatar_id":"","url":"https://api.github.com/users/iget-master","html_url":"https://github.com/iget-master","followers_url":"https://api.github.com/users/iget-master/followers","following_url":"https://api.github.com/users/iget-master/following{/other_user}","gists_url":"https://api.github.com/users/iget-master/gists{/gist_id}","starred_url":"https://api.github.com/users/iget-master/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iget-master/subscriptions","organizations_url":"https://api.github.com/users/iget-master/orgs","repos_url":"https://api.github.com/users/iget-master/repos","events_url":"https://api.github.com/users/iget-master/events{/privacy}","received_events_url":"https://api.github.com/users/iget-master/received_events","type":"User","site_admin":false},"created_at":"2018-02-13T17:50:44Z","updated_at":"2018-02-13T17:50:44Z","author_association":"NONE","body":"@taylorotwell I'm trying to create a repository to reproduce the problem, also trying to explain the reason why static is necessary."}}
{"actor":{"display_login":"iget-master"}}