2017 © Pedro Peláez
 

library shield

A HTTP basic auth middleware for Laravel

image

vinkla/shield

A HTTP basic auth middleware for Laravel

  • Thursday, April 26, 2018
  • by vinkla
  • Repository
  • 4 Watchers
  • 146 Stars
  • 12,568 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 17 Versions
  • 58 % Grown

The README.md

Laravel Shield

This package used to be an HTTP basic auth middleware for Laravel. However, it is now deprecated as I no longer use it personally. Laravel already has built-in basic auth support for their web guard., (*1)

If you need simpler basic auth for your API, instead of depending on a third-party library, you can add it yourself. Please follow the guide below., (*2)

To begin, update your .env file with the following details:, (*3)

BASIC_AUTH_USER=your-username
BASIC_AUTH_PASSWORD=your-password

Modify your config/auth.php file as follows:, (*4)

'basic' => [
    'user' => env('BASIC_AUTH_USER'),
    'password' => env('BASIC_AUTH_PASSWORD'),
],

Finally, create a middleware that resembles the code below:, (*5)

<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;

class BasicAuthMiddleware
{
    public function handle(Request $request, Closure $next): Response
    {
        $user = config('auth.basic.user');
        $password = config('auth.basic.password');

        if (
            $request->getUser() !== $user ||
            $request->getPassword() !== $password
        ) {
            throw new UnauthorizedHttpException('Basic');
        }

        return $next($request);
    }
}

That's it! You can now use the middleware in your routes., (*6)

use App\Http\Middleware\BasicAuthMiddleware;
use App\Models\User;

Route::get('api/users', function () {
    return User::all();
})->middleware(BasicAuthMiddleware::class);

The Versions

26/04 2018

dev-master

9999999-dev

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

01/03 2018

2.4.1

2.4.1.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

08/02 2018

2.4.0

2.4.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

02/09 2017

2.3.0

2.3.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

07/08 2017

2.2.0

2.2.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

31/01 2017

2.1.1

2.1.1.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

01/01 2017

2.1.0

2.1.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

17/11 2016

2.0.0

2.0.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

11/07 2016

1.2.0

1.2.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

05/05 2016

1.1.0

1.1.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

01/04 2016

1.0.0

1.0.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

23/02 2016

0.3.2

0.3.2.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

17/02 2016

0.3.1

0.3.1.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

09/02 2016

0.3.0

0.3.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

05/02 2016

0.2.1

0.2.1.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

31/01 2016

0.2.0

0.2.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield

27/01 2016

0.1.0

0.1.0.0

A HTTP basic auth middleware for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware auth http basic shield