laravel-passport

How to use Laravel passport for Auth and Lumen as api

一曲冷凌霜 提交于 2019-12-07 20:09:24
问题 I am researching for develop an API consumed application using laravel, laravel passport , lumen and AngularJS I have 3 domains as follows auth.dev - Laravel 5.4 + Passport oAuth server ( as a auth server ) api.dev - Lumen ( as a API seaver ) app.dev - php + angularjs ( single page app ) I can not properly configure those 3 together. I have setup auth.dev and it will successfully generate Tokens and I can use them from app.dev . But my requirement is use 3 separate instance for API, Auth and

Custom Laravel Passport Check

♀尐吖头ヾ 提交于 2019-12-07 18:32:37
问题 Is There anyway to add or pass 1 more variable to findForPassport ? In default laravel passport login, i only can pass 2 variable (username, password),but I want to pass 1 more variable and check in findForPassport if that user is belong other table or not . 回答1: I hope this answer can help to other. If you want to add variable and pass this variable to findPassport function in User Authenticate model , you need to update 3 class in passport : - UserRepositoryInterface in vendor\league\oauth2

Passport Laravel Rest API Auth With Normal Design

落爺英雄遲暮 提交于 2019-12-07 11:48:00
问题 I have Completely assigned the Passport REST API and i get token and tested on PostMan and it retrieve the data with this Auth this is normal js html with laravel blade view (NOT VUE.JS) <script> $.ajax({ method: 'POST', dataType: 'json', url: "**********/api/User/GetPost", headers: { 'Authorization':'Bearer Tokenblablabla', 'Content-Type':'application/json' }, data: null, success: function(data){ console.log('succes: '+data); } }); this is the controller function public function GetPosts

laravel passport returns unauthenticated

允我心安 提交于 2019-12-07 08:21:47
问题 I'm creating an api that uses Passport to manage authentication. I've set up Passport with the docs. The problem I am unable to login. I keep getting a JSON response saying unauthenticated Database In my database I have the following data: users id name email password timestamps 1 admin admin@admin.com $2y$10$mUu5KZdQhJ6qeyCeXsr9De0J9e8rgClILbhsGmnPpStwr1rhaa2je 2016-12-09 09:47:39 2016-12-09 09:47:39` ` oauth_clients id, user_id, name, secret, redirect, personal_access_client, password

Laravel Passport: Create access token manually

走远了吗. 提交于 2019-12-07 05:57:55
问题 I'm trying to find a way to create an access token manually in Laravel 5.5 using Passport and can't seem to figure it out. I have 2 applications, one that holds the frontend and one api. The user receives an invitation via mail, and when he accesses the link, i wish to create the auth token and send it back in the response. Any ideas on how to do this ? Thanks. 回答1: Solved it myself. It seems that the HasApiTokens trait that you put on the users model has a method to create a token $user-

Sending more data with Laravel passport oauth/token

落爺英雄遲暮 提交于 2019-12-07 03:13:22
问题 So, I'm using Laravel+Passport and so far is working fine. But, I would like to made a small change to the passport code(well, not in the vendor folder, I hope), once that I would request the User to change it's password in case that he is doing the first login. So, what I would need is two things (I believe): 1 - How can I add one more info to the oauth/token response? Together with the access_token, I would like to add one column from the DB that is needsNewPassword=true/false. 2 - In case

How to edit laravel passport token's expires_at field

一曲冷凌霜 提交于 2019-12-06 22:05:31
I am trying to edit expires_at field of my token with a middleware like bellow namespace App\Http\Middleware; use Carbon\Carbon; use Closure; use Auth; class Refresh { /** * @param $request * @param Closure $next * @return mixed */ public function handle($request, Closure $next) { $token = Auth::user()->token(); $expiresDate = $token->expires_at; $currentDate = Carbon::now(); $diff = date_diff_in_minutes($currentDate, $expiresDate); $baseExpire = site_config('token_expires_minutes'); if ($diff > 0 && $diff < $baseExpire) { $token->update([ 'expires_at' => (new Carbon($expiresDate))->addMinutes

Laravel Passport - Guest Token

我的梦境 提交于 2019-12-06 16:47:17
Let's assume there is an application with 10 dynamic pages (probably forms) out of which, 8 pages are restricted (requires user to login in application) and 2 pages are available for anonymous users. My front end application is in Angular 2 and back-end API is developed in Laravel 5.4. I'm more fascinated towards JWT tokens and found that, laravel has in-built support through passport. Questions: I can easily use password grant tokens for those 8 restricted page. But how do I give guest token to my Angular app for accessing those 2 pages How can I restrict guest user for accessing API features

Authorization Policies/Gates for Laravel 5.3 web app consuming own API w/ Passport

Deadly 提交于 2019-12-06 15:28:36
Using Laravel 5.3 I've set up a web app that consumes its own API. Authentication successfully handled by Passport. Web app uses auth middleware in routes and Model Policies for authorization. API routing uses default 'auth:api' token guard to control access. I would like to use the same Policies in app/Policies for API authorization as well as the web auth, but I don't understand how. Calls such as $this->authorize('view', $model) do not work. I guess I need to pass the user from Auth::guard('api')->user() to the Policies somehow? Any help would be appreciated! Update: Got it working. Seems

Custom Laravel Passport Check

只谈情不闲聊 提交于 2019-12-06 04:42:17
Is There anyway to add or pass 1 more variable to findForPassport ? In default laravel passport login, i only can pass 2 variable (username, password),but I want to pass 1 more variable and check in findForPassport if that user is belong other table or not . Seakleng Say I hope this answer can help to other. If you want to add variable and pass this variable to findPassport function in User Authenticate model , you need to update 3 class in passport : - UserRepositoryInterface in vendor\league\oauth2-server\src\Repositories\UserRepositoryInterface - PasswordGrant in vendor\league\oauth2-server