summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/apiaccountratelimitstatus.php17
-rw-r--r--actions/apifriendshipsexists.php15
-rw-r--r--actions/apifriendshipsshow.php16
-rw-r--r--actions/apigroupismember.php15
-rw-r--r--actions/apigroupshow.php15
-rw-r--r--actions/apihelptest.php15
-rw-r--r--actions/apistatusnetconfig.php15
-rw-r--r--actions/apistatusnetversion.php15
-rw-r--r--actions/apiusershow.php15
-rw-r--r--lib/apiauth.php39
10 files changed, 160 insertions, 17 deletions
diff --git a/actions/apiaccountratelimitstatus.php b/actions/apiaccountratelimitstatus.php
index 1a5afd552..f19e315bf 100644
--- a/actions/apiaccountratelimitstatus.php
+++ b/actions/apiaccountratelimitstatus.php
@@ -105,7 +105,22 @@ class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
print json_encode($out);
}
- $this->endDocument($this->format);
+ $this->endDocument($this->format);
+ }
+
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
}
}
diff --git a/actions/apifriendshipsexists.php b/actions/apifriendshipsexists.php
index c040b9f6a..ca62b5f51 100644
--- a/actions/apifriendshipsexists.php
+++ b/actions/apifriendshipsexists.php
@@ -116,4 +116,19 @@ class ApiFriendshipsExistsAction extends ApiPrivateAuthAction
}
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/actions/apifriendshipsshow.php b/actions/apifriendshipsshow.php
index 73ecc9249..f29e63713 100644
--- a/actions/apifriendshipsshow.php
+++ b/actions/apifriendshipsshow.php
@@ -87,7 +87,6 @@ class ApiFriendshipsShowAction extends ApiBareAuthAction
return true;
}
-
/**
* Determines whether this API resource requires auth. Overloaded to look
* return true in case source_id and source_screen_name are both empty
@@ -165,4 +164,19 @@ class ApiFriendshipsShowAction extends ApiBareAuthAction
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/actions/apigroupismember.php b/actions/apigroupismember.php
index 69ead0b53..97f843561 100644
--- a/actions/apigroupismember.php
+++ b/actions/apigroupismember.php
@@ -119,4 +119,19 @@ class ApiGroupIsMemberAction extends ApiBareAuthAction
}
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/actions/apigroupshow.php b/actions/apigroupshow.php
index ef9cbf0e7..5745a81f4 100644
--- a/actions/apigroupshow.php
+++ b/actions/apigroupshow.php
@@ -158,4 +158,19 @@ class ApiGroupShowAction extends ApiPrivateAuthAction
return null;
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/actions/apihelptest.php b/actions/apihelptest.php
index 7b4017531..d0e9e4926 100644
--- a/actions/apihelptest.php
+++ b/actions/apihelptest.php
@@ -92,5 +92,20 @@ class ApiHelpTestAction extends ApiPrivateAuthAction
}
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/actions/apistatusnetconfig.php b/actions/apistatusnetconfig.php
index ab96f2e5f..dc1ab8685 100644
--- a/actions/apistatusnetconfig.php
+++ b/actions/apistatusnetconfig.php
@@ -138,5 +138,20 @@ class ApiStatusnetConfigAction extends ApiAction
}
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/actions/apistatusnetversion.php b/actions/apistatusnetversion.php
index 5109cd806..d09480759 100644
--- a/actions/apistatusnetversion.php
+++ b/actions/apistatusnetversion.php
@@ -98,5 +98,20 @@ class ApiStatusnetVersionAction extends ApiPrivateAuthAction
}
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/actions/apiusershow.php b/actions/apiusershow.php
index a7fe0dcc1..6c8fad49b 100644
--- a/actions/apiusershow.php
+++ b/actions/apiusershow.php
@@ -123,4 +123,19 @@ class ApiUserShowAction extends ApiPrivateAuthAction
}
+ /**
+ * Return true if read only.
+ *
+ * MAY override
+ *
+ * @param array $args other arguments
+ *
+ * @return boolean is read only action?
+ */
+
+ function isReadOnly($args)
+ {
+ return true;
+ }
+
}
diff --git a/lib/apiauth.php b/lib/apiauth.php
index ac5e997c7..d441014ad 100644
--- a/lib/apiauth.php
+++ b/lib/apiauth.php
@@ -57,7 +57,6 @@ class ApiAuthAction extends ApiAction
var $auth_user_password = null;
var $access_token = null;
var $oauth_source = null;
- var $auth_user = null;
/**
* Take arguments for running, and output basic auth header if needed
@@ -82,22 +81,27 @@ class ApiAuthAction extends ApiAction
if (!empty($this->access_token)) {
$this->checkOAuthRequest();
} else {
- $this->checkBasicAuthUser();
+ $this->checkBasicAuthUser(true);
}
} else {
// Check to see if a basic auth user is there even
// if one's not required
- $this->checkBasicAuthUser(false);
+ if (empty($this->access_token)) {
+ $this->checkBasicAuthUser(false);
+ }
}
// Reject API calls with the wrong access level
if ($this->isReadOnly($args) == false) {
+
+ common_debug(get_class($this) . ' is not read-only!');
+
if ($this->access != self::READ_WRITE) {
- $msg = 'API resource requires read-write access, ' .
- 'but you only have read access.';
+ $msg = _('API resource requires read-write access, ' .
+ 'but you only have read access.');
$this->clientError($msg, 401, $this->format);
exit;
}
@@ -176,7 +180,7 @@ class ApiAuthAction extends ApiAction
($this->access = self::READ_WRITE) ?
'read-write' : 'read-only'
));
- return true;
+ return;
} else {
throw new OAuthException('Bad access token.');
}
@@ -228,9 +232,14 @@ 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 = common_check_user($this->auth_user_nickname,
- $this->auth_user_password);
+
+ if (!empty($user)) {
+ $this->auth_user = $user;
+ }
Event::handle('EndSetApiUser', array($user));
}
@@ -239,18 +248,18 @@ class ApiAuthAction extends ApiAction
$this->access = self::READ_WRITE;
- if (empty($this->auth_user)) {
+ if (empty($this->auth_user) && $required) {
// basic authentication failed
list($proxy, $ip) = common_client_ip();
- common_log(
- LOG_WARNING,
- 'Failed API auth attempt, nickname = ' .
- "$nickname, proxy = $proxy, ip = $ip."
- );
-
+ $msg = sprintf(_('Failed API auth attempt, nickname = %1$s, ' .
+ 'proxy = %2$s, ip = %3$s'),
+ $this->auth_user_nickname,
+ $proxy,
+ $ip);
+ common_log(LOG_WARNING, $msg);
$this->showAuthError();
exit;
}