0.0
No release in over a year
Provides helper methods for working with JSON Web Tokens (JWTs)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0

Runtime

~> 2
 Project Readme

Jot

A light wrapper around the JWT gem.

Setup

Configure the gem:

Jot.configure do |config|
  config.algorithm = "HS256"
  config.secret = # Something long and complex, such as a value generated by SecureRandom.hex(32)
end

You may wish to also specify the expiration time for tokens as well. The default is 1 hour, but it can be overridden:

  config.expiration_time_in_seconds = 1500 # 25 minutes

Usage

Encode a payload:

Jot.encode({ user_id: 1 }) # => "eyJhbGciOiJIUz..."

Decode a payload:

Jot.decode("eyJhbGciOiJIUz...") # => { "user_id" => 1 }

Decode a payload and get the header information too:

Jot.original_decode("eyJhbGciOiJIUz") # => [{ "user_id" => 1 }, { "alg" => "HS256" }]

Exceptions raised for invalid / expired tokens will be the same as those raised by the JWT gem.