NoWayJose.Jwks.Fetcher (NoWayJose v1.0.2)

View Source

GenServer that periodically fetches and caches JWKS from a remote endpoint.

Options

  • :name (required) - Unique identifier for this fetcher
  • :url (required) - JWKS endpoint URL
  • :refresh_interval - Refresh period in ms (default: 15 minutes)
  • :retry_interval - Retry period on failure in ms (default: 30 seconds)
  • :sync_init - Block until first fetch completes (default: false)
  • :http_client - Module implementing NoWayJose.Jwks.HttpClient behaviour
  • :http_opts - Options passed to the HTTP client

Telemetry Events

The fetcher emits the following telemetry events:

  • [:no_way_jose, :jwks, :fetch, :start] - Fetch started

    • Metadata: %{name: name, url: url}
  • [:no_way_jose, :jwks, :fetch, :stop] - Fetch completed successfully

    • Measurements: %{duration: native_time}
    • Metadata: %{name: name, url: url, key_count: count}
  • [:no_way_jose, :jwks, :fetch, :exception] - Fetch failed

    • Measurements: %{duration: native_time}
    • Metadata: %{name: name, url: url, reason: reason}

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the current state of the fetcher (for debugging).

Triggers an immediate refresh of the JWKS.

Starts a JWKS fetcher.

Returns the via tuple for a fetcher.

Types

option()

@type option() ::
  {:name, String.t()}
  | {:url, String.t()}
  | {:refresh_interval, non_neg_integer()}
  | {:retry_interval, non_neg_integer()}
  | {:sync_init, boolean()}
  | {:http_client, module()}
  | {:http_opts, keyword()}

options()

@type options() :: [option()]

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_state(name)

@spec get_state(String.t()) :: map()

Returns the current state of the fetcher (for debugging).

refresh(name)

@spec refresh(String.t()) :: :ok

Triggers an immediate refresh of the JWKS.

start_link(opts)

@spec start_link(options()) :: GenServer.on_start()

Starts a JWKS fetcher.

Examples

# Async start (returns immediately, fetches in background)
{:ok, pid} = NoWayJose.Jwks.Fetcher.start_link(
  name: "auth0",
  url: "https://example.auth0.com/.well-known/jwks.json"
)

# Sync start (blocks until first fetch completes)
{:ok, pid} = NoWayJose.Jwks.Fetcher.start_link(
  name: "google",
  url: "https://www.googleapis.com/oauth2/v3/certs",
  sync_init: true
)

via_tuple(name)

@spec via_tuple(String.t()) :: {:via, Registry, {NoWayJose.Jwks.Registry, String.t()}}

Returns the via tuple for a fetcher.