php - Checking logged-in user info on CakePHP when using a custom auth adapter -
i'm using this jwtauth adapter use jwt authentication instead of cookie-based auth in cakephp 2.8 app. works great, except 1 hitch:
normally 1 of rest endpoints, can use $this->auth->user("id")
logged-in users' id.
when try make controller action accessible non-members using $this->auth->allow()
, problem occurs. if this, using $this->auth->loggedin()
in controller returns false
, meaning can not add additional logic logged-in users.
when using standard cookie auth:
$this->auth->user('id')
available incontroller::beforefilter()
.$this->auth->loggedin()
true
incontroller::beforefilter()
.$this->auth->user('id')
available in controller actions, public , members-only.$this->auth->loggedin()
true
in controller actions, public , members-only.
when using jwt auth:
$this->auth->user('id')
null
incontroller::beforefilter()
.$this->auth->loggedin()
false
incontroller::beforefilter()
.$this->auth->user('id')
available in members-only controller actions, ,null
in public controller actions.$this->auth->loggedin()
true
in members-only controller actions, ,false
in public controller actions.
is there way can auth include information returned jwtauth component on actions have been made public $this->auth->allow()
?
example controller here:
public function visible(){ // false, if valid jwt token sent $this->set("loggedin", $this->auth->loggedin()); } public function members_only(){ // unavailable if not logged in, , true if logged in $this->set("loggedin", $this->auth->loggedin()); } public function beforefilter($options = array()){ parent::beforefilter(); $this->auth->allow("visible"); }
and reference, appcontroller::components array;
public $components = array( 'debugkit.toolbar', 'auth' => array( 'authorize' => array( 'actions' => array( 'actionpath' => 'controllers' ), ), 'authenticate' => array( 'form' => array( 'fields' => array('username' => 'email'), 'contain' => array( 'userprofile', ) ), 'jwtauth.jwttoken' => array( 'fields' => array( 'username' => 'email', 'token' => 'password', ), 'header' => 'authtoken', 'usermodel' => 'user', ), ), 'unauthorizedredirect' => false ), "acl", "requesthandler", "session" );
for stateless adapters authentication process triggerd in authcomponent::startup()
. component's startup()
methods run after controller::beforefilter()
, why authcomponent::user()
doesn't return info.
for other adapters when user authenticated identity info stored in session. getting info doesn't require authentication process why authcomponent::user()
give user info in case of standard cookie based auth.
Comments
Post a Comment