AlgoMaster Logo
AlgoMasterValidate JWT Time Claimseasy

Validate JWT Time Claims

easy

A JWT can carry three standard time claims: iat (issued at), nbf (not before), and exp (expiration). This exercise validates only those claims; assume the token's structure and signature have already been verified.

Design a JwtClaimValidator class:

  • JwtClaimValidator() creates a stateless validator.
  • boolean isValid(int iat, int nbf, int exp, int now) returns whether the token is valid at now.

A token is valid exactly when all three conditions hold:

The not-before boundary is inclusive. The expiration boundary is exclusive. No clock-skew allowance is applied.

Example 1:

Input:

Output:

Explanation: At time 50, the token has been issued, its validity window has begun, and its expiration time is still in the future.

Example 2:

Input:

Output:

Explanation: A token is expired when now == exp, so the strict expiration check fails.

Constraints

  • 0 <= iat, nbf, exp, now <= 2^31 - 1
  • Values are integer timestamps using the same unit.
  • nbf is inclusive and exp is exclusive.
  • Do not apply clock skew or validate signatures, audiences, issuers, or revocation.
  • At most 100 calls are made to isValid.
Hints

Loading...
CallReturns
new JwtClaimValidator()null
isValid(5, 10, 100, 50)true

The token was issued before now, its not-before time has passed, and its expiration is still in the future.

Run checks these cases. Submit also runs a larger hidden set.