{"action":"created","issue":{"url":"https://api.github.com/repos/laravelbrasil/forum/issues/37","repository_url":"https://api.github.com/repos/laravelbrasil/forum","labels_url":"https://api.github.com/repos/laravelbrasil/forum/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/laravelbrasil/forum/issues/37/comments","events_url":"https://api.github.com/repos/laravelbrasil/forum/issues/37/events","html_url":"https://github.com/laravelbrasil/forum/issues/37","id":214399135,"number":37,"title":"Postgres lança exceção quando usa token client_credentials em rota protegida com auth:api","user":{"login":"danteldev","id":24196728,"avatar_url":"https://avatars0.githubusercontent.com/u/24196728?v=3","gravatar_id":"","url":"https://api.github.com/users/danteldev","html_url":"https://github.com/danteldev","followers_url":"https://api.github.com/users/danteldev/followers","following_url":"https://api.github.com/users/danteldev/following{/other_user}","gists_url":"https://api.github.com/users/danteldev/gists{/gist_id}","starred_url":"https://api.github.com/users/danteldev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danteldev/subscriptions","organizations_url":"https://api.github.com/users/danteldev/orgs","repos_url":"https://api.github.com/users/danteldev/repos","events_url":"https://api.github.com/users/danteldev/events{/privacy}","received_events_url":"https://api.github.com/users/danteldev/received_events","type":"User","site_admin":false},"labels":[{"id":552011418,"url":"https://api.github.com/repos/laravelbrasil/forum/labels/auth","name":"auth","color":"1565c0","default":false},{"id":550851904,"url":"https://api.github.com/repos/laravelbrasil/forum/labels/passport","name":"passport","color":"283593","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-03-15T14:05:07Z","updated_at":"2017-03-17T20:04:35Z","closed_at":"2017-03-16T11:39:14Z","body":"Usando o laravel passport quando eu tento acessar uma rota protegida com o auth:api middleware usando um token gerado com grant type cliente_credentials, ao invés de receber a resposta `{\"error\":\"Unauthenticated.\"}` Eu recebo a exceção listada abaixo.\r\nEntão quando TokenGuard tenta receber um User através do EloquentUserProvider, internamente ele envia uma string vazia como parametro (pois não existe usuário no token gerado via client_credentials) e o postgres lança exceção pois não faz cast automático de '' para int.\r\n\r\n> QueryException in Connection.php line 647:\r\n> SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: \"\" (SQL: select * from \"users\" where \"users\".\"id\" = limit 1)\r\n> in Connection.php line 647\r\n> at Connection->runQueryCallback('select * from \"users\" where \"users\".\"id\" = ? limit 1', array(''), object(Closure)) in Connection.php line 607\r\n> at Connection->run('select * from \"users\" where \"users\".\"id\" = ? limit 1', array(''), object(Closure)) in Connection.php line 326\r\n> at Connection->select('select * from \"users\" where \"users\".\"id\" = ? limit 1', array(''), true) in Builder.php line 1718\r\n> at Builder->runSelect() in Builder.php line 1703\r\n> at Builder->get(array('*')) in Builder.php line 493\r\n> at Builder->getModels(array('*')) in Builder.php line 477\r\n> at Builder->get(array('*')) in Builder.php line 409\r\n> at Builder->first(array('*')) in Builder.php line 284\r\n> at Builder->find('') in EloquentUserProvider.php line 47\r\n> at EloquentUserProvider->retrieveById('') in TokenGuard.php line 116\r\n> at TokenGuard->authenticateViaBearerToken(object(Request)) in TokenGuard.php line 90\r\n> at TokenGuard->user(object(Request)) in PassportServiceProvider.php line 251\r\n> at PassportServiceProvider->Laravel\\Passport\\{closure}(object(Request))\r\n> at call_user_func(object(Closure), object(Request)) in RequestGuard.php line 54\r\n> at RequestGuard->user() in GuardHelpers.php line 49\r\n> at RequestGuard->check() in Authenticate.php line 61\r\n> at Authenticate->authenticate(array('api')) in Authenticate.php line 41\r\n> at Authenticate->handle(object(Request), object(Closure), 'api') in Pipeline.php line 148\r\n> at Pipeline->Illuminate\\Pipeline\\{closure}(object(Request)) in Pipeline.php line 53\r\n> at Pipeline->Illuminate\\Routing\\{closure}(object(Request)) in ThrottleRequests.php line 49\r\n> at ThrottleRequests->handle(object(Request), object(Closure), '60', '1') in Pipeline.php line 148\r\n> at Pipeline->Illuminate\\Pipeline\\{closure}(object(Request)) in Pipeline.php line 53\r\n> at Pipeline->Illuminate\\Routing\\{closure}(object(Request)) in Pipeline.php line 102\r\n> at Pipeline->then(object(Closure)) in Router.php line 561\r\n> at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520\r\n> at Router->dispatchToRoute(object(Request)) in Router.php line 498\r\n> at Router->dispatch(object(Request)) in Kernel.php line 174\r\n> at Kernel->Illuminate\\Foundation\\Http\\{closure}(object(Request)) in Pipeline.php line 30\r\n> at Pipeline->Illuminate\\Routing\\{closure}(object(Request)) in TransformsRequest.php line 30\r\n> at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148\r\n> at Pipeline->Illuminate\\Pipeline\\{closure}(object(Request)) in Pipeline.php line 53\r\n> at Pipeline->Illuminate\\Routing\\{closure}(object(Request)) in TransformsRequest.php line 30\r\n> at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148\r\n> at Pipeline->Illuminate\\Pipeline\\{closure}(object(Request)) in Pipeline.php line 53\r\n> at Pipeline->Illuminate\\Routing\\{closure}(object(Request)) in ValidatePostSize.php line 27\r\n> at ValidatePostSize->handle(object(Request), object(Closure)) in Pipeline.php line 148\r\n> at Pipeline->Illuminate\\Pipeline\\{closure}(object(Request)) in Pipeline.php line 53\r\n> at Pipeline->Illuminate\\Routing\\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46\r\n> at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148\r\n> at Pipeline->Illuminate\\Pipeline\\{closure}(object(Request)) in Pipeline.php line 53\r\n> at Pipeline->Illuminate\\Routing\\{closure}(object(Request)) in Pipeline.php line 102\r\n> at Pipeline->then(object(Closure)) in Kernel.php line 149\r\n> at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116\r\n> at Kernel->handle(object(Request)) in index.php line 53\r\n> at require_once('/home/dantel/Projects/api-cotacoesecompras/public/index.php') in server.php line 21\r\n\r\nEloquentUserProvider implementa a função retrieveById desta forma:\r\n```\r\npublic function retrieveById($identifier)\r\n    {\r\n        return $this->createModel()->newQuery()->find($identifier);\r\n    }\r\n```\r\n\r\nO que basicamente é: \r\n```\r\n$model = new \\App\\User(); \r\n$model->newQuery()->find('');\r\n```\r\n\r\nO que funciona normal em sqlite (não testei outro banco de dados), mas lança exceção no postgres.\r\nTem alguma forma  de corrigir isto sem ser necessário alterar o código dentro do próprio Laravel/Passport?"},"comment":{"url":"https://api.github.com/repos/laravelbrasil/forum/issues/comments/287457529","html_url":"https://github.com/laravelbrasil/forum/issues/37#issuecomment-287457529","issue_url":"https://api.github.com/repos/laravelbrasil/forum/issues/37","id":287457529,"user":{"login":"JuaumCruz","id":25864506,"avatar_url":"https://avatars1.githubusercontent.com/u/25864506?v=3","gravatar_id":"","url":"https://api.github.com/users/JuaumCruz","html_url":"https://github.com/JuaumCruz","followers_url":"https://api.github.com/users/JuaumCruz/followers","following_url":"https://api.github.com/users/JuaumCruz/following{/other_user}","gists_url":"https://api.github.com/users/JuaumCruz/gists{/gist_id}","starred_url":"https://api.github.com/users/JuaumCruz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuaumCruz/subscriptions","organizations_url":"https://api.github.com/users/JuaumCruz/orgs","repos_url":"https://api.github.com/users/JuaumCruz/repos","events_url":"https://api.github.com/users/JuaumCruz/events{/privacy}","received_events_url":"https://api.github.com/users/JuaumCruz/received_events","type":"User","site_admin":false},"created_at":"2017-03-17T20:04:35Z","updated_at":"2017-03-17T20:04:35Z","body":"Não que eu usaria, mas o postgres aceita string vazia em campo id varchar sim. "}}
{"actor":{"display_login":"JuaumCruz"}}