A little more progress. In identify() in my custom Identifier class, I am now returning an Identity object rather than just an array.
$data = [
'id' => $authPlatypus['contact']['id'],
'login_type' => 'customer',
'contact' => $authPlatypus['contact'],
'customer' => $authPlatypus['customer'],
];
$identity = new Identity($data);
return $identity;
Then I added some temporary debug logging to vendor/cakephp/authentication/src/AuthenticationService.php to see what is happening.
getIdentity() gets the data from _result. Data looks ok.
2025-09-04 18:15:10 debug: Authentication\AuthenticationService->getIdentity() $this->_result = \Authentication\Authenticator\Result::__set_state(array(
'_status' => 'SUCCESS',
'_data' =>
\Authentication\Identity::__set_state(array(
'_defaultConfig' =>
array (
'fieldMap' =>
array (
'id' => 'id',
),
),
'data' =>
array (
'id' => 1000,
'login_type' => 'customer',
'contact' =>
array (
'id' => 1000,
'custid' => 14175,
'first_name' => 'Jim',
'last_name' => 'Lohiser',
'role' => 'Administrative',
),
'customer' =>
array (
'id' => 14175,
'name' => 'Jim Lohiser',
'username' => 'jiml',
'password' => '********',
),
),
'_config' =>
array (
'fieldMap' =>
array (
'id' => 'id',
),
),
'_configInitialized' => true,
)),
'_errors' =>
array (
),
))
getIdentity() then strips out the Identity object, puts it into $identityData, and then passes that to buildIdentity(). buildIdentity() checks to see if it is already an Identity object (it is) and then simply returns $identityData back to getIdentity(). getIdentity() ultimately returns the data in $identityData.
2025-09-04 18:15:10 debug: Authentication\AuthenticationService->getIdentity() $identityData = \Authentication\Identity::__set_state(array(
'_defaultConfig' =>
array (
'fieldMap' =>
array (
'id' => 'id',
),
),
'data' =>
array (
'id' => 1000,
'login_type' => 'customer',
'contact' =>
array (
'id' => 1000,
'custid' => 14175,
'first_name' => 'Jim',
'last_name' => 'Lohiser',
'role' => 'Administrative',
),
'customer' =>
array (
'id' => 14175,
'name' => 'Jim Lohiser',
'username' => 'jiml',
'password' => '********',
),
),
'_config' =>
array (
'fieldMap' =>
array (
'id' => 'id',
),
),
'_configInitialized' => true,
))
However, the next debug log is from the login() function in the controller right after it passes the authentication.
$result = $this->Authentication->getResult();
Log::debug('Authentication->getResult() = '.var_export($result, TRUE));
// If the user is logged in send them away.
if ($result && $result->isValid()) {
Log::debug('Authentication->getIdentity() = '.var_export($this->Authentication->getIdentity(), TRUE));
Log::debug('Authentication->getIdentifier() = '.var_export($this->Authentication->getIdentifier(), TRUE));
return $this->redirect('/dashboard');
}
And getIdentity() is now NULL.
2025-09-04 18:15:11 debug: Authentication->getIdentity() = NULL
Something is happening between these few lines of code above that seems to be causing the identity to be lost.