dsegw3424 2018-02-07 06:23
浏览 75

请求标头缺少授权 - Codeigniter休息

I am creating a restful services with Codeigniter rest server and firebase php-jwt. Created an api to return list of operator. To access this api client has to send token in headers. Sample request is -

GET /index.php/operators/prepaid HTTP/1.1
Host: testing.mydomain.in
Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjExNTIxNCIsImlhdCI6MTUxNzk4MjU1NywiZXhwIjoxNTE4MDAwNTU3fQ.PZYh3OlSsKGo_ihPPSm7RrU5BbTNaeTN1fKlNcOZ2r4
Cache-Control: no-cache
Postman-Token: 933f3b1d-7934-d30a-11bf-f80f3912f433

controller code

use \Firebase\JWT\JWT;
class Operators extends REST_Controller 
{
    private $_payload;

    public function __construct($config = 'rest')
    {
        parent::__construct($config);
        $token = $this->input->get_request_header('Authorization');
        if(!$token) {
            $output = array("Error" => "Access Denied");
            $this->response($output, REST_Controller::HTTP_UNAUTHORIZED);
        }
        try {
            $this->_payload = JWT::decode($token, $this->config->item('jwt_secret_key'),array('HS256'));
        } catch (Exception $ex) {
            $output = array("Error" => $ex->getMessage());
            $this->response($output, REST_Controller::HTTP_UNAUTHORIZED);
        }
        $this->load->model('Operators_Data');
    }       

    public function prepaid_get()
    { 
        $operators = $this->Operators_Data->getOperatorsByService(1);
        $this->response($operators);
    }
}

I am getting the following result

{
     "Error": "Access Denied"
}

Returned from controller constructor if token is not present.But i am sending the token in header authorisation.

This is working on my local host (it returns list of operator). but when i trying from testing server it always returning "Access Denied".

UPDATE : Pretty sure that server is ignoring "Authorization" header.

Also tried with

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Settings in .htaccess

Any help is very much appreciated.

  • 写回答

1条回答 默认 最新

  • douhui8025 2019-02-28 17:46
    关注

    Adding

    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    

    at the top of the .htaccess file solved it in my case

    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢