Skip to content
Permalink
Browse files

fix HTTP Basic Auth on FastCGI PHP

  • Loading branch information...
nicolabeghin committed Aug 28, 2016
1 parent 51963ab commit 41851d60b466b7740647f73f317494b23ff7344c
Showing with 10 additions and 0 deletions.
  1. +1 −0 app/webroot/.htaccess
  2. +9 −0 lib/Cake/Controller/Component/Auth/BasicAuthenticate.php
@@ -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]
@@ -82,6 +82,15 @@ public function authenticate(CakeRequest $request, CakeResponse $response) {
* @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');

0 comments on commit 41851d6

Please sign in to comment.
You can’t perform that action at this time.