Sending more data with Laravel passport oauth/token
Right,
I answering my own question, in case someone needs to do the same. Maybe is not the best way, but is working.What I did is:
- Create a new route, like /api/login that points to a method (be sure that is Outside of your middleware "auth", once that it's not sending the token in thi call). E.g:
Route::post('/login', 'Auth\LoginController@apiLogin');
in the method, you do a request to the oauth/token and, with the result, you add the fields that you want. test
function apiLogin(Request $request) { $tokenRequest = $request->create('/oauth/token', 'POST', $request->all()); $request->request->add([ "client_id" => 'your_client_id', "client_secret" => 'your_client_secret', "grant_type" => 'password', "code" => '*', ]); $response = Route::dispatch($tokenRequest); $json = (array) json_decode($response->getContent()); $json['new_value'] = '123456'; $response->setContent(json_encode($json)); return $response }
This is working for me. In my case, I also have just one app so, my client_id, client_secret, grant_type and code is added in the server side. The client only need to pass username(or email, depends of what you are using) and password and then it will get the access_token and the other info that I want to send as well. Hope that this helps someone else too.
Cheers, joao