0

On the frontend, using React and the Google Login Button, the user logs in to my application. Google returns the user's JWT to a callback URL on the frontend, encoded. I then deliver this JWT on each request to a Rails API and want the rails API to decode and verify this JWT, and if it is verified successfully, return the data that API endpoint is supposed to give.

I am currently using this code:

def google_public_key
  x509 = OpenSSL::X509::Certificate.new ENV["GOOGLE_CERT"]
  x509.public_key
end

The env var is described like this: https://gist.github.com/Connorelsea/c6b91a4b4b6889294fd4e2fcacb06564

I am getting this error: OpenSSL::X509::CertificateError (nested asn1 error)

If I do not verify, I can read the content of the JWT. From the JWT website it can be decoded, but not verified, as well.

Connorelsea
  • 2,308
  • 6
  • 26
  • 47

1 Answers1

0

Had the same problem and solved by setting the public_key as Pkey object not as a string in the constructor, try:

def google_public_key
  x509 = OpenSSL::X509::Certificate.new 
  x509.public_key = OpenSSL::PKey::RSA.new ENV["GOOGLE_CERT"]
end
Bmxer
  • 397
  • 1
  • 3
  • 9