Generating a JSON Web Key (JWK) With Ruby
Sometimes you need to generate a new JWK, and converting an existing key isn't quite what you want.
We can use the ruby-jose library to do this via its handy generate_key
method, which provides us a JWKS when invoking the script:
require 'jose'
jwk = JOSE::JWS.generate_key({"alg" => "RS256"})
jwk_s = JSON.parse(jwk.to_binary)
puts JSON.pretty_generate(keys: jwk_s)