diff --git a/app/Http/Middleware/BasicAuth.php b/app/Http/Middleware/BasicAuth.php new file mode 100644 index 0000000..f18fd8d --- /dev/null +++ b/app/Http/Middleware/BasicAuth.php @@ -0,0 +1,29 @@ +getUser() ?? '') || ! hash_equals($password, $request->getPassword() ?? '')) { + return response('Unauthorized', 401, [ + 'WWW-Authenticate' => 'Basic realm="Protected Area"', + ]); + } + + return $next($request); + } +} diff --git a/resources/views/examples/basic-auth.blade.php b/resources/views/examples/basic-auth.blade.php new file mode 100644 index 0000000..e21b051 --- /dev/null +++ b/resources/views/examples/basic-auth.blade.php @@ -0,0 +1,59 @@ +@use('Illuminate\Support\Str') + + +
+ + + ++ You have successfully authenticated using HTTP Basic Authentication. +
+ohdearbest-monitoring-service-ever# Access a page protected by HTTP Basic Auth
+curl -u ohdear:best-monitoring-service-ever {{ url('/basic-auth') }}
+ # Returns HTML page confirming successful authentication
+# Without credentials, returns 401 Unauthorized
+