Class JwksOptions

java.lang.Object
com.jsgalactic.axiom.security.jwt.JwksOptions

public final class JwksOptions extends Object
Bounds and timings for a JSON Web Key Set used by JwtAuthenticator, set with JwtAuthenticator.Builder.jwks(JwksSource, JwksOptions). Immutable; every method returns a changed copy.
Settings
SettingDefaultRangeMeaning
maxBytes64 KiB1 KiB to 1 MiBlongest accepted document; at most 100 keys
refreshInterval10 minutes1 second to 24 hoursage after which the set is refetched
minRefreshInterval30 seconds1 second to the refresh intervalshortest time between fetch attempts, successful or not
maxStale24 hoursthe refresh interval to 7 dayshow long the last good set stays usable while fetches fail
defaultAlgorithmnone-algorithm for keys that declare no alg
  • Method Details

    • defaults

      public static JwksOptions defaults()
      Returns the default settings.
      Returns:
      the defaults
    • maxBytes

      public JwksOptions maxBytes(int bytes)
      Sets the longest accepted key set document.
      Parameters:
      bytes - 1,024 to 1,048,576
      Returns:
      a changed copy
    • refreshInterval

      public JwksOptions refreshInterval(Duration interval)
      Sets the age after which the next token triggers a refetch. Tokens keep being verified with the previous set while the refetch is running or failing.
      Parameters:
      interval - 1 second to 24 hours, whole seconds
      Returns:
      a changed copy
    • minRefreshInterval

      public JwksOptions minRefreshInterval(Duration interval)
      Sets the shortest time between two fetch attempts, successful or not. It bounds the load a stream of tokens with unknown key IDs can put on the key set endpoint, and the retry rate while the endpoint fails.
      Parameters:
      interval - 1 second up to the refresh interval, whole seconds
      Returns:
      a changed copy
    • maxStale

      public JwksOptions maxStale(Duration age)
      Sets how long a key set stays usable after its last successful fetch while later fetches fail. After that no key of the set verifies a token (fail closed), so a revoked key cannot outlive an unreachable endpoint forever.
      Parameters:
      age - the refresh interval up to 7 days, whole seconds
      Returns:
      a changed copy
    • defaultAlgorithm

      public JwksOptions defaultAlgorithm(JwsAlgorithm algorithm)
      Sets the algorithm for keys of the set that declare no alg (some issuers omit it). Without it such keys are skipped, because an RSA key alone does not say whether it is meant for RS256 or PS256. The algorithm must fit the key type; a key of another type is skipped. A key that declares an alg always keeps its own.
      Parameters:
      algorithm - an RS, PS, ES or EdDSA algorithm
      Returns:
      a changed copy