简体   繁体   中英

method specific authentication in 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.

"philsturgeon Phil Sturgeon Why do people ask questions about my code on StackOverflow 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();
}

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