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
encode
? Can you find it and link it here? – gmponos