I am working on an API at the moment and have hit a brick wall. I am using Passport with the \'Password\' grant type.
I want to return the user information with the
Two steps.
1. Add a new route in your routes file.
// routes/api.php
Route::post('oauth/token', 'AuthController@auth');
Keep in mind this will change the route for getting the token from /oauth/token
to /api/oauth/token
.
2. Add the controller method.
getContent();
// $tokenInfo will contain the usual Laravel Passort token response.
$tokenInfo = json_decode($token, true);
// Then we just add the user to the response before returning it.
$username = $request->getParsedBody()['username'];
$user = User::whereEmail($username)->first();
$tokenInfo = collect($tokenInfo);
$tokenInfo->put('user', $user);
return $tokenInfo;
}
}