tuupola/slim-basic-auth

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

manzowa opened this issue · 16 comments

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!

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

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.

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().

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

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.

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

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).

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

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

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.

Thanks for the help.

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}]

Thank you very much I managed to work

Great! How did you fix it?

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

Ok. Thanks for info!