View Source Charon.TokenFactory.Behaviour behaviour (Charon v3.1.1)

Behaviour for token-signing modules.

Note that the token payload must be returned as a map with string keys on verification. When the payload is serialized as JSON, this happens automatically. However, when Erlang term format is used, this is not the case.

Link to this section Summary

Callbacks

Create a new token with the provided payload and a valid signature.

Verify that the signature matches the token's header and payload, and decode the payload.

Link to this section Callbacks

@callback sign(payload :: %{required(String.t()) => any()}, config :: Charon.Config.t()) ::
  {:ok, String.t()} | {:error, String.t()}

Create a new token with the provided payload and a valid signature.

@callback verify(token :: String.t(), config :: Charon.Config.t()) ::
  {:ok, %{required(String.t()) => any()}} | {:error, String.t()}

Verify that the signature matches the token's header and payload, and decode the payload.

Must return a map of string keys.