1

https://github.com/philsturgeon/codeigniter-restserver/了解摘要式身份验证 - CodeIgniter的REST服务器

我创建使用上述其余服务器的API,并需要现在登录保护它。我知道有在其他服务器两种方法1)基本,2)消化

我也使用其他客户端来测试这个API

$this->load->library('rest', array( 
     'server' => 'http://mynew/api/', 
     'http_user' => 'admin', 
     'http_pass' => '1234', 
     'http_auth' => 'basic', // or 'digest' 
     //'http_auth' => 'digest' 
    )); 

    $user = $this->rest->get('listrecord', array('key' => 'mykey'), 'json'); 

$config['rest_valid_logins'] = array('admin' => '1234');

在上面的代码中“基本”身份验证正常工作,但当我改变它来消化它说“没有授权”。请注意,当我在这里进行更改时,我也将配置更改为摘要。

我的理解是基本不是很安全?所以这就是为什么我认为消化比它好。任何想法如何获得消化工作?谢谢你的帮助。我想,它可能不是代码特定的问题。

回答

1

您可能会为自己节省一些麻烦并使用基于SSL的基本身份验证。如果你不使用SSL,那么我认为Digest会是一条好路。再说一遍,如果你不使用SSL,那么你并不安全。

我会使用curl弄清楚你的问题是否是客户端或服务器

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://mynew/api/"); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 
curl_setopt($ch, CURLOPT_USERPWD, "admin:1234"); 

// need to get WWW-Authenticate header from the server (for realm and nonce) with a HEAD request 
curl_setopt($ch, CURLOPT_NOBODY, 1); 
curl_exec($ch);   

// the get the real output 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_HTTPGET, 1); 
$output = curl_exec($ch); 
echo $output; 
上测试您的REST服务器