-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Labels
Description
Hi,
I have the following code:
$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"path" => ["/auth", "/user", "/search"],
"realm" => "Protected",
"authenticator" => new PdoAuthenticator([
"pdo" => $authenticator_pdo,
"table" => "users",
"user" => "username",
"hash" => "password_hash"
]),
"callback" => function ($request, $response, $arguments) {
print_r($arguments);
},
"error" => function ($request, $response, $arguments) {
return $response->withJson(array('error' => 'AUTHENTICATION_FAILED'), 403);
}
]));
// Check HTTP Basic Authentication
$app->get('/auth', function ($request, $response, $args) {
$auth_username = $_SERVER['PHP_AUTH_USER'];
// Return
return $response->withJson(array(
'username' => $auth_username,
'status' => 'OK'
), 200);
});
If I pass in the header "Authorization: Basic" (upper case B) the authentication is successful and PHP_AUTH_USER is set:
curl 'http://localhost:8080/auth' -H 'Authorization: Basic bmlsczp0ZXN0MTIzNA=='
Array
(
[user] => nils
[password] => test1234
)
{"username":"nils","status":"OK"}
If I pass in the header "Authorization: basic" (lowercase letter b) the authentication is successful and PHP_AUTH_USER is not set.
curl 'http://localhost:8080/auth' -H 'Authorization: basic bmlsczp0ZXN0MTIzNA=='
Array
(
[user] => nils
[password] => test1234
)
{"username":null,"status":"OK"}
When I remove the case-insensitive (/i) Regular Expression in HttpBasicAuthentication.php then the authentication with basic (lowercase letter b) fails:
curl 'http://localhost:8080/auth' -H 'Authorization: basic bmlsczp0ZXN0MTIzNA=='
{"error":"AUTHENTICATION_FAILED"}
That would be better in my case. I am briefly overflown the RFCs. Basic is always written with (upper case B).
Best regards
Nils