authex v0.1.1 Authex View Source
To come…
Link to this section Summary
Functions
Returns the current scopes from a Plug.Conn
Returns the current user from a Plug.Conn
Turns a usable data structure into a compact token using a serializer module
Turns a token into a usable data structure using a serializer module
Signs an Authex.Token struct, creating a compact token
Creates a new Authex.Token struct from the given claims and options
Verifies a compact token
Link to this section Functions
current_scopes(Plug.Conn.t()) :: {:ok, list()} | :error
Returns the current scopes from a Plug.Conn.
Parameters
- conn: A Plug.Conn struct.
current_user(Plug.Conn.t()) :: {:ok, term()} | :error
Returns the current user from a Plug.Conn.
Parameters
- conn: A Plug.Conn struct.
for_token(term()) :: Authex.Token.t() | :error
Turns a usable data structure into a compact token using a serializer module.
Parameters
- resource: Any usable data structure.
Examples
iex> %{id: 1} |> Authex.for_token() |> is_binary()
true
from_token(Authex.Token.t()) :: term() | {:error, atom()}
Turns a token into a usable data structure using a serializer module.
Parameters
- token: An Authex.Token struct or compact token binary.
Examples
iex> [sub: 1] |> Authex.token() |> Authex.sign() |> Authex.from_token()
%{id: 1, scopes: []}
sign(Authex.Token.t(), list()) :: binary()
Signs an Authex.Token struct, creating a compact token.
Parameters
- token: An Authex.Token struct.
- options: A keyword list of options.
Options
:secret
- the secret key to sign the token with.:alg
- the algorithm to sign the token with.
Examples
iex> Authex.token() |> Authex.sign() |> is_binary()
true
token(list(), list()) :: Authex.Token.t()
Creates a new Authex.Token struct from the given claims and options
Parameters
- claims: A keyword list of JWT claims.
- options: A keyword list of options.
Options
:time
- the base time (timestamp format) in which to use.:ttl
- the TTL for the token.
Examples
iex> token = Authex.token([sub: 1], [ttl: 60])
iex> with %Authex.Token{sub: sub} <- token, do: sub
1
verify(binary(), list()) :: {:ok, Authex.Token.t()} | {:error, atom()}
Verifies a compact token.
Parameters
- compact_token: A compact token binary.
- options: A keyword list of options.
Options
:secret
- the secret key to verify the token with.:alg
- the algorithm to verify the token with.
Examples
iex> {:ok, token} = [sub: 1] |> Authex.token() |> Authex.sign() |> Authex.verify()
iex> with %Authex.Token{sub: sub} <- token, do: sub
1