NoWayJose.Jwks.HttpClient behaviour (NoWayJose v1.0.2)
View SourceBehaviour for HTTP clients used by JWKS fetchers.
The default implementation uses Req (if available). You can provide
a custom implementation by passing the :http_client option to
NoWayJose.start_jwks_fetcher/3.
Options
The following options are supported by the default implementation:
:timeout- Connection and receive timeout in milliseconds (default: 30000):connect_options- Options passed toReq's:connect_options, including::transport_opts- Options for the underlying socket, such as SSL settings
SSL Configuration
To disable SSL certificate verification (useful for self-signed certificates in development/staging environments):
NoWayJose.start_jwks_fetcher("auth0", url,
http_opts: [
connect_options: [
transport_opts: [verify: :verify_none]
]
]
)To use a custom CA certificate:
NoWayJose.start_jwks_fetcher("auth0", url,
http_opts: [
connect_options: [
transport_opts: [
verify: :verify_peer,
cacertfile: "/path/to/ca-cert.pem"
]
]
]
)Custom Implementation
To implement a custom HTTP client:
defmodule MyApp.HttpClient do
@behaviour NoWayJose.Jwks.HttpClient
@impl true
def fetch(url, opts) do
case HTTPoison.get(url, [], opts) do
{:ok, %{status_code: 200, body: body}} -> {:ok, body}
{:ok, %{status_code: status}} -> {:error, {:http_error, status}}
{:error, reason} -> {:error, reason}
end
end
endThen use it:
NoWayJose.start_jwks_fetcher("auth0", url,
http_client: MyApp.HttpClient
)
Summary
Callbacks
Fetches the content at the given URL.
Functions
Default implementation using Req.
Types
@type body() :: String.t()
@type error() :: {:http_error, non_neg_integer()} | term()
@type opts() :: keyword()
@type url() :: String.t()