]> 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>
Thu, 21 Jan 2010 01:55:37 +0000 (17:55 -0800)
lib/apiauth.php

index 691db584b7706d6c8a461ce964c80a652c3c0005..b4292408a1ecbc2c82f21e09f0d179e24c218027 100644 (file)
@@ -79,10 +79,13 @@ class ApiAuthAction extends ApiAction
                 $this->checkOAuthRequest();
             } else {
                 $this->checkBasicAuthUser();
-                // By default, all basic auth users have read and write access
-
-                $this->access = self::READ_WRITE;
             }
+        } else {
+
+            // Check to see if a basic auth user is there even
+            // if one's not required
+
+            $this->checkBasicAuthUser(false);
         }
 
         return true;
@@ -198,13 +201,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)) {
+        if (!isset($this->auth_user) && $required) {
             header('WWW-Authenticate: Basic realm="' . $realm . '"');
 
             // show error if the user clicks 'cancel'
@@ -212,12 +215,16 @@ class ApiAuthAction extends ApiAction
             $this->showBasicAuthError();
             exit;
 
-        } else {
+        } else if (isset($this->auth_user)) {
             $nickname = $this->auth_user;
             $password = $this->auth_pw;
             $user = common_check_user($nickname, $password);
             if (Event::handle('StartSetApiUser', array(&$user))) {
                 $this->auth_user = $user;
+
+                // By default, all basic auth users have read and write access
+                $this->access = self::READ_WRITE;
+
                 Event::handle('EndSetApiUser', array($user));
             }