duanlan7239 2013-10-30 11:40
浏览 59
已采纳

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

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

I have created an api using rest server above and need to login-protect it now. I know there are two methods in the rest server 1) basic, 2) digest

I am also using rest client to test this 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');

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.

  • 写回答

1条回答 默认 最新

  • doulu5109 2013-11-16 14:14
    关注

    You might save yourself some trouble and use Basic authentication over SSL. If you're not using SSL, then I suppose Digest would be the way to go. Then again, if you are not using SSL, you're not really secure.

    I would test your REST server using CURL to figure out whether your problem is on the client or server

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧