1
votes

I use plugin BzUtils plugin create token for authenticate. file boostrapt:

CakePlugin::load('BzUtils ');

file AppController:

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
                )
            )
        );

And action login in 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

Error : Fatal error: Class 'JWT' not found in C:\xampp\htdocs\koreconx\app\Controller\RestUsersController.php on line 42

2
Is this the plugin you are using? github.com/burzum/cakephp-bz-utilsgmponos
Yea I found the branch that is different. In this plugin/branch where is the static function encode? Can you find it and link it here?gmponos
I don't understand.. Help me fix error..I doing code api restful webservie with cakephp2 but I can not using any plugin.van tinh

2 Answers

0
votes

Error : Fatal error: Class 'JWT' not found in

The error is pretty obvious. You need the php-jwt lib that is used within the adapter. Add it via composer or manually add it.

composer require firebase/php-jwt   

I've updated the plugins composer.json with that depedency but only suggest it there. Also I've updated the readme.md, added the adapter there and a link to an article about it. And I've merged develop to master as well.

It looks like you're using my article, it mentions in the 2nd paragraph that php-jwt is needed and even links to it.

0
votes

Sorry you, I mistake Declaration of JwtTokenAuthenticate::getUser() should be compatible with BaseAuthenticate::getUser($request) [APP\Plugin\BzUtils\Controller\Component\Auth\JwtTokenAuthenticate.php, line 123]