Looking to hire Laravel developers? Try LaraJobs

laravel-passport-auth maintained by kamrul-haque

Description
Authentication functionality for API using Laravel Passport
Last update
2022/12/28 20:45 (dev-master)
License
Links
Downloads
175

Comments
comments powered by Disqus

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
});