Laravel

Laravel 5.5 passport authentication

Laravel 5.5 passport authentication

We are going to create a authentication system in laravel api using passport.

Step 1 : Install Laravel

Step 2 : Install Laravel passport package

It will help us to provide Oauth2 implementation

If you are using greater then laravel 5.5

else

install passport

Step 3 : Run Migration

While installing laravel passport package it will create some migrations to create tables for oauth clients and tokens

Run Migrations

Step 4 : Generate Passport Encryption key and Clients

This command is used to create encryption keys that needs to create access tokens.

Generate Keys

Step 5 : Add HasApiTokens to User.php model



Step 6 : Call Passport Routes

Call Passport::routes method to AuthServiceProvider.php file under boot function. Which will help us to create & revoke tokens, clients and personal access tokens

Step 7 : Set Passport gaurd to config/auth.php file

Step 8 : Create API Routes

Create your routes in api.php file

Step 9 : Create Controller

In my case I have create a controller called AuthController.php inside a Api folder

Thats it, Now you need to validate your api calls

Step 10 : Outputs

Login Samples :

Error

Login Error

Success

Login Success

Get User Sample

Getting User

Logout

Logout

Thanks,

Hope it will help for some else.