简体   繁体   English

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

[英]Understanding digest authentication - CodeIgniter Rest Server

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

I have created an api using rest server above and need to login-protect it now. 我已经使用上面的rest服务器创建了一个api,现在需要对其进行登录保护。 I know there are two methods in the rest server 1) basic, 2) digest 我知道其余服务器中有两种方法1)基本,2)摘要

I am also using rest client to test this api 我也在使用Rest Client测试此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'); 

I have $config['rest_valid_logins'] = array('admin' => '1234'); 我有$config['rest_valid_logins'] = array('admin' => '1234');

In the above code the "basic" auth works fine but when I change it to digest it says "Not Authorised". 在上面的代码中,“基本”身份验证工作正常,但是当我将其更改为摘要时,它显示为“未授权”。 Please note when I make change here I also change config to digest too. 请注意,当我在此处进行更改时,我也将配置也更改为摘要。

My understanding is that basic is not very secure? 我的理解是基本不是很安全吗? so that's why I think digest be better than it. 所以这就是为什么我认为摘要要比它更好。 Any ideas how do I get digest working?? 任何想法如何使摘要工作? thanks for your help. 谢谢你的帮助。 It maynot be codeigniter specific issue, I guess. 我想这可能不是特定于Codeigniter的问题。

You might save yourself some trouble and use Basic authentication over SSL. 您可能会省去一些麻烦,并使用基于SSL的基本身份验证。 If you're not using SSL, then I suppose Digest would be the way to go. 如果您不使用SSL,那么我想Digest是您的最佳选择。 Then again, if you are not using SSL, you're not really secure. 再说一次,如果您不使用SSL,那么您并不是很安全。

I would test your REST server using CURL to figure out whether your problem is on the client or server 我会使用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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM