use apivalk\apivalk\Security\Authenticator\AuthenticatorInterface;use apivalk\apivalk\Security\AuthIdentity\AbstractAuthIdentity;use apivalk\apivalk\Security\AuthIdentity\JwtAuthIdentity;
class ApiKeyAuthenticator implements AuthenticatorInterface
{
public function authenticate(string $token): ?AbstractAuthIdentity
{
// 1. Check if the API key exists in your database
$user = $this->db->findUserByApiKey($token);
if (!$user) {
return null;
}
// 2. Return a JwtAuthIdentity (or a custom identity class)
return new JwtAuthIdentity(
$user->username,
$user->email,
(string)$user->id,
$user->getScopes(),
$user->getPermissions()
);
}
}