View Source OTT
A One-Time Token (OTT) is a unique and time-sensitive authentication mechanism used for secure login processes or transactions, ensuring each token is single-use only.
This package facilitates the creation and management of OTTs, empowering developers to seamlessly integrate this robust security measure into their applications.
Installation
OTT is published on Hex. The package can be installed by adding ott
to your list of dependencies in mix.exs
:
def deps do
[
{:ott, "~> 0.1.0"}
]
end
After the packages are installed you must create a database migration to add the ott tables to your database:
defmodule MyApp.Repo.Migrations.AddOTTTables do
use Ecto.Migration
def up do
OTT.Migrations.V1.up()
end
def down do
OTT.Migrations.V1.down()
end
end
Now, run the migration to create the table:
mix ecto.migrate
Usage
iex(1)> OTT.generate_token!(%{"user_id" => 1})
"xDkfMo23dm"
iex(2)> OTT.access_token_data("xDkfMo23dm")
%{"user_id" => 1}
iex(3)> OTT.access_token_data("xDkfMo23dm")
nil