Joken Signer Config v0.1.1 Joken.Signer.Config View Source

Joken Signer Config is used to derive an appropriate %Joken.Signer from a jwt token based on the criteria of one or many %Joken.Signer.Configs within a list

Link to this section Summary

Functions

Reports if a given config is a match for a map of jwt headers and claims. If every key value pair in the headers and claims of the config match the same key values in the jwt headers and claims this returns true

Runs test_equality/2 on a key value pair(tuple) in a given map

Reports if all of the key value pairs in map 1 are present in map 2, but not that all the key value pairs in map 2 are present in map 1

Combines &peek/1 and &peek_header/1 to give a map that includes both headers and claims from the token

when first argument is a function hands the second argument to that function and returns the result otherwise returns whether or not the two values are equal

Link to this section Types

Link to this type claims() View Source
claims() :: %{}
Link to this type headers() View Source
headers() :: %{}
Link to this type json_value() View Source
json_value() :: binary() | number()
Link to this type t() View Source
t() :: %Joken.Signer.Config{
  claims: claims(),
  headers: headers(),
  signer: (... -> Joken.Signer.t())
}
Link to this type token_string() View Source
token_string() :: String.t()
Link to this type value_or_verifier() View Source
value_or_verifier() :: json_value() | function()

Link to this section Functions

Link to this function config_match?(config, jwt) View Source
config_match?(%{headers: value_or_verifier(), claims: value_or_verifier()}, %{
  headers: any(),
  claims: any()
}) :: boolean()

Reports if a given config is a match for a map of jwt headers and claims. If every key value pair in the headers and claims of the config match the same key values in the jwt headers and claims this returns true

Examples

iex> jwt = %{ iex> headers: %{}, iex> claims: %{ “a” => “ok”} iex> } iex> config_match?(%{ headers: %{}, claims: %{ “a” => “ok”}}, jwt) true iex> config_match?(%{ headers: %{“a” => “ok”}, claims: %{ “a” => “ok”}}, jwt) false iex> config_match?(%{ headers: %{}, claims: %{ “a” => “fail”}}, jwt) false

Link to this function find(config_list, jwt_binary) View Source
Link to this function get(config_list, jwt_binary) View Source
Link to this function key_value_match?(arg, map) View Source
key_value_match?({binary(), any()}, map()) :: boolean()

Runs test_equality/2 on a key value pair(tuple) in a given map

Examples

iex> test_map = %{ iex> “b” => “some_other_value”, iex> “a” => “my_value_to_test_for” iex> } iex> key_value_match?({“a”, “my_value_to_test_for”}, test_map) true iex> key_value_match?({“b”, “my_value_to_test_for”}, test_map) false iex> key_value_match?({“a”, “some_other_value”}, test_map) false iex> my_match_fn = fn val -> val === “my_value_to_test_for” end iex> key_value_match?({“a”, my_match_fn }, test_map) true iex> my_match_fn = fn val -> val === “some_other_value” end iex> key_value_match?({“a”, my_match_fn }, test_map) false

Link to this function map_match?(map1, map2) View Source
map_match?(map(), map()) :: boolean()

Reports if all of the key value pairs in map 1 are present in map 2, but not that all the key value pairs in map 2 are present in map 1

Examples

iex> map_match?(%{ “a” => “b” }, %{ “a” => “b”, “c” => “d”}) true iex> map_match?(%{ “a” => “a” }, %{ “a” => “b” }) false iex> map_match?(%{ “b” => “a” }, %{ “a” => “b” }) false iex> map_match?(%{ “b” => “a”, “c” => “d” }, %{ “b” => “a” }) false iex> my_match_fn = fn val -> val === “b” end iex> map_match?(%{ “a” => my_match_fn }, %{ “a” => “b” }) true iex> my_match_fn2 = fn val -> val === “a” end iex> map_match?(%{ “a” => my_match_fn2 }, %{ “a” => “b” }) false iex> my_match_fn3 = fn val -> val === “b” end iex> map_match?(%{ “c” => my_match_fn3 }, %{ “a” => “b” }) false

Link to this function peek_headers_and_claims(raw_jwt) View Source
peek_headers_and_claims(binary()) :: map()
peek_headers_and_claims(token()) :: map()

Combines &peek/1 and &peek_header/1 to give a map that includes both headers and claims from the token

Examples

iex> my_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.DjwRE2jZhren2Wt37t5hlVru6Myq4AhpGLiiefF69u8"
iex> import Joken.Signer.Config
iex> peek_headers_and_claims(my_token)
%{
  claims: %{"name" => "John Doe"},
  headers: %{"alg" => "HS256", "typ" => "JWT"}
}
Link to this function test_equality(func, value2) View Source
test_equality(value_or_verifier(), json_value()) :: any()

when first argument is a function hands the second argument to that function and returns the result otherwise returns whether or not the two values are equal

this function is meant for letting users of our api test for values in a jwt token in a custom way.

Examples

iex> test_equality(1, 1) true iex> test_equality(&(&1 == 1), 1) true iex> test_equality(&(&1 - 1 === 4), 5) true iex> test_equality(&(&1 - 2 === 4), 5) false