Default rules that can be used during the building and/or parsing of PASETO tokens.
A rule is just a function that accepts a claim as its first argument and
returns :ok or an error reason tuple. For example, build applies the
following rules by default:
iex> key = Pasexto.Key.new(:v4, :local)
iex> claims = %{"hello": "world"}
iex> footer = <<>>
iex> {:ok, paseto, claims} = Pasexto.build(:v4, :local, key, claims, footer)
iex> {:ok, ^claims, ^footer} = Pasexto.parse(:v4, :local, key, paseto, rules: [
...> &Pasexto.Rules.validate_required(&1),
...> &Pasexto.Rules.validate_exp(&1),
...> &Pasexto.Rules.validate_iat(&1),
...> &Pasexto.Rules.validate_nbf(&1)
...> ])
Summary
Functions
Validates that the expiry claim has not expired.
Validates that the issued at claim has happened in the past.
Validates that the not before claim has happened in the past.
Validates the the required claims are present.
Types
@type claims() :: map()
Functions
@spec validate_exp(claims(), pos_integer()) :: :ok | {:error, {:invalid_claim, :exp, DateTime.t()}}
Validates that the expiry claim has not expired.
The jitter can be set in seconds for how much grace to give to the time
check, it defaults to 60.
Note
This function does not enforce requirement, for that validate_required/2
should be used.
@spec validate_iat(claims(), pos_integer()) :: :ok | {:error, {:invalid_claim, :iat, DateTime.t()}}
Validates that the issued at claim has happened in the past.
The jitter can be set in seconds for how much grace to give to the time
check, it defaults to 60.
Note
This function does not enforce requirement, for that validate_required/2
should be used.
@spec validate_nbf(claims(), pos_integer()) :: :ok | {:error, {:invalid_claim, :nbf, DateTime.t()}}
Validates that the not before claim has happened in the past.
The jitter can be set in seconds for how much grace to give to the time
check, it defaults to 60.
Note
This function does not enforce requirement, for that validate_required/2
should be used.
Validates the the required claims are present.
By default the following claims are required: :exp, :jti, :iat and
:nbf.