laravel-passport

Get authenticated user with Laravel Passport and grant password

久未见 提交于 2019-11-30 11:28:24
I did an API REST with Laravel and now I'm trying to consume it. The thing is I need to authenticate users in the API and I am using the Password Grant method. I can authenticate users correctly and I can get an access token but from then, I don't see a way to retrieve the authenticated user with the access token in my consuming application. I tried in the API with a route like this: Route::get('/user', function(Request $request) { $user = $request->user(); // Even with $user = Auth::user(); return $user; }); No dice. I am reading Passport code but I can't figure it out. My guess is that I

How to logout a user from API using laravel Passport

社会主义新天地 提交于 2019-11-30 10:31:01
问题 I'm currently using 2 projects. 1 front end (with laravel backend to communicate with API) and another laravel project (the API). Now I use Laravel Passport to authenticate users and to make sure every API call is an authorized call. Now when I want to log out my user, I send a post request to my API (with Bearer token) and try to log him out of the API (and clear session, cookies,...) Then on the client I also refresh my session so the token is no longer known. Now when I go back to the

Custom Laravel Passport BearerTokenResponse

大兔子大兔子 提交于 2019-11-30 10:30:49
Currently I have a Laravel installation using Laravel Passport (which uses league/oauth2-server for the server implementation). I would like to return the user id when a oauth2 token is granted, so I can use it to identify the authenticated user in my EmberJS app. The suggested method to do this is: Create my own class: use League\OAuth2\Server\ResponseTypes\BearerTokenResponse; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; class UserIdBearerTokenResponse extends BearerTokenResponse { protected function getExtraParams(AccessTokenEntityInterface $accessToken) { return [ 'user_id

Laravel Passport Get Client ID By Access Token

喜你入骨 提交于 2019-11-30 02:36:54
问题 I'm writing a tiny sms gateway to be consumed by a couple of projects, I implemented laravel passport authentication (client credentials grant token) Then I've added CheckClientCredentials to api middleware group: protected $middlewareGroups = [ 'web' => [ ... ], 'api' => [ 'throttle:60,1', 'bindings', \Laravel\Passport\Http\Middleware\CheckClientCredentials::class ], ]; The logic is working fine, now in my controller I need to get client associated with a valid token. routes.php Route::post(

Get authenticated user with Laravel Passport and grant password

被刻印的时光 ゝ 提交于 2019-11-29 17:03:52
问题 I did an API REST with Laravel and now I'm trying to consume it. The thing is I need to authenticate users in the API and I am using the Password Grant method. I can authenticate users correctly and I can get an access token but from then, I don't see a way to retrieve the authenticated user with the access token in my consuming application. I tried in the API with a route like this: Route::get('/user', function(Request $request) { $user = $request->user(); // Even with $user = Auth::user();

Customising token response Laravel Passport

a 夏天 提交于 2019-11-29 16:57:26
问题 I am working on an API at the moment and have hit a brick wall. I am using Passport with the 'Password' grant type. I want to return the user information with the access tokens, however, I am not sure how to. Which class could I implement, edit or extend to get this?. I would like this to be returned: { "token_type": "Bearer", "expires_in": 31536000, "access_token": "lalalalalal", "refresh_token": "lalalallala", "user": { "username": "a username", "user_type": "admin" } } Thanks in advance.

composer unable to install laravel/passport

穿精又带淫゛_ 提交于 2019-11-29 13:19:17
I have created a new project with laravel new blogposts using "Laravel Installer 2.0.1" globally installed on my ubuntu 18. When i trying to install passport using composer require laravel/passport following errors are their Using version ^6.0 for laravel/passport ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - Conclusion: don't install laravel/passport v6.0.6 - Conclusion: don't install laravel/passport v6.0.5 - Conclusion

Laravel 5.4 passport axios always returns Unauthenticated

爷,独闯天下 提交于 2019-11-29 07:55:26
I've followed the guide here: https://laravel.com/docs/5.4/passport#consuming-your-api-with-javascript Using axios: ... mounted: function() { axios.get('/api/user') .then(function (response) { console.log(response) }) .catch(function (response) { console.error(response); }); }, But the response is always unauthenticated, I check to see if a laravel_token cookie is present and it is: I'm running on apache2 ( docker ) ---- Update -- Upon debugging, its actually the xsrf token thats failing in this method in TokenGuard : /** * Authenticate the incoming request via the token cookie. * * @param

How to use Laravel Passport with Password Grant Tokens?

大憨熊 提交于 2019-11-28 07:37:31
I just read the https://laravel.com/docs/5.6/passport documentation and I have some doubts that hopefully someone could help me with: First, some context, I want to use Passport as a way to provide Oauth authentication for my mobile app (first-party app). When I use php artisan passport:client --password I get back a Client ID and a Client Secret. Does this value have to be fixed on my app? for example storing them hardcoded or as a "settings" file? If the values shouldn't be stored then how should it work? To register a user to my app I use: $user->createToken('The-App')->accessToken; I get

How to use Laravel Passport with a custom username column

瘦欲@ 提交于 2019-11-28 06:18:16
Now I'm using something like that for authenticating the user on my base site: if (Auth::attempt($request->only(['id', 'password']))) { // } How can I modify this code for using custom column as username? https://laravel.com/docs/5.3/passport#password-grant-tokens You can use findForPassport method in your user model. This method take username as argument, and return user model For example: class User extends Authenticatable { use HasApiTokens, Notifiable; // ... some code public function findForPassport($username) { return $this->where('id', $username)->first(); } } A bit too late to answer,