authority v0.3.0 Authority.Tokenization behaviour
A behaviour for creating tokens to represent resources (or credentials).
Most commonly, this will be used to exchange credentials for a temporary token which will be used to authenticate future requests.
Example
defmodule MyApp.Accounts.Tokenization do
use Authority.Tokenization
@impl Authority.Tokenization
def tokenize(credential, purpose \\ :any) do
with {:ok, user} <- MyApp.Accounts.authenticate(credential, purpose) do
# create a token associated with the user
end
end
end
Link to this section Summary
Types
The purpose for the token
A resource to be converted into a token. Can be any type that makes sense for the application
A token. Can be any type that makes sense for your application
Callbacks
Gets a token by an identifier, such as a string version of it
Creates a token, assuming the :any
purpose, representing a given resource
Create a token with a given purpose, representing a given resource. For example, you might convert credentials (email/password) into a token representing a user
Link to this section Types
The purpose for the token.
A resource to be converted into a token. Can be any type that makes sense for the application.
A token. Can be any type that makes sense for your application.
Link to this section Callbacks
Gets a token by an identifier, such as a string version of it.
Creates a token, assuming the :any
purpose, representing a given resource.
Create a token with a given purpose, representing a given resource. For example, you might convert credentials (email/password) into a token representing a user.