[英]Code Igniter - Consuming my own API and authorisation
我試圖將我的HMVC codeigniter安裝程序構建到以API為中心的HMVC中(是的,我知道!)
我現在有ion_auth作為授權系統。
我的設置方式是
MODELS
CONTROLLERS
- API CONTROLLER
- CONTROLLER
VIEWS
使用API控制器可以接受JSON編碼的輸入並發送JSON編碼的輸出。
現在-一切正常->我可以通過調用controller/api
來訪問API,並可以將其傳遞JSON並接收回JSON。
然后,我只需從普通controller
調用控制器/ api
我的問題現在來自授權。
如果沒有通過Ion_auth登錄(因此很安全),則沒有人可以訪問API
然后如何公開API?
我想我需要遵循O Auth
但是我一直束手無策,試圖讓我了解如何使用O Auth作為API,並且在通過控制器訪問應用程序時不影響應用程序的性能。
原因是不了解O Auth的工作原理(我可以實現它並理解握手等,但是有點棘手)->如果我找到了某種通過O Auth驗證用戶身份的方法(我的意思是站點用戶沒有API用戶)這如何傳遞到我的控制器-是否存儲在會話中? 我可以給我的控制器授權嗎? (我需要)
或-有沒有辦法使用我從未聽說過的Ion Auth做到這一點?
為了清晰
我希望自己的應用程序能夠使用它自己的API,但不知道如何設置身份驗證,以便API可以直接或本地由應用程序本身使用(當用戶使用網站時)
救命!!!!
提前致謝!
也許您可以刪除API的O auth並僅創建訪問密鑰表。 當有人調用API時,他需要在表中注冊的密鑰。 不是嗎
使用Promo的答案,再加上一點點思考后,他指出我所做的很明顯的是:
public function __construct()
{
parent::__construct();
//see if they logged in -> if they are no problem as they are obviously using the page through my application, if they aren't then we do checks for the API
if (!$this->authentication->logged_in())
{
$this->token = $this->input->get_post('token');
//API should have a token set before anything can happen, this is for every request
if($this->token){
//Check that the token is valid
if (!$this->checkToken($this->token)){
$this->error('Token did not match');
}
//all clear if we get to here - token matched
}else{ //no token was found
$this->error('No Token was sent');
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.