CakePHP 3 Rest Api JWT plugin Form login Not working -


i using admad/cakephp-jwt-auth plugin json web token authentication rest api.

for token generation sending email , password login via form . fails don't issue.

here settings. in appcontroller.php

$this->loadcomponent('auth', [             'form' => [                             'fields' => [                                     'username' => 'email',                                     'password' => 'password'                             ]              ],             'authenticate' => [                     'admad/jwtauth.jwt' => [                             'parameter' => '_token',                             'usermodel' => 'users',                             'scope' => ['users.active' => 1],                             'fields' => [                                     'id' => 'id'                             ]                     ]             ],             'unauthorizedredirect' => false,             // config below available since cakephp 3.1.             // makes user info available in controller's beforefilter() not possible in cakephp 3.0.             'checkauthin' => 'controller.initialize',     ]); 

userscontroller token generation method script;

public function token(){     $user = $this->auth->identify();     if (!$user) {         throw new unauthorizedexception('invalid email or password');     }          $this->set([             'success' => true,             'data' => [                 'token' => $token = \jwt::encode([                     'id' => $user['id'],                     'exp' =>  time() + 604800                 ],                 security::salt())             ],             '_serialize' => ['success', 'data']         ]); }    

the json data posting is

{  'email' : 'muni@smart.com', 'password': '123' } 

please me mistake?

form must in authenticate

 $this->loadcomponent('auth', [                 'authenticate' => [                     'form' => [                         'fields' => [                             'username' => 'email',                             'password' => 'password'                         ]                     ],                     'admad/jwtauth.jwt' => [                         'parameter' => '_token',                         'usermodel' => 'users',                         'fields' => [                               'id' => 'id'                         ]                 ]             ]         ]); 

Comments