 restws_basic_auth/restws_basic_auth.module | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/restws_basic_auth/restws_basic_auth.module b/restws_basic_auth/restws_basic_auth.module
index 3b611d1..889a3fe 100644
--- a/restws_basic_auth/restws_basic_auth.module
+++ b/restws_basic_auth/restws_basic_auth.module
@@ -15,11 +15,24 @@ 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));
-    list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', $authentication);
+  if(!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])) {
+    if (!empty($_SERVER['HTTP_AUTHORIZATION']) || !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
+      $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()) {
+      if (isset($headers['Authorization']) && !empty($headers['Authorization'])) {
+        $authentication = base64_decode(substr($headers['Authorization'], 6));
+      }
+    }
+    
+    // We should have an auth string here
+    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'])) {
+
+  if(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.*/');
     if (preg_match($user_regex, $_SERVER['PHP_AUTH_USER'])) {
@@ -38,4 +51,4 @@ function restws_basic_auth_init() {
       }
     }
   }
-}
+}
\ No newline at end of file
