Laravel Authentication: HTTP Basic Authentication

Provides a quick way to authenticate users of your application without setting up a dedicated "login" page.

Route::get('profile', function () {
    // Only authenticated users may enter...
})->middleware('auth.basic');

A Note On FastCGI

RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Stateless HTTP Basic Authentication

<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Auth;

class AuthenticateOnceWithBasicAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, $next)
    {
        return Auth::onceBasic() ?: $next($request);
    }

}
Route::get('api/user', function () {
    // Only authenticated users may enter...
})->middleware('auth.basic.once');

Laravel Authentication: HTTP Basic Authentication — Structure map

Clickable & Draggable!

Laravel Authentication: HTTP Basic Authentication — Related pages: