Guardian.Token behaviour (Guardian v2.2.4) View Source

The behaviour module for all token modules.

Token modules are responsible for all the heavy lifting in Guardian.

Link to this section Summary

Callbacks

Build the default claims for the token.

Create the token including serializing and signing.

Decode the token. Without verification of the claims within it.

Exchange a token from one type to another.

Inspect the contents of the token without validation or signature checking.

Revoke a token (if appropriate).

Generate a unique id for a token.

Verify the claims of a token.

Link to this section Types

Specs

claims() :: map()

Specs

decoding_error() :: {:error, atom()}

Specs

encoding_error() :: {:error, atom()}

Specs

resource() :: any()

Specs

secret_error() :: {:error, :secret_not_found}

Specs

signing_error() :: {:error, :signing_error}

Specs

token() :: String.t()

Specs

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}

Link to this section Callbacks

Link to this callback

build_claims(mod, resource, sub, claims, options)

View Source

Specs

build_claims(
  mod :: module(),
  resource :: any(),
  sub :: String.t(),
  claims :: claims(),
  options :: Keyword.t()
) :: {:ok, claims()} | {:error, atom()}

Build the default claims for the token.

Link to this callback

create_token(mod, claims, options)

View Source

Specs

create_token(mod :: module(), claims :: claims(), options :: Guardian.options()) ::
  {:ok, token()} | signing_error() | secret_error() | encoding_error()

Create the token including serializing and signing.

Link to this callback

decode_token(mod, token, options)

View Source

Specs

decode_token(mod :: module(), token :: token(), options :: Guardian.options()) ::
  {:ok, token()} | secret_error() | decoding_error()

Decode the token. Without verification of the claims within it.

Link to this callback

exchange(mod, old_token, from_type, to_type, options)

View Source

Specs

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()}

Exchange a token from one type to another.

Specs

peek(module :: module(), token :: token()) :: map()

Inspect the contents of the token without validation or signature checking.

Link to this callback

refresh(mod, old_token, options)

View Source

Specs

refresh(mod :: module(), old_token :: token(), options :: Guardian.options()) ::
  {:ok, {token(), claims()}, {token(), claims()}} | {:error, any()}

Refresh a token.

Link to this callback

revoke(mod, claims, token, options)

View Source

Specs

revoke(
  mod :: module(),
  claims :: claims(),
  token :: token(),
  options :: Guardian.options()
) :: {:ok, claims()} | {:error, any()}

Revoke a token (if appropriate).

Specs

token_id() :: String.t()

Generate a unique id for a token.

Link to this callback

verify_claims(mod, claims, options)

View Source

Specs

verify_claims(
  mod :: module(),
  claims :: claims(),
  options :: Guardian.options()
) :: {:ok, claims()} | {:error, any()}

Verify the claims of a token.