Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for using a key finder with JWT.decode #208

Open
ghost opened this issue Jun 22, 2017 · 4 comments
Open

Documentation for using a key finder with JWT.decode #208

ghost opened this issue Jun 22, 2017 · 4 comments
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Jun 22, 2017

I'm looking for documentation on using the key finder code block for the JWT.decode method. Is there any?

@excpt
Copy link
Member

excpt commented Jun 24, 2017

There is currently no documentation on this topic.

@excpt excpt self-assigned this Aug 24, 2017
@excpt excpt added this to the Version 2.0.0 milestone Aug 24, 2017
@excpt excpt removed this from the Version 2.0.0 milestone Sep 2, 2017
@minakov
Copy link

minakov commented Feb 7, 2018

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/securetoken@system.gserviceaccount.com')
  json = JSON.parse(Net::HTTP.get(url))
  OpenSSL::X509::Certificate.new(json[header['kid']]).public_key
end

@jhmartin
Copy link

jhmartin commented Jun 12, 2018

@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>

@excpt excpt added this to the Version 2.3.0 milestone Sep 16, 2019
@kazzix14
Copy link

kazzix14 commented Aug 15, 2022

@jhmartin You should use OpenSSL::X509::Certificate.new(json[header['kid']]).keypair instead.
It returns OpenSSL::PKey::EC that have dsa_verify_asn1 method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants