@bobbybouwmann I know this is 4 years old. But I'm struggling to grasph. How are the other grant types associated with a specific users? All of the grants as far as I know are NOT associated to a SPECIFIC user. Any user can use the Authorization Grant, any user can use the Password grant, and so on.
In fact for me, the only use case for a user_id is actually the client credentials grant.
@bobbybouwmann thanks for the response. in my project I have modules like these users and vendors. Relationship: one vendor hasMany Users. here I wanna create a client token for every vendor. which way is the better one to achieve this scenario?
In this case, you need a client credential token. The above command I gave you will generate that token for you.
You can also create them using code by doing something like this
use Laravel\Passport\ClientRepository;
public function store(Request $request, ClientRepository $clientRepository)
{
// Register your user
// Create the passport client
$client = $clientRepository->createPasswordGrantClient($user->id, 'TestingUser', 'https://example.com');
}
This client will have a client_id and a client_secret. You can then use that to retrieve an access token.
Thanks @bobbybouwmann , I'm able to create an access token. so if I want to pull user details from the access token I'm always getting null I tried like Auth::guard('api')->user(); is there any helper that I can pull user data from access token?