samedi 24 février 2018

Laravel api authentication - how do I get User by api_token

I have some react components that will POST to my laravel API to update some 'from -> to' time intervals.

I have added a unique 'api_token' column to the users table, and I want to retrieve the user from this token.

In a controller I can validate a token - the $apiUserValis is true or false depeding on whether or not a row exists with a matching api_token value:

$apiToken = "Y2uibY5MIV";//correct token
$apiCredentials = ['api_token' => $apiToken];
$apiUserValid = \Auth::guard('api')->validate($apiCredentials);

However, I want to get the userId of the user with that token.

The SessionGuard has some methods that look relevant - such as login() but these are not present in the TokenGuard.

I am currently simulating this in a controller rather than dealing with a http request object - this could be part of my problem.

How do I get the user id of the person making the POST?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2CHbK1N
via IFTTT

Aucun commentaire:

Enregistrer un commentaire