Cakephp 2.0和基本身份验证

编程入门 行业动态 更新时间:2024-10-24 07:30:47
本文介绍了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和基本身份验证

本文发布于:2023-11-16 18:30:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   Cakephp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!