Cakephp 2.0和基本身份验证 [英] Cakephp 2.0 and basic auth

查看:77
本文介绍了Cakephp 2.0和基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的应用程序从CakePHP 1.3升级到2.0.4。

I've upgraded my app from CakePHP 1.3 to 2.0.4.

以前,我只能使用安全性组件来模拟基本HTTP身份验证。

Previously, I was able to use the Security component to emulate Basic HTTP authentication only in one controller.

我曾经做过这样的事情:

I used to do something like this:

$this->Auth->allow(array('*'));
$this->Security->loginOptions = array('type'=>'basic','realm'=>'api');
$this->Security->loginUsers = array("api"=>"123");
$this->Security->requireLogin();

现在SecurityComponent不再处理基本身份验证和摘要身份验证,我需要执行以下操作:

Now SecurityComponent no longer handles Basic and Digest Authentication and I need to do something like this:

public $components = array(
    'Auth' => array(
        'authenticate' => array('Basic')
    )
);

但是当我在ApiController上使用它时,它会重定向到/ users / login上的登录表单。我缺少什么吗?

But when I use this on my ApiController it redirects to my login form at /users/login. Am I missing something?

推荐答案

您需要使用登录操作配置AuthComponent。您应该查看配置蛋糕书中的身份验证处理程序

You need to configure the AuthComponent with your login action. You should check out the section on Configuring Authentication handlers in the Cake book.

您的设置可能类似于以下内容:

Your setup will probably look something similar to this:

public $components = array(
  'Auth'=> array(
    'loginAction' => array(
      'controller' => 'api',
      'action'     => 'login'
    ),
    'loginRedirect' => array(
      'controller' => 'api',
      'action'     => 'logged_on'
    ),
    'authenticate' => array(
      'Basic' => array(
        'realm' => 'api'
      )
    )
  )
);

此外,应注意,Cake不再支持使用 loginUsers定义用户属性。您可能必须扩展 BasicAuthenticate 类并覆盖其 getUser()方法。

Also, it should be noted that Cake no longer supports defining users using the loginUsers property. You would probably have to extend the BasicAuthenticate class and override it's getUser() method.

这篇关于Cakephp 2.0和基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆