Skip to content

ravihansa/laravel-passport-auth

Repository files navigation

Laravel Passport Auth App

Laravel Passport?

Laravel already makes it easy to perform authentication via traditional login forms, but what about APIs? APIs typically use tokens to authenticate users and do not maintain session state between requests. Laravel makes API authentication a breeze using Laravel Passport, which provides a full OAuth2 server implementation for your Laravel application in a matter of minutes. Passport is built on top of the League OAuth2 server that is maintained by Andy Millington and Simon Hamp.  

How to setup this application?

  1. After cloning the application, you need to install it's dependencies,
  • cd laravel-passport-auth
  • composer install    
  1. Then rename .env.example as .env and provide correct db details.    
  2. After Generate the application key using following command,
  • php artisan key:generate    
  1. Migrate the application using following command,
  • php artisan migrate    
  1. Create the encryption keys needed to generate secure access tokens,
  • php artisan passport:install    
  1. Finally run the application using following command,
  • php artisan serve  

How to create this application?

  1. Create laravel project,
  • composer create-project --prefer-dist laravel/laravel laravel-passport-auth "5.8.*"    
  1. Then install laravel passport package,
  • composer require laravel/passport    
  1. Create db connection and run migrations,
  • php artisan migrate    
  1. Generate keys,
  • php artisan passport:install    
  1. Add the Laravel\Passport\HasApiTokens trait to App\User model (Use my code).    
  2. Next, call the Passport::routes method within the boot method of the Providers/AuthServiceProvider (Use my code).    
  3. After, in config/auth.php configuration file, set the driver option of the api authentication guard to passport (Use my code).    
  4. Create UserController (Use my code),
  • php artisan make:controller /API/UserController    
  1. Create api routes (Use my code).    
  2. Finally run the following command and check the application using Postman tool.
  • php artisan serve
       

How to check application using Postman tool?

Bellow i mentioned my postman requests...    

{ "name":"Name", "email":"email@gmail.com", "password":"12345678" }

--



You can change above api as you wish and according to the requirements.

About

Laravel passport authentication rest api

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published