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
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;
}
($this->access = self::READ_WRITE) ?
'read-write' : 'read-only'
));
- return true;
+ return;
} else {
throw new OAuthException('Bad access token.');
}
} 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));
}
$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;
}