livery_auth_jwks (livery v0.2.0)

View Source

JWKS fetching, parsing, and caching with key rotation.

keys/1,2 returns the JWK set for a jwks_uri, fetching it over HTTP on first use and caching the result in persistent_term with a TTL. refresh/1,2 forces a re-fetch — call it on a no_matching_key verification failure to pick up a rotated key.

The HTTP fetch is pluggable via fetch => fun((Url) -> {ok, Body} | {error, _}) in the options, so deployments (and tests) can supply their own client. The default uses hackney and verifies the server's TLS certificate.

{ok, Keys} = livery_auth_jwks:keys(<<"https://issuer/.well-known/jwks.json">>),
{ok, Claims} = livery_auth:verify(Token, #{keys => Keys, issuer => Iss}).

Summary

Functions

Default JWKS fetcher using hackney, verifying the server's TLS cert.

Parse a JWKS document (binary or decoded map) into a key list.

JWK set for JwksUri, cached with the default 5-minute TTL.

JWK set for JwksUri. Honors fetch and ttl options.

Force a re-fetch of JwksUri, replacing the cached entry.

Types

opts()

-type opts() ::
          #{fetch => fun((binary()) -> {ok, binary()} | {error, term()}), ttl => non_neg_integer()}.

Functions

default_fetch(Url)

-spec default_fetch(binary()) -> {ok, binary()} | {error, term()}.

Default JWKS fetcher using hackney, verifying the server's TLS cert.

from_json/1

-spec from_json(binary() | map()) -> {ok, [livery_auth:jwk()]} | {error, term()}.

Parse a JWKS document (binary or decoded map) into a key list.

keys(JwksUri)

-spec keys(binary()) -> {ok, [livery_auth:jwk()]} | {error, term()}.

JWK set for JwksUri, cached with the default 5-minute TTL.

keys(JwksUri, Opts)

-spec keys(binary(), opts()) -> {ok, [livery_auth:jwk()]} | {error, term()}.

JWK set for JwksUri. Honors fetch and ttl options.

refresh(JwksUri)

-spec refresh(binary()) -> {ok, [livery_auth:jwk()]} | {error, term()}.

Force a re-fetch of JwksUri, replacing the cached entry.

refresh(JwksUri, Opts)

-spec refresh(binary(), opts()) -> {ok, [livery_auth:jwk()]} | {error, term()}.