如何使用BzUtils插件在cakephp2中通过Token进行身份验证


how to authenticate by Token in cakephp2 with BzUtils plugin.?

我使用插件BzUtils插件创建令牌进行身份验证。文件boostrapt:

CakePlugin:负载(BzUtils);

文件有:

public function beforeFilter() {
        $this->Auth->authenticate = array(
            'Form' => array(
                'fields' => array(
                    'username' => 'username',
                    'password' => 'password'
                ),
                'userModel' => 'User',
                'scope' => array(
                    'User.active' => 1,
                )
            ),
            'BzUtils.JwtToken' => array(
                'fields' => array(
                    'username' => 'username',
                    'password' => 'password',
                ),
                'header' => 'AuthToken',
                'userModel' => 'User',
                'scope' => array(
                    'User.active' => 1
                )
            )
        );

和操作登录在RestUsersController:

public function login() {
        if ($this->Auth->login()) {
            $user = $this->Auth->user();
            $token = JWT::encode($user, Configure::read('Security.salt'));
            $this->set('user', $user);
            $this->set('token', $token);
            $this->set('_serialize', array('user', 'token'));
        } else {
            throw new NotAcceptableException(__('Email or password is wrong.'));
        }
    }

的Url: http://kcxcode1.dev/restusers/login

错误:致命错误:在C:'xampp'htdocs'koreconx'app'Controller'RestUsersController.php第42行中没有找到Class 'JWT'

错误:Fatal Error: Class 'JWT' not found in

这个错误很明显。您需要适配器中使用的php-jwt库。通过编写器添加或手动添加。

composer require firebase/php-jwt   

我已经更新了插件编写器。Json与该依赖关系,但只有建议在那里。我也更新了自述文件。Md,在那里添加了适配器和一个关于它的文章的链接。并且我已经把develop和master合并了。

看起来你在使用我的文章,它在第二段提到php-jwt是需要的,甚至链接到它。

对不起,我弄错了Declaration of JwtTokenAuthenticate::getUser() should be compatible with BaseAuthenticate::getUser($request) [APP'Plugin'BzUtils'Controller'Component'Auth'JwtTokenAuthenticate.php, line 123]