【问题标题】:codeigniter-restserver: digest auth always returns "invalid credentials"codeigniter-restserver:digest auth 总是返回“无效凭据”
【发布时间】:2015-09-24 06:58:45
【问题描述】:

我正在尝试将 codeigniter-restserver 代码集成到我现有的 CI3 项目中。我不知道如何通过身份验证获得工作凭据。

这是卡住的代码 (REST_Controller.php):

    if (strcasecmp($digest['response'], $valid_response) !== 0)
    {
        // Display an error response
        $this->response([
                $this->config->item('rest_status_field_name') => "false",
                $this->config->item('rest_message_field_name') => $this->lang->line('text_rest_invalid_credentials')
            ], self::HTTP_UNAUTHORIZED);
    }

rest.php // 配置

$config['rest_auth'] = 'digest';
$config['auth_source'] = 'library';
$config['auth_library_class'] = 'auth_model';
$config['auth_library_function'] = 'validate_user';

上面提到的类(来自数据库的认证):

function validate_user($username='',$password=null)
    {
        if($username!=''&&$password!=null)
        {
            $this->db->select('md5');
            $this->db->where('username', $username);
            $query = $this->db->get('user');
            $result = $query->result_array();
            return $result[0]['md5']; // stored as md5(username:realm:password);
        }
        return false;
    }

响应 json:

{"status":"false","error":"Invalid credentials"}

使用邮递员,这是我为标题设置的方法:

Digest username="user", realm="REST API", nonce="", uri="/restapi/dashboard", response="928e85782ff2322fd2232ebbac4f058f", opaque=""

【问题讨论】:

  • 你在哪里定义你的类 auth_model ?我的错误说它找不到我请求的课程。我的课程放在库文件夹中。

标签: php codeigniter codeigniter-restserver


【解决方案1】:

确保您在授权中包含qop=auth

【讨论】:

    【解决方案2】:

    @Japheth 是对的,但是您应该添加 Nonce、Nonce Count 和 Client Nonce 值空白即可。

    nonce=" "  // Nonce
    nc=" "     // Nonce Count
    cnonce=" " // Client Nonce
    qop=auth
    

    标题将如下所示:

    Authorization:Digest username="user", realm="REST API", nonce=" ", uri="/restapi/dashboard", qop=auth, nc= , cnonce=" ", response="928e85782ff2322fd2232ebbac4f058f", opaque=""
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      • 2019-06-28
      • 2020-01-22
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      相关资源
      最近更新 更多