解释
尝试将此OAuth2插件用于CakePHP:
https://github.com/thomseddon/cakephp-oauth-server
按照说明操作,现在转到此网址:
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中,OAuthAppController,OAuthController(全部在beforeFilter中):
$this->OAuth->authenticate = array(
'userModel' => 'Members',
'fields' => array(
'username' => 'email'
)
);
我们已经尝试将其更改为所有这些地方的新格式,例如我的AppModel中的初始$ components数组:
$this->OAuth->authenticate = array(
'Form' => array(
'passwordHasher' => 'Blowfish',
'fields' => array('username'=>'email', 'password'=>'password'),
)
);
闭合:
此时,我正在寻找任何方式(除了修改实际的CakePHP核心)以使其能够使用email
而不是username
登录(并希望将它从Blowfish恢复为Simple也将解决同样的问题。
我们已经尝试过大量修改OAuth插件(无济于事)并且不反对再次尝试,但我们无法弄清楚要改变什么。
答案 0 :(得分: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;