From 140689800b03ff704f6c70260c2b740ad41578c0 Mon Sep 17 00:00:00 2001 From: zach Date: Sun, 20 Jul 2008 03:09:05 -0400 Subject: Twitter-compatible API - Error handling that better matches Twitter's darcs-hash:20080720070905-ca946-dda57dd92210461361fd58b7a3244bf24c01e801.gz --- actions/api.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'actions/api.php') diff --git a/actions/api.php b/actions/api.php index a52570320..69fda2e22 100644 --- a/actions/api.php +++ b/actions/api.php @@ -45,9 +45,7 @@ class ApiAction extends Action { $this->api_method = $cmdext[0]; $this->content_type = strtolower($cmdext[1]); } - - # common_debug("apiaction = $this->api_action, method = $this->api_method, argument = $this->api_arg, ctype = $this->content_type"); - + # XXX Maybe check to see if the command actually exists first? if($this->requires_auth()) { if (!isset($_SERVER['PHP_AUTH_USER'])) { @@ -56,7 +54,7 @@ class ApiAction extends Action { header('WWW-Authenticate: Basic realm="Laconica API"'); # if the user hits cancel -- bam! - common_show_basic_auth_error(); + $this->show_basic_auth_error(); } else { $nickname = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; @@ -67,7 +65,7 @@ class ApiAction extends Action { $this->process_command(); } else { # basic authentication failed - common_show_basic_auth_error(); + $this->show_basic_auth_error(); } } } else { @@ -123,5 +121,12 @@ class ApiAction extends Action { return true; } } + + function show_basic_auth_error() { + header('HTTP/1.1 401 Unauthorized'); + header('Content-type: text/plain'); + print("Could not authenticate you."); # exactly what Twitter says - no \n + exit(); + } } -- cgit v1.2.3-54-g00ecf