Joken v2.2.0 Joken.Hooks.RequiredClaims View Source

Hook to demand claims presence.

Adding this hook to your token configuration will allow to ensure some claims are present. It adds an after_validate/3 implementation that checks claims presence. Example:

defmodule MyToken do
  use Joken.Config

  add_hook Joken.Hooks.RequiredClaims, ensure: [:claim1, :claim2]
end

On missing claims it returns: {:error, [message: "Invalid token", missing_claims: claims]}.