Why do I get a "Unauthorized" error even though the user is logged-in?
Below code might help you login-in with current user:

function mymodule_user_login_cred($username, $password)
{
  if(user_authenticate($username, $password))
  {
    $user_obj = user_load_by_name($username);
    $form_state = array();
    $form_state['uid'] = $user_obj-&gt;uid;      
    user_login_submit(array(), $form_state);
    return true;
  }
  else
  {
    return false;
  }
}