问题描述
我使用插件BzUtils插件创建令牌进行身份验证。
file boostrapt:
CakePlugin :: load('BzUtils');
文件AppController:
public function beforeFilter(){
$ this-& Auth-> authenticate = array(
'Form'=> array(
'fields'=> array(
'username'=>'username',
'password'=>'password'
),
'userModel'=>'User',
'scope'=& => 1,
),
),
'BzUtils.JwtToken'=> array(
'fields'=& >'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。'));
}
}
网址:
错误:致命错误:在第42行上的C:\ xampp \htdocs\koreconx\app\Controller\RestUsersController.php中找不到类'JWT'
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
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]
这篇关于如何通过Token在cakephp2与BzUtils插件验证。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!