rederlo / t-auth
Auth plugin for CakePHP
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=5.5.9
- admad/cakephp-jwt-auth: ^2.0
- cakephp/cakephp: 3.3.*
- cakephp/plugin-installer: *
- firebase/php-jwt: ~4.0
Requires (Dev)
This package is not auto-updated.
Last update: 2025-03-07 21:09:01 UTC
README
in config/bootstrap.php
//Enable Cors DispatcherFactory::add('TAuth.Cors', ['priority' => 1]); //Enable plugin Plugin::load('TAuth', ['bootstrap' => false, 'routes' => false]);
in src/AppController.php
use \TAuth\Controller\AuthTrait;
public function initialize() { parent::initialize(); $auth = new \TAuth\Controller\AuthBuilder([ 'model' => 'peoples', 'scope_auth' => ['username' => 'email'], 'scope_jwt' => ['username' => 'id'] ]); $this->loadComponent('Auth', $auth->getConfig()); }
is get user id
public function getUserId() { return $this->getUser(); }
Generate database
bin/cake migrations migrate --plugin TAuth
Generate data in tables
bin/cake migrations seed --seed <fileSeed> --plugin TAuth
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.')); } }
Authorized
/** * @param $user * @return bool */ public function isAuthorized($user) { return (new Authorize($this, $user['id']))->exec(); }
Params token
$auth = new AuthFactory(); $auth->create($users, ['group_id' => $group_id]);
GetParamsToken
/** * @return Array */ $this->getParamsHeader();