Created
June 25, 2016 04:57
-
-
Save nov/32c37a31ad837aa97885a27c9f7b7499 to your computer and use it in GitHub Desktop.
This file contains 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 '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