rederlo / cake-auth-jwt
CakePHP plugin for authenticating using JSON Web Tokens and others features
dev-master
2017-04-13 17:46 UTC
Requires
- php: >=5.4
- admad/cakephp-jwt-auth: ^2.0
- cakephp/cakephp: 3.3.*
- cakephp/plugin-installer: *
- firebase/php-jwt: ~4.0
Requires (Dev)
- phpunit/phpunit: <6.0
This package is not auto-updated.
Last update: 2025-03-02 05:13:34 UTC
README
composer require rederlo/cake-auth-jwt
Config
// src/AppController.php use AuthTrait; public function initialize() { parent::initialize(); Auth::create($this, [ 'model' => 'Users', 'scope_auth' => ['username' => 'email'], 'scope_jwt' => ['username' => 'id'], ]); }
#cross-origin HTTP request use https://github.com/rederlo/cakephp-cors
New User
public function add() { $users = $this->Users->newEntity(); if($this->request->is('post')){ $users = $this->Users->patchEntity($users, $this->request->data()); if ($this->Users->save($users)) { $auth = new AuthFactory(); //Expected Type Entity $auth->create($users); $token = $auth->build(); } } $this->set(compact('token')); $this->set('_serialize', ['token']); }
Login
public function login() { if ($this->request->is('post')) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); return $this->redirect($this->Auth->redirectUrl()); } $this->Flash->error(__('Usernamme or password ínvalid, try again.')); } }
Params token
$auth = new AuthFactory(); $auth->create($users, ['group_id' => $group_id]);
GetParamsToken
/** * @return Array */ $this->getParamsHeader();