Switon's JWT contract for application services that want HMAC-signed tokens, kid-based key selection, and exp/nbf
checks.
- Token issuing and validation:
JwtInterfacecovers both sides of the JWT flow. - Per-token signing keys: tokens can carry a key ID, and decode can use it to select the matching signing key.
- Claim policy: issued tokens get consistent
expandnbfclaims. - Validation policy: signatures and standard claim checks are enforced together.
- Clear failure types: invalid tokens surface as specific exceptions.
composer require switon/jwtuse Switon\Core\Attribute\Autowired;
use Switon\Jwt\JwtInterface;
class AuthService
{
#[Autowired] protected JwtInterface $jwt;
public function issueForTenant(int $userId, string $kid): string
{
return $this->jwt->encode(['user_id' => $userId], 3600, $kid);
}
public function authenticate(string $token, string $kid): array
{
return $this->jwt->decode($token, $kid);
}
}Docs: https://docs.switon.dev/latest/jwt
MIT.