authority v0.1.0 Authority.Tokenization behaviour

A behaviour for converting resources (or credentials) into tokens.

Usage

defmodule MyApp.Accounts.Tokenization do
  use Authority.Tokenization

  @impl Authority.Tokenization
  def tokenize(resource, purpose) do
    # create a token for the resource
  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

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

Link to this type purpose()
purpose() :: atom()

The purpose for the token.

Link to this type resource()
resource() :: any()

A resource to be converted into a token. Can be any type that makes sense for the application.

Link to this type token()
token() :: any()

A token. Can be any type that makes sense for your application.

Link to this section Callbacks

Link to this callback tokenize(resource)
tokenize(resource()) :: {:ok, token()} | {:error, term()}

Creates a token, assuming the :any purpose, representing a given resource.

Link to this callback tokenize(resource, purpose)
tokenize(resource(), purpose()) :: {:ok, token()} | {:error, term()}

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.