jwt_obj
adds a high level mixin for your classes for easily encoding your objects with JWT claims.
Implements crystal-community/jwt. See their README.md
for more details on what JWT is and how it works.
Add this to your application's shard.yml
:
dependencies:
jwt_obj:
github: y32/jwt_obj
See JWT's supported reserved claims for details on what each claim is for.
require "jwt_obj"
struct Session
include JWT::Token
JSON.mapping(foo: String)
def initialize(@foo)
end
end
session = Session.new("bar")
encoded = session.encode("secret", "none") do
issued_at Time.now
issuer "z64"
audience ["GitHub", "snapcase"]
end
JWT.decode(encoded, "secret", "none")
#=> {{"foo" => "bar", "iat" => 1507264921, "iss" => "z64", "aud" => ["GitHub", "snapcase"]}, {"typ" => "JWT", "alg" => "none"}}
- z64 Zac Nowicki - creator, maintainer