Basic authentication filter on the fly

Submitted by itsmko - 9 years ago

Basic authentication filter on the fly

Route::filter('auth_basic_fly', function()
{
    if( isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']))
    {
    	$username = 'test'; 

    	$password = 'test';

    	if( $_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password )
    	{
    		return;
    	}
    }

	$headers['WWW-Authenticate'] = 'Basic realm="REST API"';

	return Response::make('Authenticate required', 401, $headers);

});