Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix HTTP Basic Auth on FastCGI PHP
  • Loading branch information
nicolabeghin committed Aug 28, 2016
1 parent 51963ab commit 41851d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/webroot/.htaccess
Expand Up @@ -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]
Expand Down
9 changes: 9 additions & 0 deletions lib/Cake/Controller/Component/Auth/BasicAuthenticate.php
Expand Up @@ -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');

Expand Down

0 comments on commit 41851d6

Please sign in to comment.