Laravel 5.4 Passport: unsupported_grant_type
You need to install a password
client for Passport. Assuming you've installed and configured Passport, to generate a password client, run:
php artisan passport:client --password
Make sure to use the details from the output of this command in your API requests.
inside form-data in postman use following
grant_type : password
client_id : 2
client_secret : vSFxVqALQHjyotPyGfhrGj3ziudUGsts2ZWiAGms or whatever this is
username: [email protected]
password: mypassword
scope:
You can get client id and secret from oauth_clients table if no data there use following command to create a client
php artisan passport:client --password
use the oauth_clients table particular row, where password client column value is 1
see how i have integrated token generation code with login. I used right format to solve grant issue in laravel 5.8
public function login(Request $request) {
if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
$user = Auth::user();
if(Auth::check()) { // check whether user exist
$req = Request::create('/oauth/token', 'POST',[
'grant_type' => 'password',
'client_id' => 2,
'client_secret' => 'WDv6wrY9Tf9HuixaiQjDWGy7yBqEG1IrmsLucAUI',
'username' => request('email'),
'password' => request('password'),
'scope' => ''
]);
$res = app()->handle($req);
$responseBody = json_decode($res->getContent()); // convert to json object
return response()->json(['success' => $responseBody], $res->getStatusCode());
} else {
return response()->json(['error' => 'Not logged in '], 401);
}
} else {
return response()->json(['error' => 'Authentication failed '], 401);
}
}