Skip to content

Instantly share code, notes, and snippets.

@olssonm
Last active September 14, 2016 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olssonm/ea5561d7ab20fb5c8ddbdac9b556b32b to your computer and use it in GitHub Desktop.
Save olssonm/ea5561d7ab20fb5c8ddbdac9b556b32b to your computer and use it in GitHub Desktop.
Basic authentication for Laravel 4, based on https://github.com/olssonm/l5-very-basic-auth
<?php
Route::filter('auth.very_basic', function($request, $response)
{
// Load configuration
$veryBasicAuthUser = 'admin';
$veryBasicAuthPass = 'admin';
$veryBasicAuthEnvs = array('dev');
$veryBasicAuthMsg = 'Access denied';
// Check if middleware is in use in current environment
if(in_array(App::environment(), $veryBasicAuthEnvs)) {
// dd(Request::header());
if(Request::header('php-auth-user') != $veryBasicAuthUser || Request::header('php-auth-pw') != $veryBasicAuthPass) {
$response = Response::make($veryBasicAuthMsg, 401);
$response->header('WWW-Authenticate', 'Basic');
return $response;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment