Adding compatibility with PHP running in FastCGI mode. In order to get this working you need to update your .htaccess-file with the following line:

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

implementing solution from stackoverflow

Comments

maximilianmikus’s picture

Title: FastCGI support. » HTTP Basic auth headers not supported by FastCGI.
StatusFileSize
new1.2 KB

Updating title & patch.

fago’s picture

StatusFileSize
new1.94 KB

Thanks, I found the following problems:

+++ b/restws_basic_auth/restws_basic_auth.module
@@ -11,6 +11,17 @@
+  // Try to fill PHP_AUTH_USER &  PHP_AUTH_PW with REDIRECT_HTTP_AUTHORIZATION

Two spaces after &

+++ b/restws_basic_auth/restws_basic_auth.module
@@ -11,6 +11,17 @@
+  if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])
+    && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])

The isset is unnecessary when !empty() is used.

So, I fixed those, improved comments and code formatting a bit and added some docs to the README.

fago’s picture

StatusFileSize
new1.94 KB
+++ b/restws_basic_auth/README.txt
@@ -15,3 +15,14 @@ You can configure the regex (suitable for preg_match()) in your settings.php,
+  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Fixed miss newline at end of file.

fago’s picture

StatusFileSize
new1.91 KB

grml, new line should not have indentation.

klausi’s picture

Title: HTTP Basic auth headers not supported by FastCGI. » HTTP Basic auth headers not supported by Apache FastCGI
Status: Needs review » Postponed (maintainer needs more info)

Not sure about this, looks like an Apache specific problem? This was never a problem for Nginx and FastCGI/FPM, so what web server are you using? Why can't Apache pass in the correct headers? Why can't FastCGI just pass on the headers to PHP?

fago’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.88 KB

Yes, it's apache with php as fast-cgi.

see https://bugs.php.net/bug.php?id=35752 and http://stackoverflow.com/questions/3663520/php-auth-user-not-set

It seems to be an apache only problem. Looks like one can configure at least mod-fast cgi to pass through unknown headers, but that's not the case in our server configuration (which we have no access to). In our case authentication details are by default not available in $_SERVER at all - what sucks. But the .htaccess work-a-round does it.

So I'd suggest adding it but fixing the docs to make clear it's an apache problem? -> Updated patch with updated docs.

klausi’s picture

Status: Needs review » Needs work
+++ b/restws_basic_auth/restws_basic_auth.module
@@ -11,6 +11,14 @@
+  // Try to fill PHP_AUTH_USER & PHP_AUTH_PW with REDIRECT_HTTP_AUTHORIZATION
+  // for compatibility with PHP FastCGI.
+  // This requires the following line in your ".htaccess"-File:
+  // RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

The comment should also mention that this is Apache-specific.

Needless to say that we don't have to hack around like this in Drupal 8, Symfony would handle this case for us :)

Otherwise looks good!

fago’s picture

Status: Needs work » Needs review
StatusFileSize
new1.89 KB

Needless to say that we don't have to hack around like this in Drupal 8, Symfony would handle this case for us :)

:-)

Updated patch accordingly.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

OK, I guess you can commit that yourself :-)

fago’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Yep, committed and pushed to 2.x and 1.x.

fago’s picture

klausi pointed out 7.x-1.x should only receive security fixes, so reverted it for 7.x-1.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.