HTTP Basic Auth Guard is a Laravel & Lumen Package that lets you use
basic
as your driver for authentication guard in your application.
The Guard provides the missing stateless HTTP Basic Authentication possibilities - espacially for Lumen.
- Laravel or Lumen Installation.
Via Composer
$ composer require arubacao/http-basic-auth-guard
Lumen 5.2: Authentication
Laravel 5.2: Authentication
Note: For Laravel you can use HTTP Basic Auth out-of-the-box with the session
driver: Link.
But the session
driver does NOT work for Lumen 5.2, so there is no HTTP Basic Auth out-of-the-box for Lumen 5.2
Open config/app.php
and, to your providers
array at the bottom, add:
Arubacao\BasicAuth\BasicGuardServiceProvider::class
Open bootstrap/app.php
and register the service provider:
$app->register(Arubacao\BasicAuth\BasicGuardServiceProvider::class);
Open your config/auth.php
config file and in place of driver under any of your guards, just add the basic
as your driver and you're all set. Make sure you also set provider
for the guard to communicate with your database.
Note: In Lumen you first have to copy the config file from the directory vendor/laravel/lumen-framework/config/auth.php
, create a config
folder in your root folder and finally paste the copied file there.
// config/auth.php
'guards' => [
'api' => [
'driver' => 'basic',
'provider' => 'users'
],
// ...
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
],
Middleware protecting the route:
Route::get('api/whatever', ['middleware' => 'auth:api', 'uses' => 'NiceController@awesome']);
Middleware protecting the controller:
<?php
namespace App\Http\Controllers;
class NiceController extends Controller
{
public function __construct()
{
$this->middleware('auth:api');
}
}
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
Any issues, feedback, suggestions or questions please use issue tracker here.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT).