Created
March 18, 2020 10:24
-
-
Save ysv/68569ffa6ce72d818a3b758e45c5f407 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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