Package com.auth0.jwk

Class JwkProviderBuilder

java.lang.Object
com.auth0.jwk.JwkProviderBuilder

public class JwkProviderBuilder extends Object
JwkProvider builder
  • Constructor Details

    • JwkProviderBuilder

      public JwkProviderBuilder(URL url)
      Creates a new Builder with the given URL where to load the jwks from.
      Parameters:
      url - to load the jwks
      Throws:
      IllegalStateException - if url is null
    • JwkProviderBuilder

      public JwkProviderBuilder(String domain)
      Creates a new Builder with a domain where to look for the jwks.

      It can be a url link 'https://samples.auth0.com' or just a domain 'samples.auth0.com'. If the protocol (http or https) is not provided then https is used by default. The default jwks path "/.well-known/jwks.json" is appended to the given string domain.

      For example, when the domain is "samples.auth0.com" the jwks url that will be used is "https://samples.auth0.com/.well-known/jwks.json"

      Use JwkProviderBuilder(URL) if you need to pass a full URL.
      Parameters:
      domain - where jwks is published
      Throws:
      IllegalStateException - if domain is null
      See Also:
  • Method Details

    • cached

      public JwkProviderBuilder cached(boolean cached)
      Toggle the cache of Jwk. By default, the provider will use a cache size of 5 and a duration of 10 hours.
      Parameters:
      cached - if the provider should cache jwks
      Returns:
      the builder
    • cached

      public JwkProviderBuilder cached(long cacheSize, Duration expiresIn)
      Enable the cache specifying size and expire time.
      Parameters:
      cacheSize - number of jwk to cache
      expiresIn - amount of time the jwk will be cached
      Returns:
      the builder
    • cached

      public JwkProviderBuilder cached(long cacheSize, long expiresIn, TimeUnit unit)
      Enable the cache specifying size and expire time.
      Parameters:
      cacheSize - number of jwk to cache
      expiresIn - amount of time the jwk will be cached
      unit - unit of time for the expire of jwk
      Returns:
      the builder
    • rateLimited

      public JwkProviderBuilder rateLimited(boolean rateLimited)
      Toggle the rate limit of Jwk. By default the Provider will use rate limit.
      Parameters:
      rateLimited - if the provider should rate limit jwks
      Returns:
      the builder
    • rateLimited

      public JwkProviderBuilder rateLimited(long bucketSize, long refillRate, TimeUnit unit)
      Enable the cache specifying size and expire time.
      Parameters:
      bucketSize - max number of jwks to deliver in the given rate.
      refillRate - amount of time to wait before a jwk can the jwk will be cached
      unit - unit of time for the expire of jwk
      Returns:
      the builder
    • proxied

      public JwkProviderBuilder proxied(Proxy proxy)
      Sets the proxy to use for the connection.
      Parameters:
      proxy - proxy server to use when making this connection
      Returns:
      the builder
    • timeouts

      public JwkProviderBuilder timeouts(int connectTimeout, int readTimeout)
      Sets a custom connect and read timeout values. When this method is not called, the default timeout values will be those defined by the UrlJwkProvider implementation.
      Parameters:
      connectTimeout - connection timeout in milliseconds.
      readTimeout - read timeout in milliseconds.
      Returns:
      the builder
      See Also:
    • headers

      public JwkProviderBuilder headers(Map<String,String> headers)
      Sets the headers to send on the request. Any headers set here will override the default headers ("Accept": "application/json")
      Parameters:
      headers - a map of header keys to values to send on the request.
      Returns:
      this builder instance
    • build

      public JwkProvider build()
      Creates a JwkProvider
      Returns:
      a newly created JwkProvider