douxu5233 2013-12-21 07:53
浏览 59
已采纳

不能在CakePHP的OAuth2插件中使用“email”字段而不是“username”

Explanation:

Attempting to use this OAuth2 Plugin for CakePHP:

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

Have followed the instructions, and am now going to this URL:

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

(We had made a client in the database with the same info he used in the example)

It brings up a log-in box for Email and Password, but fails authentication every time. I believe it's failing because by the time it gets to Cake's FormAuthenticate->authenticate() method, the settings have reverted to 'username'=>'username' and 'passwordHasher'=>'Simple'.

If we add these lines to the FormAuthenticate (above $fields = ...):

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

Then the log-in works successfully.

Things We've tried:

Putting this in our AppController, the OAuthAppController, the OAuthController (all in beforeFilter):

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

We've tried changing it to the new format like 2.3 in all of those places, as well as in the initial $components array in my AppModel:

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

Closing:

At this point, I'm looking for any way (other than modifying the actual CakePHP core) to get it to be able to log-in with email instead of username (and hopefully that will solve the same issue with having it revert from Blowfish to Simple as well.

We've already tried heavily modifying the OAuth Plugin (to no avail) and aren't opposed to trying that again, but we can't figure out what to change.

  • 写回答

1条回答 默认 最新

  • douciping4283 2013-12-21 08:18
    关注

    Instead of using this in the OAuthController:

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

    Change it to this (notice removal of the "O" so it calls the regular "Auth"):

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

    Or, take it a step further, and set your $this->OAuth->authenticate array in your own AppController, then, in the OAuthController do this (instead of the above):

    $this->Auth->authenticate = $this->OAuth->authenticate;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器