azzarip / api-basic-auth
Basic auth system for intraserver api communication
Fund package maintenance!
Azzarip
Requires
- php: ^8.3
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^2.0||^3.0
- pestphp/pest-plugin-arch: ^2.5||^3.0
- pestphp/pest-plugin-laravel: ^2.0||^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2025-08-11 20:31:43 UTC
README
This package enables secure API communication between two Laravel applications using HTTP Basic Authentication.
Install the package on both applications that need to communicate.
In your .env
or config/services.php
, define the following:
-
Inbound Password
Used to authenticate incoming API requests from the other server. -
Outbound Password
Used when this application sends outgoing API requests to the other server. -
Endpoint
The full URL of the other server (e.g.,https://api.example.com
).
Installation
You can install the package via composer:
composer require azzarip/api-basic-auth
In the config/services.php
add the following
'username' => [ 'endpoint' => 'http....' //full url for calls 'inbound_password' => env('INBOUND_PASSWORD'), 'outbound_password' => env('OUTBOUND_PASSWORD'), ]
You can define multiple username
each of them with endpoint and inbound and outbound password.
Usage
Inbound Requests
For the inbound request use the api.auth
middleware, followed by the username as specified in the config file.
Route::get('/api')->middleware('api.auth:username');
This middleware will let all the request with username username
and password inbound_password
, as specified in the config files.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.