NoWayJose.Jwks (NoWayJose v1.0.2)
View SourceFunctions for working with JSON Web Key Sets (JWKS).
This module handles parsing JWKS JSON and looking up keys by kid.
Example
# Fetch JWKS JSON (user's responsibility)
{:ok, %{body: jwks_json}} = Req.get("https://example.com/.well-known/jwks.json")
# Parse the JWKS
{:ok, keys} = NoWayJose.Jwks.parse(jwks_json)
# Get the kid from the token header
{:ok, header} = NoWayJose.decode_header(token)
# Find the matching key and verify
case NoWayJose.Jwks.find_key(keys, header.kid) do
{:ok, key} ->
NoWayJose.verify(token, key, aud: "my-app")
:error ->
{:error, :key_not_found}
endAutomatic Fetching
For automatic key fetching and caching, see NoWayJose.start_jwks_fetcher/3.
Summary
Functions
Finds a key in the JWKS by its kid (key ID).
Finds a key by kid, raising if not found.
Parses a JWKS JSON string into a list of Key structs.
Functions
@spec find_key([NoWayJose.Key.t()], String.t() | nil) :: {:ok, NoWayJose.Key.t()} | :error
Finds a key in the JWKS by its kid (key ID).
Example
{:ok, key} = NoWayJose.Jwks.find_key(keys, "key-id-1")
@spec find_key!([NoWayJose.Key.t()], String.t() | nil) :: NoWayJose.Key.t() | no_return()
Finds a key by kid, raising if not found.
Example
key = NoWayJose.Jwks.find_key!(keys, "key-id-1")
@spec parse(String.t()) :: {:ok, [NoWayJose.Key.t()]} | {:error, atom()}
Parses a JWKS JSON string into a list of Key structs.
Example
{:ok, keys} = NoWayJose.Jwks.parse(jwks_json)