authex v0.1.1 Authex.Serializer behaviour View Source

Link to this section Summary

Functions

Takes a resource and turn it into a compact token using the default serializer module

Takes a resource and turn it into a compact token using the provided serializer module

Takes a resource and turns it into an Authex.Token using the default serializer

Takes a resource and turns it into an Authex.Token using the provided serializer

Takes an Authex.Token struct and runs the default serializer against it

Takes an Authex.Token struct and runs the provided serializer against it

Link to this section Types

Link to this type serializer() View Source
serializer() :: atom()

Link to this section Functions

Link to this function for_compact_token(resource) View Source
for_compact_token(term()) :: binary()

Takes a resource and turn it into a compact token using the default serializer module.

Parameters

  • resource: Any usable data structure.

Examples

iex> %{id: 1} |> Authex.Serializer.for_compact_token() |> is_binary()
true
Link to this function for_compact_token(serializer, resource) View Source
for_compact_token(serializer(), term()) :: binary()

Takes a resource and turn it into a compact token using the provided serializer module.

Parameters

  • resource: Any usable data structure.

Examples

iex> compact = Authex.Serializer.for_compact_token(Authex.Serializer.Basic, %{id: 1})
iex> is_binary(compact)
true
Link to this function for_token(resource) View Source
for_token(term()) :: Authex.Token.t()

Takes a resource and turns it into an Authex.Token using the default serializer.

Parameters

  • resource: Any data structure the serializer can use.

Examples

iex> token = Authex.Serializer.for_token(%{id: 1, scopes: ["test/read"]})
iex> with %Authex.Token{sub: sub, scopes: scopes} <- token, do: [sub, scopes]
[1, ["test/read"]]
Link to this function for_token(serializer, resource) View Source
for_token(serializer(), term()) :: Authex.Token.t()

Takes a resource and turns it into an Authex.Token using the provided serializer.

Parameters

  • serializer: A serializer module.
  • resource: Any data structure the serializer can use.

Examples

iex> token = Authex.Serializer.for_token(Authex.Serializer.Basic, %{id: 1, scopes: ["test/read"]})
iex> with %Authex.Token{sub: sub, scopes: scopes} <- token, do: [sub, scopes]
[1, ["test/read"]]
Link to this function from_token(token) View Source
from_token(Authex.Token.t()) :: term()

Takes an Authex.Token struct and runs the default serializer against it.

Parameters

  • token: An Authex.Token struct.

Examples

iex> [sub: 1, scopes: []] |> Authex.token() |> Authex.Serializer.from_token()
%{id: 1, scopes: []}
Link to this function from_token(serializer, token) View Source
from_token(serializer(), Authex.Token.t()) :: term()

Takes an Authex.Token struct and runs the provided serializer against it.

Parameters

  • serializer: A serializer module.
  • token: An Authex.Token struct.

Examples

iex> token = Authex.token([sub: 1, scopes: []])
iex> Authex.Serializer.from_token(Authex.Serializer.Basic, token)
%{id: 1, scopes: []}

Link to this section Callbacks

Link to this callback handle_for_token(term) View Source
handle_for_token(term()) :: Authex.Token.t() | :error
Link to this callback handle_from_token(arg0) View Source
handle_from_token(Authex.Token.t()) :: term() | :error