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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!