Skip to content

explore-laravel/http-basic-auth-guard

 
 

Repository files navigation

HTTP Basic Auth Guard

Latest Version on Packagist Software License Total Downloads

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.

Requirements

  • Laravel or Lumen Installation.

Install

Via Composer

$ composer require arubacao/http-basic-auth-guard

Read & Follow Documentation

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

Add the Service Provider

Laravel

Open config/app.php and, to your providers array at the bottom, add:

Arubacao\BasicAuth\BasicGuardServiceProvider::class

Lumen

Open bootstrap/app.php and register the service provider:

$app->register(Arubacao\BasicAuth\BasicGuardServiceProvider::class);

Usage

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.

Setup Guard Driver

// config/auth.php
'guards' => [
    'api' => [
        'driver' => 'basic',
        'provider' => 'users'
    ],

    // ...
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model'  => App\User::class,
    ],
],

Middleware Usage

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

Change log

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Any issues, feedback, suggestions or questions please use issue tracker here.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT).

About

HTTP Basic Auth Guard for Laravel and Lumen Frameworks.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%