How would you pass back a custom error code or message from a custom authenticator using Tuupolas Basic Authenticator? Obviously my example below is pulled completely out of thin air and would never work, but I think you get what I mean? Somehow, there must be a way to pass a message from here, back to the error handler, or alter the $arguments? Any tips?
class DbAuthenticator implements AuthenticatorInterface {
public function __invoke(array $arguments) {
if (wrongPassword($user, $pass)) {
==> $returnThisMessageSomeHow = "Invalid password";
$failedLogins = $failedLogins + 1;
return false;
}
if (invalidUsername($user, $pass)) {
==> $returnAmessageSomeHow = "Invalid username";
return false;
}
}
}
then…
$container["HttpBasicAuthentication"] = function ($container) {
return new HttpBasicAuthentication([
"path" => [ ... ],
"authenticator" => new DbAuthenticator(),
"error" => function ($request, $response, $arguments) {
$data = [];
$data["status"] = "error";
==> $data["message"] = $messageReturnedFromAuthenticatorSomehow;
return $response->write(json_encode($data, JSON_UNESCAPED_SLASHES));
}
]);
};