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
And here is the code online
Online URL => https://noe300-dev.developpement-lanteas.fr/v3/connecteurs
.
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.
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?
Ok. Thanks for info!