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

Overview

Laravel Very Basic Auth

Latest Version on Packagist Total downloads Software License Build Status

very-basic-auth

Documentation available in:

🇬🇧 English
🇯🇵 日本語

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.

Screenshot

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.

On failed authentication the user will get a "401 Unauthorized" response.

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.

Version Compatibility

Laravel l5-very-basic-auth
^5.4 5.*
^6 || ^7 || ^8 || ^9 6.*

The odd versioning is due to breaking changes in the testing framework and PHP versions. 3.x-releases are for Laravel 5.4 (PHP 5.6 and up) and 4.x-releases for Laravel 5.5.

Using Laravel 4.x?

Take a look at this gist, it uses the old Route::filter-methods to achieve pretty much the same goal.

Installation

Via Composer

$ composer require olssonm/l5-very-basic-auth

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

If you would like to manually add the provider, turn off Auto-Discovery for the package in your composer.json-file:

"extra": {
    "laravel": {
        "dont-discover": [
            "olssonm/l5-very-basic-auth"
        ]
    }
},

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

'providers' => [
    Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider::class
]

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 a random password is set for added security (we don't want everyone to use the same default password). Please publish the packages configuration to have the ability to set a custom password.

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).

'envs' => [
    '*'
],

Or

'envs' => [
    'production',
    'development',
    'local'
],

Views and messages

In the very_basic_auth.php-configuration you have the ability to set a custom view instead of a message.

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

// 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'

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).

If you've upgraded to 2.1 from a previous version this key and value will be missing from your published configuration and you will have to add it yourself.

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

Route::group(['middleware' => 'auth.very_basic'], function() {
    Route::get('/', ['as' => 'start', 'uses' => 'StartController@index']);
    Route::get('/page', ['as' => 'page', 'uses' => 'StartController@page']);
});

Single

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

You may also set the credentials inline;

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.

Testing

$ composer test

or

$ phpunit

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.

Thank you

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

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)

License

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

© 2021 Marcus Olsson.

Comments
  • Stuck in authentication loop

    Stuck in authentication loop

    Hi,

    every time I open the my test page I get the prompt to enter details, enter them and get another prompt. This is due to the fact, that $request->getUser() and $request->getPassword() are always empty. In postman and curl I simply get the error message.

    I installed laravel in a subfolder, could it be some redirect issue? Maybe I have to enter something in .htaccess?

    thanks

    opened by repat 9
  • Request - Config & Inline Credentials

    Request - Config & Inline Credentials

    Hi, as the title suggests;

    # Inline
    Route::group(['middleware' => 'auth.very_basic:admin,password'], function() {
        ...
    });
    
    # Config
    Route::group(['middleware' => 'auth.very_basic:services.xservice.basic_auth'], function() {
        ...
    });
    
    

    Basically the config part can be negated as can be used as:

    Route::group([ 'middleware' => 'auth.very_basic:' . config('services.xservice.basic_auth') ], function() {
        ...
    });
    
    enhancement 
    opened by kevyworks 7
  • Disable prompting for authentication details

    Disable prompting for authentication details

    Thank you. Package works great - straight out of the box, though the creation of the config file in the vendor folder (which should be write-only to web processes) is a little disconcerting.

    Anyway, my requirement. I would like to be able to protect a route or group using basic auth details, but I don't want the browser to pop up with a user credentials box. This is specifically for a machine-to-machine API, so no user will ever be logging in, and any user encountering the route should not be given clues that basic auth is in place on that route.

    The idea is just to return a 401 without the WWW-Authenticate header, or better still a 404 - no clues that a route is there.

    Obviously it's not going to stop a brute force attempt given the knowledge about the route, but a little security-by-obscurity should help to reduce the likelihood of it happening.

    Is this something you would be interested in supporting, if I had a PR?

    opened by judgej 6
  • PHP 7 support / issue

    PHP 7 support / issue

    Switched my environment from PHP 5.6 to 7.2 and prompt still works however after entering the correct password, it declines it.

    As soon as I switch over to 5.6, the username/password combination works again.

    I know PHP 7 is not supported but it would really help to support it in my situations where people are upgrading or migrating their hosts.

    under investigation 
    opened by zicodes 6
  • Uncaught ReflectionException: Class translator does not exist

    Uncaught ReflectionException: Class translator does not exist

    Hi and thanks for creating the package.

    I have a multi-lingual site and would like to customize the 'opt out / cancel' message. I tried updated the 'very_basic_auth.php' config file to include

    'error_message'     =>  trans('auth.opt_out')
    

    but get an error. Is this supported? Is there a different way of doing this?

    Thanks in advance

    enhancement 
    opened by tyler36 4
  • Add realm attribute to WWW-Authenticate header.

    Add realm attribute to WWW-Authenticate header.

    Hi.

    Thank you for this great package. I encountered a problem not remembering authentication with Internet Explorer (version 11).

    Internet Explorer probably requires the realm attribute in WWW-Authenticate header. Without realm attribute, Internet Explorer refuses to remember authentication.

    opened by faiare 2
  • [Info] Can't load page using very-basic-auth at all on emphaty browser on raspberry pi one Model B

    [Info] Can't load page using very-basic-auth at all on emphaty browser on raspberry pi one Model B

    Hi,

    I'm using your package for a fork of a dashboard package. I'd like to show the page on a old raspberry pi in the Epiphany Browser (v3.8.2) in kiosk mode.

    But the site could not been loaded. The browser don't stop loading the page and don't show the authentication dioalog as expected.

    Since I can solve this with native apache basic authentication, this is not critical at all. But I thought this could be a Problem with some Browsers want to be fixed.

    Hope it helps.

    opened by okaufmann 2
  • improve publish config command

    improve publish config command

    Hi,

    thank you for this nice and handy package.

    When publishing assets it's always a good idea to specifically target a service provider. More info here: https://murze.be/2016/04/publishing-package-assets-right-way/

    opened by freekmurze 2
  • PHP 8

    PHP 8

    Support for PHP 8 is available and has been tested.

    However, Travis CI doesn't seem to support PHP 8 just yet so the build is failing. Until all tests has been passed I will not put out a new release.

    In the meanwhile – if PHP 8 support i critical, require the hash bfd6e8a on dev-master. I.e:

    composer require olssonm/l5-very-basic-auth:dev-master#bfd6e8a
    
    under investigation 
    opened by olssonm 1
  • Add license scan report and status

    Add license scan report and status

    Your FOSSA integration was successful! Attached in this PR is a badge and license report to track scan status in your README.

    Below are docs for integrating FOSSA license checks into your CI:

    opened by fossabot 1
  • Issues with Apache/CGI-combo

    Issues with Apache/CGI-combo

    Authorization headers do not work as expected when using the Apache CGI-module.

    It would be nice if there was a fix for this built in directly in the package to remove the need for a custom solution to circumvent this, as this issue might be common on shared hosting services. The only custom code that would be needed is a line in the .htaccess.

    For reference: RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]

    For previous discussion, see #5.

    bug enhancement 
    opened by olssonm 1
Releases(v6.8)
Owner
Marcus Olsson
Freelancing web developer based in Borås, Sweden.
Marcus Olsson
Multi Auth and admin auth in Laravel Project

Laravel Multi Auth For Complete Documentation, visit Here This package is just create admin side (multi auth), which is totaly isolated from your norm

Bitfumes 435 Dec 31, 2022
CakeDC Auth Objects is a refactor of the existing Auth objects present in the CakeDC Users Plugin, to let anyone else use them in their projects.

CakeDC Auth Objects is a refactor of the existing Auth objects present in the CakeDC Users Plugin, to let anyone else use them in their projects.

Cake Development Corporation 24 Sep 23, 2022
A Native PHP MVC With Auth. If you will build your own PHP project in MVC with router and Auth, you can clone this ready to use MVC pattern repo.

If you will build your own PHP project in MVC with router and Auth, you can clone this ready to use MVC pattern repo. Auth system is implemented. Works with bootstrap 5. Composer with autoload are implemented too for future composer require.

null 2 Jun 6, 2022
Configurable Basic Auth based on Pimcore Documents

CORS Property Basic Auth This bundles allows to add basic auth based on Properties on Pimcore Documents. Simply use these properties password_enabled

CORS GmbH 1 Nov 12, 2021
PSR-7 and PSR-15 HTTP Basic Authentication Middleware

PSR-7 and PSR-15 Basic Auth Middleware This middleware implements HTTP Basic Authentication. It was originally developed for Slim but can be used with

Mika Tuupola 430 Dec 30, 2022
Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system.

Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system. Built on Bootstrap 4.

Jeremy Kenedy 2.8k Dec 31, 2022
Set up Laravel Auth guards using Eloquent in seconds

Nightguard Set up Auth guards using Eloquent in seconds. Introduction Laravel guards provide a super convenient way of authorizing different areas of

Luke Downing 10 Mar 18, 2021
Laravel starter kit with Livewire & Bootstrap 5 auth scaffolding.

Laravel Livewire Auth Laravel starter kit with Livewire & Bootstrap 5 auth scaffolding. Requirements NPM Installation Create a new Laravel app: larave

null 8 Sep 11, 2021
JWT auth for Laravel and Lumen

JWT Artisan Token auth for Laravel and Lumen web artisans JWT is a great solution for authenticating API requests between various services. This packa

⑅ Generation Tux ⑅ 141 Dec 21, 2022
Laravel Auth guard for FusionAuth JWT

Laravel FusionAuth JWT Implement an Auth guard for FusionAuth JWTs in Laravel. It ships with also a middleware to check against the user role. Install

Theraloss 7 Feb 21, 2022
Files Course Laravel Micro Auth and Authorization

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

EspecializaTi 8 Oct 22, 2022
Simple JWT Auth support for Laravel PHP Framework

Laravel JWT Simple JWT Auth for Laravel PHP Framework using Firebase JWT under the hood. Installation Standard Composer package installation: composer

Ricardo Čerljenko 34 Nov 21, 2022
Simple PASETO Auth support for Laravel PHP Framework

Laravel PASETO Simple PASETO Auth for Laravel PHP Framework using paragonie/paseto under the hood. Installation Standard Composer package installation

Ricardo Čerljenko 9 Jan 11, 2022
Light-weight role-based permissions system for Laravel 6+ built in Auth system.

Kodeine/Laravel-ACL Laravel ACL adds role based permissions to built in Auth System of Laravel 8.0+. ACL middleware protects routes and even crud cont

Kodeine 781 Dec 15, 2022
Laravel auth-boilerplate using sanctum

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Jigar Bhaliya 3 Mar 2, 2022
Hierarchical Rol-Permission Based Laravel Auth Package with Limitless Hierarchical Level of Organizations

AAuth for Laravel Hierarchical Rol-Permission Based Laravel Auth Package with Limitless Hierarchical Level of Organizations Features Organization Base

Aurora Web Software Team 23 Dec 27, 2022
Google Auth Library for PHP

This is Google's officially supported PHP client library for using OAuth 2.0 authorization and authentication with Google APIs.

Google APIs 1.2k Jan 4, 2023
Sliding captcha for dcat-admin auth / dcat-admin登陆 滑动验证插件 多平台支持

dcat-admin登陆 滑动验证插件 多平台支持 dcat-admin登陆 滑动验证插件 多平台支持 另有 laravel-admin版 Demo演示 演示站点(暂时无,目前地址为laravel-admin版的演示地址) 支持(按照字母顺序) 顶象 ✔️ 极验 ✔️ hCaptcha(和谷歌Rec

塵世不再 38 Dec 17, 2022
A PHP boilerplate based on Slim Framework, for start projects with Eloquent ORM, Validation, Auth (JWT), Repositories and Transformers ready

A PHP boilerplate based on Slim Framework, for start projects with Eloquent ORM, Validation, Auth (JWT), Repositories and Transformers ready.

Damiano Petrungaro 58 Aug 10, 2022