Project

token-die

0.0
No commit activity in last 3 years
No release in over 3 years
Generate and validate time expiring tokens
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.8
>= 10.0
>= 3.3.0

Runtime

~> 0.2.0
 Project Readme

TokenDie

Generate and validate time expiring tokens

Usage

secret = 'my-secret' #=> Secret token
ttl = 5 #=> Token TTL, default 300 (5 minutes)

token_die = TokenDie.new(secret, ttl = ttl)

token = token_die.generate #=> haNSO3ArFzE/2Jm2KQPkyWEaV0wX5dK7HbaYYEmyX/k=
token_die.valid?(token) #=> true
token_die.recover(token) #=> {}

# Passing Data
token_with_data = token_die.generate({'foo' => 'bar'}) #=>JzJW02mJsJDNFH+jMGMmhFLigHie+j/gCZh60dI7LBsf3z73kAMh/+ZtQTgWbxE7
token_die.valid?(token_with_data) #=> true
token_die.recover(token_with_data) #=> {"foo" => "bar"}

sleep(ttl) #=> When TTL expires

token_die.valid?(token) #=> false
token_die.recover(token) #=> nil
token_die.recover(token_with_data) #=> nil