【问题标题】:CodeIgniter 2.2.0 + ION_Auth + Restful APICodeIgniter 2.2.0 + ION_Auth + Restful API
【发布时间】:2015-01-23 16:31:22
【问题描述】:

我正在使用带有 ion_auth 库的 code igniter 2.2.0 来验证我的用户,但现在我需要创建一些安静的服务并且我想使用 this 库。我在rest.php中看到我可以将rest_auth参数更改为'digest'并且我可以将auth_source定义为'library',问题是我不知道我是否可以将ion_auth库设置为身份验证库。

1- 在我的 /application/confing/rest.php 文件中,我设置了这些首选项:

$config['rest_auth'] = 'digest';
$config['auth_source'] = 'library';
$config['auth_library_class'] = 'ion_auth';
$config['auth_library_function'] = 'get_hashed_password';
$config['rest_enable_keys'] = TRUE;

2- 我在 /application/libraries/ion_auth 上创建了一个新函数

public function get_hashed_password($username) {
    $user = $this->db->select('password')->where('email',$username)->get('users');
    if ($user->num_rows() == 0) {
        return false;
    }
    $user_details = $user->row();
    $HA1 = $user_details->password;
    return $HA1;
}

然后我尝试连接到我的示例服务,但答案是:

{"status":0,"error":"Invalid credentials"}

我试图在我的服务器上进行一些调试,我认为问题在于 get_hashed_pa​​ssword() 函数应该使用 md5 返回密码,如果我直接从数据库中获取密码,ion_auth 正在使用 bcrypt。我认为这就是第 1411 行中 REST_controller 中的 digest['response'] 和 valid_response 变量不相等的原因。

我还尝试强制 REST_crontroller 接受凭据(我知道它不正确,但我正在做一些测试)然后我的问题是我总是收到以下错误:

{"status":false,"error":"Invalid API Key "}

有人知道如何让它工作吗?

感谢您的帮助!

【问题讨论】:

  • 您如何测试控制器?您使用的是 curl 还是某种 REST 客户端。 (您如何将凭据发送到服务器)
  • 嗨,Kyslik!我尝试使用 cURL、一个名为 CocoaRestClient 的 Rest 客户端和 Safari 本身。
  • 您发送已经散列的密码?因为我在get_hashed_password 函数中看不到任何散列。
  • 不,那是我不知道如何正确做的事情????在 get_hashed_pa​​ssword 函数中,我从使用 bcrypt 加密的数据库中获取密码。

标签: php web-services codeigniter rest ion-auth


【解决方案1】:

对于摘要式身份验证,库函数应该为该用户名返回已存储的 md5(username:restrealm:password) |例如:md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2'

我试过了,我通过了: 尝试返回 MD5('$login:REST API:$password'); 其中 $login 是您的登录名, $password 是密码

【讨论】:

    猜你喜欢
    • 2014-02-27
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多