authex v0.2.1 Authex behaviour View Source

Link to this section Summary

Callbacks

Bans a subject

Checks whether a subject is banned

Blacklists a jti

Checks whether a jti is blacklisted

Fetches a config value

Gets the current scopes from a Plug.Conn

Gets the current user from a Plug.Conn

Turns a usable data structure into a compact token using a serializer module

Turns a usable data structure into an Authex.Token using a serializer module

Turns a compact token into a usable data structure using a serializer module

Turns an Authex.Token into a usable data structure using a serializer module

Sets the secret key that will be used to sign our tokens with

Signs an Authex.Token struct, creating a compact token

Creates a new token from the given claims and options

Unbans a subject

Unblacklists a jti

Verifies a compact token

Link to this section Types

Link to this type token_or_jti() View Source
token_or_jti() :: Authex.Token.t() | binary()
Link to this type token_or_sub() View Source
token_or_sub() :: Authex.Token.t() | binary() | integer()

Link to this section Callbacks

Link to this callback ban(token_or_sub) View Source
ban(token_or_sub()) :: :ok | :error

Bans a subject.

Parameters

Link to this callback banned?(token_or_sub) View Source
banned?(token_or_sub()) :: boolean()

Checks whether a subject is banned.

Returns a boolean

Parameters

Link to this callback blacklist(token_or_jti) View Source
blacklist(token_or_jti()) :: :ok | :error

Blacklists a jti.

Parameters

Link to this callback blacklisted?(token_or_jti) View Source
blacklisted?(token_or_jti()) :: boolean()

Checks whether a jti is blacklisted.

Returns a boolean

Parameters

Link to this callback config(key, default) View Source
config(key :: atom(), default :: any()) :: any()

Fetches a config value.

Parameters

  • key: A binary secret.
  • default: A default value if none is present.
Link to this callback current_scopes(arg0) View Source
current_scopes(Plug.Conn.t()) :: {:ok, list()} | :error

Gets the current scopes from a Plug.Conn.

Returns a list of scopes.

Parameters

  • conn: A Plug.Conn struct.
Link to this callback current_user(arg0) View Source
current_user(Plug.Conn.t()) :: {:ok, any()} | :error

Gets the current user from a Plug.Conn.

Returns a term defined by a serializer.

Parameters

  • conn: A Plug.Conn struct.
Link to this callback for_compact_token(any) View Source
for_compact_token(any()) :: Authex.Token.compact() | :error

Turns a usable data structure into a compact token using a serializer module.

Returns a binary compact token.

Parameters

  • resource: Any usable data structure.
Link to this callback for_token(any) View Source
for_token(any()) :: Authex.Token.t() | :error

Turns a usable data structure into an Authex.Token using a serializer module.

Returns a Authex.Token struct.

Parameters

  • resource: Any usable data structure.
Link to this callback from_compact_token(compact_token, options) View Source
from_compact_token(compact_token :: Authex.Token.compact(), options :: Authex.Signer.options()) ::
  any() |
  {:error, atom()}

Turns a compact token into a usable data structure using a serializer module.

Returns any term defined by the serializer.

Otherwise, returns :error.

Parameters

  • compact_token: A binary compact token.
Link to this callback from_token(token) View Source
from_token(token :: Authex.Token.t()) :: any() | {:error, atom()}

Turns an Authex.Token into a usable data structure using a serializer module.

Returns any term defined by the serializer.

Otherwise, returns :error.

Parameters

Link to this callback set_secret(binary) View Source
set_secret(binary()) :: :ok

Sets the secret key that will be used to sign our tokens with.

Parameters

  • secret: A binary secret.
Link to this callback sign(token, options) View Source
sign(token :: Authex.Token.t(), options :: Authex.Signer.options()) :: compact_token :: Authex.Token.compact()

Signs an Authex.Token struct, creating a compact token.

Returns a binary 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.
Link to this callback token(claims, options) View Source
token(claims :: Authex.Token.claims(), options :: Authex.Token.options()) :: token :: Authex.Token.t()

Creates a new token from the given claims and options.

Returns an Authex.Token struct.

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.
Link to this callback unban(token_or_sub) View Source
unban(token_or_sub()) :: :ok | :error

Unbans a subject.

Parameters

Link to this callback unblacklist(token_or_jti) View Source
unblacklist(token_or_jti()) :: :ok | :error

Unblacklists a jti.

Parameters

Link to this callback verify(compact_token, options) View Source
verify(compact_token :: Authex.Token.compact(), options :: Authex.Verification.options()) ::
  {:ok, token :: Authex.Token.t()} |
  {:error, atom()}

Verifies a compact token.

Returns {:ok, %Authex.Token{}} if the token is valid.

Otherwise, returns {:error, :reason}

Parameters

  • compact_token: A compact token binary.
  • options: A keyword list of options.

Options

  • :time - the base time (timestamp format) in which to use.
  • :secret - the secret key to verify the token with.
  • :alg - the algorithm to verify the token with.
  • :banlist - the banlist module to verify with.
  • :blacklist - the blacklist module to verify with.