SmartToken

Smart Tokens provide a mechanism to associate a query token with a given set of permissions and access attempts. It may be used, for example, for a single login link, or to allow 5 downloads of a specific file.

Setup

1. Add SmartToken to your mix.exs file.

def deps do
[
{:smart_token, "~> 0.1.1"}
]
end

2. Set config.exs repo or schema for smart token.

Repo - you ecto repo where the SmartToken table will be stored

config :smart_token, repo: MyApp.Repo

Schema - you ecto schema where the SmartToken table will be stored

Schema module must implement the SmartToken.Schema behaviour. Note get_token, lookup_token should insure the nested smart_token element's identifier field is set to the id of the record if not set on create.

See SSmartToken.Schema.SmartToken for an example implementation.

config :smart_token, schema: MyApp.Schema.SmartToken

3. Setup migration

Run

mix ecto.gen.migration setup_smart_tokens

Edit migration file:

defmodule MyApp.Repo.Migrations.SetupSmartTokens do
use Ecto.Migration
def up() do
SmartTokens.Migration.up(1)
end
def down() do
SmartTokens.Migration.down(1)
end
end