Cakephp 3 HTTP基本身份验证登录问题

时间:2015-10-14 16:27:10

标签: cakephp authentication cakephp-3.0 http-basic-authentication

我在项目中使用基本身份验证来访问Api。在ApiController中,我在beforeFilter中添加了以下代码:

   $this->Auth->config('authenticate', [
       'Basic' => [
           'fields' => ['username' => 'username', 'password' => 'api_key'],
           'userModel' => 'Users'
       ]
   ]); 

因此,从chrome postman应用程序,我发送带有基本身份验证凭据的发布请求。例如如下: enter image description here

因此,当我发送请求时,我会收到未经授权的错误。

2 个答案:

答案 0 :(得分:0)

您要发送带有“密码”字段的帖子请求

您的应用程序需要一个包含密码的“api_key”字段。

答案 1 :(得分:0)

我认为你错过了模型实体中的这个脚本。

$( document ).ready(function(){
        $('table.display').DataTable({
            lengthChange: true,
            info: false,
            fixedHeader: true,
            select: true,
            "bAutoWidth": false,
            "bProcessing": true,
            "serverSide": true,         
            "ajax":{
                url :"tableresponses.php", // json datasource
                type: "post",  // type of method  , by default would be get
                    error: function(){  // error handling code
                    $("#astab_processing").css("display","none");
                    }
            }
        });   
});

将此文件放在Model / Entity / User.php

相关问题