 restws_basic_auth/restws_basic_auth.module | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/restws_basic_auth/restws_basic_auth.module b/restws_basic_auth/restws_basic_auth.module
index 3b611d1..8113eeb 100644
--- a/restws_basic_auth/restws_basic_auth.module
+++ b/restws_basic_auth/restws_basic_auth.module
@@ -15,10 +15,20 @@ function restws_basic_auth_init() {
   // for compatibility with Apache PHP CGI/FastCGI.
   // This requires the following line in your ".htaccess"-File:
   // RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
-  if (!empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])) {
-    $authentication = base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 6));
+  if ((!empty($_SERVER['HTTP_AUTHORIZATION']) || !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) && !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])) {
+    $authentication = base64_decode(substr((!empty($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : $_SERVER['REDIRECT_HTTP_AUTHORIZATION']), 6));
+  }
+  // If that did not work, we attempt the fallback
+  elseif ($headers = getallheaders() && !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])) {
+    if (isset($headers['Authorization']) && !empty($headers['Authorization'])) {
+      $authentication = base64_decode(substr($headers['Authorization'], 6));
+    }
+  }
+
+  if (isset($authentication)) {
     list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', $authentication);
   }
+
   if (user_is_anonymous() && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
     // Login only user names that match a pattern.
     $user_regex = variable_get('restws_basic_auth_user_regex', '/^restws.*/');
