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 section Functions
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
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
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"]]
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"]]
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: []}
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
handle_for_token(term()) :: Authex.Token.t() | :error
handle_from_token(Authex.Token.t()) :: term() | :error