简体   繁体   中英

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. 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.

1- On my /application/confing/rest.php file I set those prefs:

$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

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. 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.

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:

{"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 | Eg: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2'

I tried and I passed : try to return MD5('$login:REST API:$password'); where $login is your login et $password is the password

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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