]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
HTTP auth provided is evaluated even if it's not required
authorMichele <macno@macno.org>
Sun, 17 Jan 2010 10:21:07 +0000 (11:21 +0100)
committerZach Copley <zach@status.net>
Wed, 27 Jan 2010 22:06:27 +0000 (14:06 -0800)
lib/apiauth.php

index ad9651ff267d977b44461392ab1d3680b0117481..ac5e997c78dfc9b96b96810a1bee61fcda410637 100644 (file)
@@ -84,16 +84,22 @@ class ApiAuthAction extends ApiAction
             } else {
                 $this->checkBasicAuthUser();
             }
+        } else {
 
-            // Reject API calls with the wrong access level
+            // Check to see if a basic auth user is there even
+            // if one's not required
 
-            if ($this->isReadOnly($args) == false) {
-                if ($this->access != self::READ_WRITE) {
-                    $msg = 'API resource requires read-write access, ' .
-                      'but you only have read access.';
-                    $this->clientError($msg, 401, $this->format);
-                    exit();
-                }
+            $this->checkBasicAuthUser(false);
+        }
+
+        // Reject API calls with the wrong access level
+
+        if ($this->isReadOnly($args) == false) {
+            if ($this->access != self::READ_WRITE) {
+                $msg = 'API resource requires read-write access, ' .
+                       'but you only have read access.';
+                $this->clientError($msg, 401, $this->format);
+                exit;
             }
         }
 
@@ -206,13 +212,13 @@ class ApiAuthAction extends ApiAction
      * @return boolean true or false
      */
 
-    function checkBasicAuthUser()
+    function checkBasicAuthUser($required = true)
     {
         $this->basicAuthProcessHeader();
 
         $realm = common_config('site', 'name') . ' API';
 
-        if (!isset($this->auth_user_nickname)) {
+        if (!isset($this->auth_user_nickname) && $required) {
             header('WWW-Authenticate: Basic realm="' . $realm . '"');
 
             // show error if the user clicks 'cancel'
@@ -222,11 +228,10 @@ class ApiAuthAction extends ApiAction
 
         } else {
 
-            $user = common_check_user($this->auth_user_nickname,
-                                      $this->auth_user_password);
-
             if (Event::handle('StartSetApiUser', array(&$user))) {
-                $this->auth_user = $user;
+                $this->auth_user = common_check_user($this->auth_user_nickname,
+                                                     $this->auth_user_password);
+
                 Event::handle('EndSetApiUser', array($user));
             }