server_utils v0.3.2 ServerUtils.Parsers.Jwt

JWT parser to get claim values.

Link to this section Summary

Functions

Gets a claim value using the claim key from a JWT. Optional this call can fail if error_if_blank is provided

Gets the claims from a JWT string

Link to this section Functions

Link to this function get_claim(jwt, claim_key, opts \\ [error_if_blank: false])
get_claim(String.t(), String.t(), Keyword.t()) :: {atom(), String.t()}

Gets a claim value using the claim key from a JWT. Optional this call can fail if error_if_blank is provided.

Examples

iex> Elixir.ServerUtils.Parsers.Jwt.get_claim("example_jwt", "username")
{:ok, "luke"}

iex> Elixir.ServerUtils.Parsers.Jwt.get_claim("example_jwt", "username")
{:ok, ""}

iex> Elixir.ServerUtils.Parsers.Jwt.get_claim("example_jwt", "username", error_if_blank: true)
{:error, "Blank claim username"}
Link to this function get_claims(jwt)
get_claims(String.t()) :: {atom(), String.t()}

Gets the claims from a JWT string.

Examples

iex> Elixir.ServerUtils.Parsers.Jwt.get_claims("example_jwt")
{:ok, %{"username" => "luke"}}

iex> Elixir.ServerUtils.Parsers.Jwt.get_claims("example_jwt")
{:ok, %{}}

iex> Elixir.ServerUtils.Parsers.Jwt.get_claims(nil)
{:error, :invalid_token}