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
token_or_sub() :: Authex.Token.t() | binary() | integer()
Link to this section Callbacks
Bans a subject.
Parameters
- token_or_sub: An
Authex.Token
or binary subject.
Checks whether a subject is banned.
Returns a boolean
Parameters
- token_or_sub: An
Authex.Token
or binary subject.
Blacklists a jti.
Parameters
- token_or_jti: An
Authex.Token
or binary jti.
blacklisted?(token_or_jti()) :: boolean()
Checks whether a jti is blacklisted.
Returns a boolean
Parameters
- token_or_jti: An
Authex.Token
or binary jti.
config(key :: atom(), default :: any()) :: any()
Fetches a config value.
Parameters
- key: A binary secret.
- default: A default value if none is present.
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.
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.
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.
Turns a usable data structure into an Authex.Token
using a serializer module.
Returns a Authex.Token
struct.
Parameters
- resource: Any usable data structure.
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.
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
- token: An
Authex.Token
struct.
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.
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.
Unbans a subject.
Parameters
- token_or_sub: An
Authex.Token
or binary subject.
unblacklist(token_or_jti()) :: :ok | :error
Unblacklists a jti.
Parameters
- token_or_jti: An
Authex.Token
or binary jti.
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.