Skip to content

A high-level mixin for creating objects with JWT claims

License

Notifications You must be signed in to change notification settings

sledgang/jwt_obj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwt_obj

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.

Installation

Add this to your application's shard.yml:

dependencies:
  jwt_obj:
    github: y32/jwt_obj

Usage

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"}}

Contributors

  • z64 Zac Nowicki - creator, maintainer

About

A high-level mixin for creating objects with JWT claims

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published