Laravel 5.7 Passport oauth - Single client for multiple users - laravel

Is there a way I could use the same OAuth client for all my users instead of using one client per user?

If you use the Password Grant Client you can pass a username and password to the client and it will authenticate your users with only one client.
To protect your routes use the auth middleware and the api guard.
Remember to set the driver for your api guard to passport.
https://laravel.com/docs/5.7/passport#password-grant-tokens
Use this link to help you.

There must be an issue when creating a client via front end.
I ran
php artisan migrate:fresh --seed
composer dump-autoload
php artisan config:clear
Then created a user manually.
next
php artisan passport:client

Related

How to generate only API_KEY and USER_SECRET in with laravel passport

I am developing api using laravel passport. But i have tried using the various grant types, the authorization code, password grants, client credentials but still not getting the desired result i want. Maybe i am not able to understand well. Looking at stripe, after you signup, you get api key and a secret which you use in your application. How do I achieve same result using passport where after user signup, user get API_KEY and USER_SECRET to use in his application.
To generate passport:keys you need to execute:
php artisan passport:keys
More you can read here.
Also, you will need to create client with:
php artisan passport:client
More in docs.

password reset email to any user in users table in laravel

I am new to laravel. How to implement password reset email sending to any of the users in users table.
I think your best resource would be the functionality that comes out of the box with Laravel. Take a look at the Laravel Authentication Documentation.
You can simply run the artisan command to create all authentication scaffolding:
php artisan make:auth
The password reset should be included in that scaffolding.
As stated in the Laravel documentation:
Just run php artisan make:auth and php artisan migrate in a fresh Laravel application. Then, navigate your browser to http://your-app.test/register or any other URL that is assigned to your application. These two commands will take care of scaffolding your entire authentication system!
Maybe something like this:
\App\User::all()->each(function($user){
\Illuminate\Support\Facades\Password::broker()->sendResetLink(['email' => $user->email]);
});
Laravel provide full Authentication mechanism out of the box. You can try with php artisan make:auth. To send the email you need to configure the SMTP setting in laravel configuration.
For more info please learn from the documentation below:
https://laravel.com/docs/5.7/authentication
https://laravel.com/docs/5.7/mail

Using Passport Oauth2 in server access token issue

Hello To All I'm facing problem for using passport Oauth2 Authentication in laravel 5.4, I am working on project where I define two routes
1. For login through API http://localhost:8000/api/login from Which, I got a response as Access Token.
2. Another for get user details http://localhost/api/user and I am getting the user details.
But When I deploy my App to server and try to Hit the above two URL in Postman I am getting the access token but While tried to access the user with the generated access token. It send me error of Unauthenticated.
Do I need to generate passport key in server with php artisan passport:keys
Yes you'll need the encryption keys on the server as well:
php artisan passport:keys
// or with new installations
php artisan passport:install
Also ensure you're using the correct auth guard, auth:api, when accessing the user:
// middleware
Route::group(['middleware' => ['auth:api'])->(...)
// and with the user helper
auth('api')->user()

How to use Laravel passport if default Laravel auth is not being used

I am using laravel 5.4 and not using the default Auth for user authentication with it.
I have created a custom users table and using it with a custom Auth system having all custom middlewares etc.
I have thus not run the command php artisan make:auth or php aritsan migrate in the initial setup.
How i I integrate the project with Laravel/Passport for API authentication ? Also how do I issue tokens with passport if the default auth is not used not even Auth::attempt();

Do I need to run artisan make:auth command to use Auth facade

I'm new to Laravel.
Do we need to run "php artisan make:auth" command to use Auth facade?
I don't need laravel's pre-built views and controllers.
No You don't need to run " php artisan make:auth " to use the Auth facade.
make:auth command just creates views and other stuff so you don't have to create that. It includes login and registration process.
Auth Facade is the facade that gives you the information about authenticated user.
For more detail read the larvel documentation
https://laravel.com/docs/5.4/authentication

Resources