我已将我的应用程序从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和基本身份验证
发布评论