Phil Sturgeons中的方法特定身份验证php codeigniter rest api

Phil Sturgeons中的方法特定身份验证php codeigniter rest api

问题描述:

Hi I know that I can set the rest authentication in Phil Sturgeons rest API, but I only want authentication for some methods in the REST API.

I want some of my methods to be accessible for everyone with no authentication at all, and others to only be accessible to administrators/people authenticated users.

In .net I can simply set a [RequiresAuthentication] attribute over methods in a webservice, is there something similar I can do with Rest PHP in CodeIgniter?

Or Controller specific would be fine too.

一些

嗨我知道我可以在Phil Sturgeons rest API中设置其余身份验证,但我只想要一些身份验证 REST API中的方法。 p>

我希望我的一些方法可供所有未经身份验证的人访问,而其他方法只能由管理员/经过身份验证的用户访问。 p >

在.net中我可以简单地在Web服务中设置[RequiresAuthentication]属性,在CodeIgniter中是否可以使用Rest PHP做类似的事情? p>

或者控制器特定也可以。 p> div>

"philsturgeon Phil Sturgeon Why do people ask questions about my code on * and random forums instead of just asking me?"

Go ask Phil Sturgeon.

Hello Jakob :) What you are trying to do is a bit tricky as Phil Sturgeons rest API Controller only supports setting the authentication method globally. To set it globaly you edit this line in the rest config file:

$config['rest_auth'] = '';

I have an untested theory though: To set this setting per controller make sure the setting in the config file is as above (empty) and add this constructor to the controller you would like to specify authentication method for:

function __construct()
{
    $this->load->config('rest');
    //$this->_prepare_basic_auth(); //Uncomment to use basic
    //$this->_prepare_digest_auth(); //Uncomment to use digest
    parent::Controller();
}