-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Labels
Description
How would you pass back a custom error message from a custom 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?
class DbAuthenticator implements AuthenticatorInterface {
private $settings;
public function __construct($settings) {
$this->settings = $settings;
}
public function __invoke(array $arguments) {
if (wrongPassword($user, $pass)) {
$returnAmessageSomeHow = "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($container['settings']),
"error" => function ($request, $response, $arguments) {
$data = [];
$data["status"] = "error";
$data["message"] = $messageReturnedFromAuthenticatorSomehow;
return $response->write(json_encode($data, JSON_UNESCAPED_SLASHES));
}
]);
};
Reactions are currently unavailable