Skip to content

Instantly share code, notes, and snippets.

@ysv
Created March 18, 2020 10:24
Show Gist options
  • Select an option

  • Save ysv/68569ffa6ce72d818a3b758e45c5f407 to your computer and use it in GitHub Desktop.

Select an option

Save ysv/68569ffa6ce72d818a3b758e45c5f407 to your computer and use it in GitHub Desktop.
require "pry-byebug"
require "openssl"
require "jwt"
require "securerandom"
priv_key = File.open("path/to/private/key") do |f|
OpenSSL::PKey.read(f.read)
end
payload = {
algorithm: "RS256",
:iss=>"barong",
:sub=>"session",
:aud=>["yellow-logic"],
:email=>"[email protected]",
:uid=>"U123456789",
:role=>"admin",
:state=>"active",
:level=>"3",
:iat=>Time.now.to_i,
:exp=>(Time.now + 60).to_i,
:jti=>SecureRandom.hex(12)
}
jwt = JWT.encode(payload, priv_key, payload[:algorithm])
print jwt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment