How JWT::JWKS works and its validation flow
masterThe JWT::JWKS class provides a unified interface for both local token validation (using shared secrets for service-to-service JWTs) and remote token validation (using JWKS from external identity providers).
When validating a remote token, the library follows this flow:
- Extracts the header (
kid,alg,typ) and validates the type (JWTorat+jwt). - If not a local validation, it extracts the
iss(issuer) claim. - Fetches OIDC metadata via HTTPS (cached).
- Validates that the token's
issmatches the metadata'sissuer. - Fetches the JWKS (cached, HTTPS only).
- Finds the correct key using
kidorx5t. - Validates the algorithm against the JWK properties.
- Converts the JWK to PEM and validates the signature.
- Validates claims (
exp,nbf,iss,aud) using a configurable leeway for clock skew.