codeigniter-restserver:digest auth 总是返回"invalid credentials"



我正试图将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

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

上面提到的类(auth from database):

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=""

确保在autho中包含qop=auth

@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=""

相关内容

最新更新