Packages
guardian
2.2.1
2.4.0
2.3.2
2.3.1
2.3.0
2.2.4
2.2.3
2.2.2
2.2.1
2.2.0
2.1.2
2.1.1
2.0.0
1.2.1
1.2.0
retired
1.1.1
1.1.0
1.0.1
1.0.0
1.0.0-beta.1
1.0.0-beta.0
0.14.6
0.14.5
0.14.4
0.14.3
retired
0.14.2
0.14.1
0.14.0
0.13.0
0.12.0
0.11.1
0.10.1
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.4
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.2
0.5.0
0.4.1
0.4.0
0.3.1
0.3.0
0.2.0
0.1.1
0.1.0
Elixir Authentication framework
Current section
Files
Jump to
Current section
Files
lib/guardian/token.ex
defmodule Guardian.Token do
@moduledoc """
The behaviour module for all token modules.
Token modules are responsible for all the heavy lifting
in Guardian.
"""
@type token :: String.t()
@type claims :: map
@type resource :: any
@type ttl ::
{pos_integer, :second}
| {pos_integer, :seconds}
| {pos_integer, :minute}
| {pos_integer, :minutes}
| {pos_integer, :hour}
| {pos_integer, :hours}
| {pos_integer, :day}
| {pos_integer, :days}
| {pos_integer, :week}
| {pos_integer, :weeks}
@type secret_error :: {:error, :secret_not_found}
@type signing_error :: {:error, :signing_error}
@type encoding_error :: {:error, atom}
@type decoding_error :: {:error, atom}
@doc """
Inspect the contents of the token without validation or signature checking.
"""
@callback peek(module :: module, token :: token) :: map
@doc """
Generate a unique id for a token.
"""
@callback token_id() :: String.t()
@doc """
Build the default claims for the token.
"""
@callback build_claims(
mod :: module,
resource :: any,
sub :: String.t(),
claims :: claims,
options :: Keyword.t()
) :: {:ok, claims} | {:error, atom}
@doc """
Create the token including serializing and signing.
"""
@callback create_token(mod :: module, claims :: claims, options :: Guardian.options()) ::
{:ok, token} | signing_error | secret_error | encoding_error
@doc """
Decode the token. Without verification of the claims within it.
"""
@callback decode_token(mod :: module, token :: token, options :: Guardian.options()) ::
{:ok, token} | secret_error | decoding_error
@doc """
Verify the claims of a token.
"""
@callback verify_claims(mod :: module, claims :: claims, options :: Guardian.options()) ::
{:ok, claims} | {:error, any}
@doc """
Revoke a token (if appropriate).
"""
@callback revoke(mod :: module, claims :: claims, token :: token, options :: Guardian.options()) ::
{:ok, claims} | {:error, any}
@doc """
Refresh a token.
"""
@callback refresh(mod :: module, old_token :: token, options :: Guardian.options()) ::
{:ok, {token, claims}, {token, claims}} | {:error, any}
@doc """
Exchange a token from one type to another.
"""
@callback exchange(
mod :: module,
old_token :: token,
from_type :: String.t() | [String.t(), ...],
to_type :: String.t(),
options :: Guardian.options()
) :: {:ok, {token, claims}, {token, claims}} | {:error, any}
end