Skip to content

Instantly share code, notes, and snippets.

@nov
Created June 25, 2016 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nov/32c37a31ad837aa97885a27c9f7b7499 to your computer and use it in GitHub Desktop.
Save nov/32c37a31ad837aa97885a27c9f7b7499 to your computer and use it in GitHub Desktop.
require 'json/jwt' # v1.6.2+
private_key = OpenSSL::PKey::RSA.generate(2048)
jwk = JSON::JWK.new(private_key)
p jwk[:kid] # => auto-generated kid (= JWK Thumbprint value)
jwt = JSON::JWT.new(
iss: 'https://idp.example.com',
aud: 'https://rp.example.com',
sub: 'user#12345',
iat: Time.now,
exp: 5.minutes.from_now
)
p jwt.kid # => nil
jws = jwt.sign(jwk)
p jws.kid # => auto-copied from jwk
jws = jwt.sign(private_key)
p jws.kid # => nil (because OpenSSL::PKey::RSA instance itself doens't have kid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment