tuupola / slim-basic-auth

PSR-7 and PSR-15 HTTP Basic Authentication Middleware
MIT License
440 stars 66 forks source link

Why does local(HTTP) connection work but not online(HTTPS)? #93

Closed manzowa closed 4 years ago

manzowa commented 4 years ago

I am testing the SLIM structure for my new API REST project.

I installed SLIM on my Apache CGI server online with SSL certificate: ok, it works! I can access my resource from my computer (http://domaine.fr/v1/test for example)

I tested with basic authentication through the htaccess file. I type user / password to access my resource: it works!

Now, "I would like to test with basic authentication in SLIM with https://github.com/tuupola/slim-basic-auth

But it does not work! It always asks me for the login and password!

tuupola commented 4 years ago

Without seeing any code or having any useful information it is impossible to think about an answer.

manzowa commented 4 years ago

First, thank you for your quick response. Here is the local code Local URL =>http://noe//v3/connecteurs

2020-06-10 095926 It works very well locally

And here is the code online Online URL => https://noe300-dev.developpement-lanteas.fr/v3/connecteurs 2020-06-10-101231.

it works very local but online it continues to ask for authentication.

tuupola commented 4 years ago

First thing I would do is to find out what is the difference between your local (development) and online (live) environments. For example what is the return value of noeUser().

manzowa commented 4 years ago

En Locally it is WAMPSERVER on windows and online is LAMP. The noeUser() function returns a table like [username => password].

tuupola commented 4 years ago

Yes. Now debug what noeUser() actually returns and what is different between the servers which causes live authorization to fail.

Code obviously works since it works in dev. Problem is some difference in live.

manzowa commented 4 years ago

The function returns an array like those [ 'silex100' => '$ 2y $ 10 $ .VspSemhS8o7pswjJPkIxOWeD / CDARiXl6zsiCQdovfFfod.Lm8ya', 'admin' => '$ 2y $ 10 $ vNt9Sv6wRBd8QKNjNuIVqelGAMn8IZCqgqSx52q7Uxj3Maz5fKROO' ], I even changed the configuration code to test Annotation-2020-06-10-112606

tuupola commented 4 years ago

If you are 100% sure that you are using the correct password start to look what is different with your server. For example does it pass the Authorization header to PHP (do a print_r($request) somewhere).

manzowa commented 4 years ago

The only difference is the secure parameter which changes to true.

tuupola commented 4 years ago

The secure parameter does not affect authentication. Look for differences in your server setup. Did you already check if PHP receives the Authorization header?

manzowa commented 4 years ago

I ran the phpinfo () function to see the difference between my local and online server. I find the absence of global variable $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] in server online.

manzowa commented 4 years ago

Thanks for the help.

tuupola commented 4 years ago

It seems that PHP is not getting the Authorization header. Server might be using FastCGI. The following might help:

https://github.com/tuupola/slim-basic-auth#usage-with-fastcgi

Or if using Apache you might try adding the following to .htaccess.

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
manzowa commented 4 years ago

Thank you very much I managed to work

tuupola commented 4 years ago

Great! How did you fix it?

manzowa commented 4 years ago

I added RewriteRule. * - [E = HTTP_AUTHORIZATION:% {HTTP: Authorization}] in the .htaccess Like these: Annotation

tuupola commented 4 years ago

Ok. Thanks for info!