Documentation for using a key finder with JWT.decode
I'm looking for documentation on using the key finder code block for the JWT.decode method. Is there any?
There is currently no documentation on this topic.
bearer = env.fetch('HTTP_AUTHORIZATION', '').slice(7..-1)
options = {
algorithm: 'RS256',
verify_aud: ENV['FIREBASE_PROJECT_ID'],
verify_iss: "https://securetoken.google.com/#{ENV['FIREBASE_PROJECT_ID']}"
}
JWT.decode(bearer, nil, true, options) do |header|
url = URI('https://www.googleapis.com/robot/v1/metadata/x509/[email protected]')
json = JSON.parse(Net::HTTP.get(url))
OpenSSL::X509::Certificate.new(json[header['kid']]).public_key
end
@minakov Are you sure that should end with .public_key? In my case I had to end with
OpenSSL::PKey::EC.new(pem)
instead of
OpenSSL::PKey::EC.new(pem).public_key
(using ES256 instead of RS256).
When I add .public_key I get:
NoMethodError: undefined method `dsa_verify_asn1' for #<OpenSSL::PKey::EC::Point:0x007f8625153d50>
@jhmartin You should use OpenSSL::X509::Certificate.new(json[header['kid']]).keypair instead.
It returns OpenSSL::PKey::EC that have dsa_verify_asn1 method.