fix HTTP Basic Auth on FastCGI PHP

This commit is contained in:
Nicola Beghin 2016-08-28 19:16:59 +02:00
parent 51963ab8fc
commit 41851d60b4
2 changed files with 10 additions and 0 deletions

View file

@ -6,6 +6,7 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

View file

@ -82,6 +82,15 @@ class BasicAuthenticate extends BaseAuthenticate {
* @return mixed Either false or an array of user information
*/
public function getUser(CakeRequest $request) {
if(!isset($_SERVER['PHP_AUTH_USER'])) {
if (isset($_SERVER['HTTP_AUTHORIZATION']) && (strlen($_SERVER['HTTP_AUTHORIZATION']) > 0)) {
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
if( strlen($_SERVER['PHP_AUTH_USER']) == 0 || strlen($_SERVER['PHP_AUTH_PW']) == 0 ) {
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);
}
}
}
$username = env('PHP_AUTH_USER');
$pass = env('PHP_AUTH_PW');