Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim Application Error: Basic auth not working properly #24

Closed
1moere1 opened this issue May 5, 2016 · 6 comments
Closed

Slim Application Error: Basic auth not working properly #24

1moere1 opened this issue May 5, 2016 · 6 comments

Comments

@1moere1
Copy link

1moere1 commented May 5, 2016

Why can't I authenticate with postman Basic Auth (username: root, password: t00r). The /open/test route works just fine

<?php
require '../../vendor/autoload.php';
$app = new \Slim\App();
$app->add(new \Slim\Middleware\HttpBasicAuthentication(array(
    "path" => "/close",
    "realm" => "Protected",
    "users" => array(
        "root" => "t00r",
        "user" => "passw0rd"
    )
)));
$app->get('/open/test', 'getOpen');
$app->get('/close/test', 'getClose');
function getOpen() {
    echo "Success Open";
}
function getClose() {
    echo "Success Close";
}
$app->run();
@tuupola
Copy link
Owner

tuupola commented May 6, 2016

It is unclear from your report what is not working. Copy pasting the code you provided and running it works as expected.

$ php -S 0.0.0.0:8080 index.php 

$ curl --include http://localhost:8080/open/test
HTTP/1.1 200 OK

Success Open

$ curl --include http://localhost:8080/close/test
HTTP/1.1 401 Unauthorized

curl --user root:t00r --include http://localhost:8080/close/test
HTTP/1.1 200 OK

Success Close

@1moere1
Copy link
Author

1moere1 commented May 6, 2016

I tried it on localhost too, and there it works for me aswell. Only on an external IP it's not working. Did I forget to enable something?

When I try this on the ip then i get for the /close/test route a 500er error eventhough i don't see something being wrong with the code

@tuupola
Copy link
Owner

tuupola commented May 6, 2016

https://github.com/tuupola/slim-basic-auth#security

If you are not using https you need to specifically set secure to false.

$app->add(new \Slim\Middleware\HttpBasicAuthentication([
    "secure" => false,
    "users" => [
        "root" => "t00r",
        "user" => "passw0rd"
    ]
]));

@1moere1
Copy link
Author

1moere1 commented May 6, 2016

thank you very much. this solved the problem.

@1moere1 1moere1 closed this as completed May 6, 2016
@tuupola
Copy link
Owner

tuupola commented May 6, 2016

Great :)

@BrevAlessio
Copy link

If it helps, I had a similar problem on a shaerd hosting, I solved by adding SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 to .htaccess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants