[英]CodeIgniter 2.2.0 + ION_Auth + Restful API
我正在將代碼igniter 2.2.0與ion_auth庫一起使用來驗證我的用戶,但是現在我需要創建一些Restful服務,並且我想使用該庫。 我在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_password()函數應該使用md5返回密碼,如果我直接從數據庫獲取密碼,ion_auth使用的是bcrypt。 我認為這就是為什么1411行中REST_controller的digest ['response']和valid_response變量不相等的原因。
我還嘗試強制REST_crontroller接受憑據(我知道這是不正確的,但是我正在做一些測試),然后我的問題是我總是遇到以下錯誤:
{"status":false,"error":"Invalid API Key "}
任何人都知道如何使其工作嗎?
謝謝你的幫助!
對於摘要身份驗證,庫函數應為該用戶名返回已存儲的md5(username:restrealm:password)。 例如:md5('admin:REST API:1234')='1e957ebc35631ab22d5bd6526bd14ea2'
我嘗試並通過了:嘗試返回MD5('$ login:REST API:$ password'); 其中$ login是您的登錄名,而$ password是密碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.