【问题标题】:Cannot use 'email' field instead of 'username' in OAuth2 Plugin for CakePHP无法在 CakePHP 的 OAuth2 插件中使用“电子邮件”字段而不是“用户名”
【发布时间】:2013-12-21 07:53:56
【问题描述】:

说明:

尝试将此 OAuth2 插件用于 CakePHP:

https://github.com/thomseddon/cakephp-oauth-server

已按照说明进行操作,现在转到此 URL:

http://mysite/oauth/login?response_type=code&client_id=NGYcZDRjODcxYzFkY2Rk&
    redirect_url=http%3A%2F%2Fwww.return_url.com

(我们在数据库中创建了一个客户端,其信息与他在示例中使用的信息相同)

它会为电子邮件和密码打开一个登录框,但每次都无法通过身份验证。我相信它失败了,因为当它到达Cake's FormAuthenticate->authenticate() method 时,设置已恢复为'username'=>'username''passwordHasher'=>'Simple'

如果我们将这些行添加到FormAuthenticate$fields = ... 上方):

$this->settings['fields']['username'] = 'email';
$this->settings['passwordHasher'] = 'Blowfish';

然后登录成功。

我们尝试过的事情:

把它放在我们的 AppController 中,OAuthAppControllerOAuthController(都在 beforeFilter 中):

$this->OAuth->authenticate = array(
    'userModel' => 'Members',
    'fields' => array(
        'username' => 'email'
    )
);

我们已经尝试在所有这些地方以及在我的 AppModel 中的初始 $components 数组中将其更改为新格式,例如 2.3:

$this->OAuth->authenticate = array(
    'Form' => array(
        'passwordHasher' => 'Blowfish',
        'fields' => array('username'=>'email', 'password'=>'password'),
    )
);

结束:

此时,我正在寻找任何方法(除了修改实际的 CakePHP 核心)以使其能够使用 email 而不是 username 登录(希望这能解决同样的问题将其从 Blowfish 恢复为 Simple 也存在问题。

我们已经尝试大量修改 OAuth 插件(无济于事)并且不反对再次尝试,但我们不知道要更改什么。

【问题讨论】:

标签: php cakephp authentication oauth-2.0 cakephp-2.3


【解决方案1】:

而不是在 OAuthController 中使用它:

$this->OAuth->authenticate = array(
    'Form' => array(
        'passwordHasher' => 'Blowfish',
        'fields' => array('username'=>'email', 'password'=>'password'),
    )
);

把它改成这个(注意去掉“O”,这样它就会调用常规的“Auth”):

$this->Auth->authenticate = array(
    'Form' => array(
        'passwordHasher' => 'Blowfish',
        'fields' => array('username'=>'email', 'password'=>'password'),
    )
);

或者,更进一步,在您自己的 AppController 中设置您的 $this->OAuth->authenticate 数组,然后在 OAuthController 中执行此操作(而不是上面的):

$this->Auth->authenticate = $this->OAuth->authenticate;

【讨论】:

  • brigevans 是天才。你甚至不知道我们花了多长时间试图让它工作......谢谢。
猜你喜欢
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-01
  • 2021-06-01
  • 1970-01-01
  • 2012-02-06
相关资源
最近更新 更多