提问者:小点点

了解摘要身份验证-CodeIgniter Rest Server


https://github.com/philsturgeon/codeigniter-restserver/

我已经创建了一个api使用Rest服务器上面,需要登录保护它现在。我知道Rest服务器有两种方法1)基本,2)摘要

我还使用rest客户端来测试这个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']=数组('admin'=

在上面的代码中,“basic”auth可以正常工作,但当我将其更改为digest时,它会显示“notauthorized”。请注意,当我在这里进行更改时,我也将配置更改为摘要。

我的理解是基本的不是很安全?所以这就是为什么我认为消化会比它更好。有什么办法让我的消化系统工作吗??谢谢你的帮助。我想这可能不是特定于codeigniter的问题。


共1个答案

匿名用户

您可以省去一些麻烦,通过SSL使用基本身份验证。如果您没有使用SSL,那么我认为Digest将是一种方式。再说一次,如果您不使用SSL,您就不是真正安全的。

我将使用CURL测试您的REST服务器,以确定您的问题是在客户端还是服务器上

$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;