Skip to content

Authentication functionality for API using Laravel Passport

License

Notifications You must be signed in to change notification settings

Kamrul-Haque/laravel-passport-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laravel-passport-auth

Latest Stable Version Total Downloads Latest Unstable Version License GitHub Repo stars

Authentication functionality for API using Laravel Passport

Prerequisite

Install and configure Laravel Passpost

Installation

Install the package via composer:

composer require kamrul-haque/laravel-passport-auth

Publish package resources:

php artisan vendor:publish --tag="laravel-passport-auth"

Migrate the necessary database tables:

php artisan migrate

Configuration

Set the required configuration in .env.

// .env

FRONTEND_URL=
FRONTEND_IP=
TOKEN_EXPIRY_DAYS=
TOKEN_REFRESH_EXPIRY_DAYS=

Usage:

Add routes in api.php:

// routes/api.php

include __DIR__ . '/passport.php';

Protect routes:

// routes/api.php

Route::group(['middleware' => 'auth:api'], function () {
  // your routes
});

Register middleware in app\Http\Kernel.php inside $routeMiddleware array if you want to restrict API calls from certain IP address:

// app\Http\Kernel.php

protected $routeMiddleware = [
  // existing middlewares

  'restrict-request-ip' => \App\Http\Middleware\RestrictRequestIP::class,
];

Assign the middleware to routes:

// routes/api.php

Route::group(['middleware' => 'restrict-request-ip'], function () {
  // your routes
});

About

Authentication functionality for API using Laravel Passport

Resources

License

Stars

Watchers

Forks

Packages

No packages published