【问题标题】:Cakephp - Custom authentification (basicauth) in a pluginCakephp - 插件中的自定义身份验证(基本身份验证)
【发布时间】:2013-11-10 08:14:25
【问题描述】:

我目前正在为我的网站开发一个 Restfull API。 我决定把它开发成一个插件。

我正在使用扩展 BasicAuthentification 的自定义类。它允许我检查客户端应用凭据,以便将 API 的使用限制为仅限于经过批准的开发人员。

此文件在添加到 CakePHP CORE 时完美运行:Cake/Controller/Component/Auth/DeviceAuthentification.php

由于我正在开发一个插件,我希望所有内容都在同一个目录中。 因此,在名为MyApi 的插件目录中,我在以下路径中添加了我的自定义类:

MyApi/Controller/Auth/DeviceAuthentification.php

为了加载它,在我的插件控制器MyApiAppController 中,我添加了以下代码:

public $components = array(
    'Auth' => array(
        'authenticate' => 'Device', // I also tried MyApi.Device
        'sessionKey' => false
    )

);

加载不出来,报错如下:

未找到身份验证适配器“设备”。

有人有想法吗?

【问题讨论】:

    标签: cakephp plugins basic-authentication restful-authentication


    【解决方案1】:

    嗯,看了下核心文件AuthComponent,看来你需要有如下路径:

    MyApi/Controller/组件/Auth/DeviceAuthentification.php

    而不是

    MyApi/Controller/Auth/DeviceAuthentification.php

    因此,每当您在插件目录中工作时,都需要添加目录Component

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-12
      • 2011-03-18
      • 2020-04-01
      • 2022-12-10
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      相关资源
      最近更新 更多