https://github.com/philsturgeon/codeigniter-restserver/
我已经使用上面的休息服务器创建了一个 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');
在上面的代码中,"基本"身份验证工作正常,但是当我将其更改为摘要时,它说"未授权"。请注意,当我在这里进行更改时,我也会将配置更改为摘要。
我的理解是基本不是很安全?所以这就是为什么我认为文摘比它更好。任何想法如何让摘要工作?感谢您的帮助。我猜这可能不是代码点火器特定的问题。
您可以省去一些麻烦,并通过 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;