简体   繁体   English

CodeIgniter 2.2.0 + ION_Auth + Restful API

[英]CodeIgniter 2.2.0 + ION_Auth + Restful API

I'm using code igniter 2.2.0 with ion_auth library to authenticate my users but now I need to create some restful services and i want to use this library. 我正在将代码igniter 2.2.0与ion_auth库一起使用来验证我的用户,但是现在我需要创建一些Restful服务,并且我想使用库。 I saw that in rest.php I can change the rest_auth parameter to 'digest' and that I can define the auth_source as a 'library', the problem is that I don't know if I can set ion_auth library as authentication library. 我在rest.php中看到可以将rest_auth参数更改为“ digest”,并且可以将auth_source定义为“ library”,问题是我不知道是否可以将ion_auth库设置为身份验证库。

1- On my /application/confing/rest.php file I set those prefs: 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- I created a new function on /application/libraries/ion_auth 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;
}

Then I tried to connect to my example service but the answer was: 然后,我尝试连接到示例服务,但答案是:

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

I tried to do some debug on my server and I think that the problem is that the get_hashed_password() function should return the password using md5 and if I get the password directly from the database ion_auth is using bcrypt. 我试图在服务器上进行一些调试,我认为问题是get_hashed_pa​​ssword()函数应该使用md5返回密码,如果我直接从数据库获取密码,ion_auth使用的是bcrypt。 I think that this is the reason why the digest['response'] and the valid_response variables from REST_controller in line number 1411 are not equal. 我认为这就是为什么1411行中REST_controller的digest ['response']和valid_response变量不相等的原因。

I also tried to force REST_crontroller to accept the credentials (I know that it's not correct but I was doing some tests) then my problem is that I'm always getting the following error: 我还尝试强制REST_crontroller接受凭据(我知道这是不正确的,但是我正在做一些测试),然后我的问题是我总是遇到以下错误:

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

Anyone knows how to make It work? 任何人都知道如何使其工作吗?

Thanks for your help! 谢谢你的帮助!

For digest authentication the library function should return already stored md5(username:restrealm:password) for that username | 对于摘要身份验证,库函数应为该用户名返回已存储的md5(username:restrealm:password)。 Eg: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2' 例如:md5('admin:REST API:1234')='1e957ebc35631ab22d5bd6526bd14ea2'

I tried and I passed : try to return MD5('$login:REST API:$password'); 我尝试并通过了:尝试返回MD5('$ login:REST API:$ password'); where $login is your login et $password is the password 其中$ login是您的登录名,而$ password是密码

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

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