kamrul-haque / laravel-passport-auth
Authentication functionality for API using Laravel Passport
v1.0.0
2022-12-28 19:31 UTC
Requires
- laravel/framework: ^7.0|^8.0|^9.0
- laravel/passport: ^10.4
This package is auto-updated.
Last update: 2025-03-29 01:14:38 UTC
README
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
});