Packages
joken
2.0.0-rc1
2.6.2
2.6.1
2.6.0
2.5.0
2.4.1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.1
2.0.0
2.0.0-rc3
2.0.0-rc2
2.0.0-rc1
2.0.0-rc0
1.5.0
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
0.16.1
0.16.0
0.15.0
0.14.1
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.8.1
0.8.0
0.7.0
0.6.2
0.6.1
0.6.0
0.5.0
0.1.0
JWT (JSON Web Token) library for Elixir.
Current section
Files
Jump to
Current section
Files
lib/joken/error.ex
defmodule Joken.Error do
@moduledoc """
Errors for the Joken API.
"""
defexception [:reason]
alias Joken.Signer
@doc false
def exception(reason), do: %__MODULE__{reason: reason}
def message(%__MODULE__{reason: :no_default_signer}),
do: """
Can't sign your token because couldn't create a signer.
To create a signer we need a key in config.exs. You can define
a key in your config.exs in several ways:
1. For the default key, use `config :joken, default_signer: <key_params>`
2. For other keys, use `config :joken, <key_name>: <key_params>`
If you are using different than default keys, you can pass it as the second
argument to `generate_and_sign/2` or as a parameter for `use Joken.Config`,
example: `use Joken.Config, default_signer: <key_name>`
See configuration docs for possible values of <key_params>.
"""
def message(%__MODULE__{reason: [:bad_generate_and_sign, reason: result]}),
do: """
Error while calling `generate_and_sign!`. Reason: #{inspect(result)}.
"""
def message(%__MODULE__{reason: [:bad_verify_and_validate, reason: result]}),
do: """
Error while calling `verify_and_validate!`. Reason: #{inspect(result)}.
"""
def message(%__MODULE__{reason: :invalid_default_claims}),
do: """
Invalid argument to default claims. Verify the types of the arguments to
Joken.Config.default_claims/1.
"""
def message(%__MODULE__{reason: :unrecognized_algorithm}),
do: """
Couldn't recognize the signer algorithm.
Possible values are:
#{inspect(Signer.algorithms())}
"""
def message(%__MODULE__{reason: :claim_not_valid}),
do: """
Claim did not pass validation.
Set log level to debug for more information.
"""
def message(%__MODULE__{reason: :claim_configuration_not_valid}),
do: """
Claim configuration is not valid. You must have either a generation function or a
validation function.
If both are nil you don`t need a Joken.Claim configuration. You can pass any map of values
to `Joken.Config.generate_and_sign/3`. Verify will only use claims that have a validation
function on your configuration. Example:
defmodule CustomClaimTest do
use Joken.Config
end
CustomClaimTest.generate_and_sign %{"a claim without configuration" => "any value"}
"""
def message(%__MODULE__{reason: :bad_validate_fun_arity}),
do: """
Claim validate function must have either arity 1 or 2.
When arity is 1, it receives the claim value in a given JWT.
When it is 2, besides the claim value, it receives a context map. You can pass dynamic
values on this context and pass it to the validate function.
See `Joken.Config.validate/3` for more information on Context
"""
def message(%__MODULE__{reason: :wrong_key_parameters}),
do: """
Couldn't create a signer because there are missing parameters.
Check the Joken.Signer.parse_config/2 documentation for the types of parameters needed
for each type of algorithm.
"""
end