2017 © Pedro Peláez
 

library l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

image

olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  • Thursday, June 7, 2018
  • by olssonm
  • Repository
  • 2 Watchers
  • 81 Stars
  • 53,247 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 2 Open issues
  • 21 Versions
  • 20 % Grown

The README.md

Laravel Very Basic Auth

Latest Version on Packagist ![Total downloads][ico-downloads] ![Software License][ico-license] [Build Status][link-build], (*1)

very-basic-auth, (*2)

Documentation available in:, (*3)

🇬🇧 English
🇯🇵 日本語, (*4)

This package allows you to add a HTTP Basic Auth filter on your routes, without the need to use a database – which the Laravel default auth.basic-middleware relies on., (*5)

Screenshot, (*6)

Perfect when you want to give your clients access to your development site before you have yet to set up your database and/or models. Or perhaps your site doesn't even use a database and you still wish to keep it protected., (*7)

On failed authentication the user will get a "401 Unauthorized" response., (*8)

A thing to note

While HTTP Basic Auth does give you a protection layer against unwanted visitors, it is still not strictly safe from brute-force attacks. If you are solely using this package for security, you should at least consider looking into Apache or Nginx rate-limiters to limit login attempts., (*9)

Installation

Via Composer, (*10)

``` bash $ composer require olssonm/l5-very-basic-auth, (*11)


Since v4.* (for Laravel 5.5) this package uses Package Auto-Discovery for loading the service provider. Once installed you should see the message

Discovered Package: olssonm/l5-very-basic-auth, (*12)


If you would like to manually add the provider, turn off Auto-Discovery for the package in your composer.json-file: ``` json "extra": { "laravel": { "dont-discover": [ "olssonm/l5-very-basic-auth" ] } },

And then add the provider in the providers array (config/app.php)., (*13)

``` php 'providers' => [ Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider::class ], (*14)


## Configuration Run the command `$ php artisan vendor:publish` and select `Provider: Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider` to publish the configuration. You could also type `$ php artisan vendor:publish --provider="Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider"` to directly publish the files. The file `very_basic_auth.php` will then be copied to your `app/config`-folder – here you can set various options such as username and password. #### Note **There is no default password**. Upon installation you will need to set your own username and password. Please publish the packages configuration to have the ability to set these. **If left empty, basic auth will not be active**. ### Environments You may set the environments that the package should be applied for. You may simply use "`*`" to use in all environments (this is also the default). ``` php 'envs' => [ '*' ],

Or, (*15)

``` php 'envs' => [ 'production', 'development', 'local' ],, (*16)


### Response handlers When the authentication fails the response handler sends out an error response (see "Views and messages" for more about these options). By default the handler will be `\Olssonm\VeryBasicAuth\Handlers\DefaultResponseHandler` (see `response_handler` in `very_basic_auth.php`). You may however write your own response-logic if you so choose. The only requirement is that it implements the `\Olssonm\VeryBasicAuth\Handlers\ResponseHandler`-interface, and has an `__invoke`-method that accepts a request-object, like so: ``` php use Illuminate\Http\Request; use Olssonm\VeryBasicAuth\Handlers\ResponseHandler; class CustomResponseHandler implements ResponseHandler { public function __invoke(Request $request) { // Do some stuff return response('Custom response', 401); } }

Views and messages

In the very_basic_auth.php-configuration you have the ability to set a custom view instead of a message., (*17)

``` php // Message to display if the user "opts out"/clicks "cancel" 'error_message' => 'You have to supply your credentials to access this resource.',, (*18)

// If you prefer to use a view with your error message you can uncomment "error_view". // This will supersede your default response message // 'error_view' => 'very_basic_auth::default', (*19)


If you uncomment `error_view`, the middleware will try to find your specified view. You supply this value as usual (without the `.blade.php`-extention). ## Usage The middleware uses the `auth.very_basic`-filter to protect routes. You can either use `Route::group()` to protect multiple routes, or chose just to protect them individually. **Group** ``` php Route::group(['middleware' => 'auth.very_basic'], function() { Route::get('/', ['as' => 'start', 'uses' => 'StartController@index']); Route::get('/page', ['as' => 'page', 'uses' => 'StartController@page']); });

Single ``` php Route::get('/', [ 'as' => 'start', 'uses' => 'StartController@index', 'middleware' => 'auth.very_basic' ]);, (*20)


You may also set the credentials inline; ``` php Route::get('/', [ 'as' => 'start', 'uses' => 'StartController@index', 'middleware' => 'auth.very_basic:username,password' ]);

Note: inline credentials always take president over the very_basic_auth.php-configuration file., (*21)

Generating hash for password

If you want to generate a hash for your password, you can use the artisan-command:, (*22)

``` bash php artisan very-basic-auth:generate-password, (*23)


It will ask you for a password, and then automatically insert the hash into your `.env`-file ## Testing ``` bash $ composer test

or, (*24)

bash $ phpunit, (*25)

Laravel always runs in the "testing" environment while running tests. Make sure that testing is set in the envs-array in very_basic_auth.php., (*26)

Thank you

A big thank you to the people who has contributed to this package, among others:, (*27)

kazuhei – for providing the awesome Japanese translation
freekmurze – for additional information on package/vendor installations
faiare – for pointing out and implementing the realm-attribute (RFC7235), (*28)

License

The MIT License (MIT). Please see License File for more information., (*29)

© 2024 Marcus Olsson., (*30)

The Versions

07/06 2018

dev-master

9999999-dev https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

07/06 2018

v5.2

5.2.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

07/06 2018

dev-realm-fixup

dev-realm-fixup https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

26/05 2018

dev-dev

dev-dev https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

29/03 2018

dev-l52php7

dev-l52php7 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

29/03 2018

v1.2.2

1.2.2.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

16/03 2018

v5.1

5.1.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

11/02 2018

dev-i18n-japanese

dev-i18n-japanese https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

09/02 2018

v5.0

5.0.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

09/02 2018

dev-L56

dev-L56 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

22/01 2018

v4.1

4.1.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

30/08 2017

v4.0

4.0.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

27/01 2017

3.0

3.0.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

22/11 2016

v2.1.0

2.1.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

14/09 2016

v2.0.1

2.0.1.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

25/08 2016

v2.0

2.0.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

15/06 2016

v1.2.1

1.2.1.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

20/11 2015

v1.2

1.2.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

10/08 2015

v1.1.1

1.1.1.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

10/08 2015

v1.1

1.1.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm

09/08 2015

v1.0

1.0.0.0 https://github.com/olssonm/l5-very-basic-auth

Stateless HTTP basic auth without the need for a database. For Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication laravel 5 http basic auth olssonm