Is there a simple way to get the passport client that granted an access token from the auth()->user(). If not get the client from the access token?
Thanks in advance
You can get client id from Laravel Auth object:
$client_id = auth()->user()->Token()->getAttribute('client_id');
Related
I have been using Laravel passport to response Api data, I want to response favorite status by user of product if a user login (token paste in header to validate with passport authentication Middleware). Is there a solution to determine if a user login or not without using Middleware "api" in route Api or separate Api url based user login and non user-login?
I just found out that without middleware we can use Auth::guard('api') to validate the bearer token, so just add authorization header with bearer token and check user in controller using Auth::guard('api')
I do to make a JWT auth with Laravel and the Tymondesign jwt-auth, at login I need to make token and a refresh token but I found only how to make token. Someone can help me?
Simply do $newToke = auth()->refresh()
Or
$newToken = Auth::guard()->refresh()
Check here for more details
https://jwt-auth.readthedocs.io/en/develop/auth-guard/
Helo,
I would like to know how get token by user with laravel passeport ?
I don't want a user to access another user's resource.
I would like to verify that the user's token in the request corresponds to the user's token.
i get the request token with:
$token = $request->bearerToken();
i don't know how to get user token.
Thank you
If you've set up correctly then passport will keep track of the tokens of each user in each device. However, if you want to retrieve the token of the authenticated user simply use Auth::user()->token();
I have created a Laravel 5.4 App, which is a REST based API for serving out data about our inventory to customers.
I have implemented Passport based Authentication, and My customers create a 'Personal Access Tokens' and use that in their client requests. All of this is working fine.
I now need to meter the usage of the API to figure out which user, and which token (by Name) is making the request.
I am able to get the User by using $request->session();, but how do I get the name of the Token that is making the request?
Laravel passport searches for valid tokens in 2 locations:
the bearer token
a cookie
When boiled down, you could use this method to find the token you seek:
$token = $request->bearerToken() ?? $request->cookie(Passport::cookie());
I'm using laravel as my backend.
Once the user has logged into my app, all I have is just a token without any information regards the username or any other user details.
Once I retrive the JWT Token and store it in my frontend (angular2), how I can get the user details?
For the record, i'm using the following laravel library:
https://github.com/tymondesigns/jwt-auth
To get the user information
First get the token from JWTAuth like this:
$token = JWTAuth::getToken();
Then get the user from the token as follows:
$user = JWTAuth::toUser($token);
you can get user information like this way :
$user = JWTAuth::toUser(your_token_here);
I have tested just
$user = JWTAuth::toUser();
Without any parameter and it works as well
I am using Laravel 7.3 with tymon/jwt-auth 1.0
JWTAuth::parseToken()->authenticate();