2

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

我已经使用上面的 rest 服务器创建了一个 api,现在需要登录保护它。我知道其余服务器中有两种方法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'] = array('admin' => '1234');

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

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

4

1 回答 1

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;
于 2013-11-16T14:14:27.827 回答