Search code examples
authenticationcakephpcakephp-3.0stateless

Cakephp 3.7 - Auth Component: Get user in stateless authentication


When using a stateless authentication type (Basic or Digest), how can you access the user who was authenticated for the request?

With normal form authentication this is done with $this->Auth->user(), however when using Basic Authentication this always returns null, even when authentication was successful.


Solution

  • Good hint from @ndm, I was calling $this->Auth->user() to soon: I am loading the Auth component in AppController->initialize(), but apparently the user info is only available afterwards.