Last active
September 14, 2016 12:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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