deepu07's avatar
Level 11

user_id in Passport oauth_clients table

Hi Mates,

I wanna save user_id in passport oauth_clients table for that I'm running this command

php artisan passport:client --client --name=TestingUser --user_id=56

it is creating a token but somehow user_id is null. any thoughts why it is saving user_id in table. TIA

0 likes
7 replies
classicalguss's avatar

@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.

So someone help me understand.

1 like
deepu07's avatar
Level 11

@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?

bobbybouwmann's avatar

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.

deepu07's avatar
Level 11

@bobbybouwmann what will be the grant_type for the above client to generate OAuth token? can I use grant_type: client_credentials?

bobbybouwmann's avatar

Yeah, with the client_id and client_secret you can use the client_credentials type to generate an access token.

deepu07's avatar
Level 11

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?

Please or to participate in this conversation.