Search code examples
ruby-on-railsrubydiscourse

Issues making API requests to discourse instance from Heroku and locally using discourse_api gem


Been banging my head against this and need to bounce thoughts against someone else. I keep getting locally:

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed

I get on heroku:

openssl::ssl::sslerror: ssl_connect returned=1 errno=0 state=sslv3 read server certificate b: certificate verify failed

My discourse instance has a SSL certificate from DNSimple, so that is all working perfectly. On heroku, since I just have a rails API, I opted not to get an SSL cert for that since heroku already provides you with one, and just use the URL from your heroku instance.

Now, I am able to use a Advanced Rest Client (Chrome extension) and make requests to my discourse instance no problem. Here is some code that I am using with the discourse_api gem.

discourse_client = DiscourseApi::Client.new('https://community.desta.co')
discourse_client.api_key = ENV['COMMUNITY_API_KEY']
# path to heroku cert, which I verified exists through `heroku run bash`
discourse_client.ssl(ca_file: '/usr/lib/ssl/certs/ca-certificates.crt')
discourse_client.api_username = 'system'

Maybe I'm misunderstanding certificates? Please help! Thanks


Solution

  • For anyone that may have this issue, I was able to fix it. I tested my SSL config at https://www.ssllabs.com/ssltest/analyze.html and realized I didn't have any intermediate certificates along with my primary certificate :(. Definitely overlooked that one, hope it helps anyone.