add_action('init', array(&$this, 'basic_auth'), 1);

add action to init, and set $priority to 1 to ensure that this plugin was exec before some other plugins (such as json-api) to avoid escaping form authentication.