3

I'm trying to convert a project I have from using Excon to Faraday with the Excon adapter, but I'm not having any luck.

The issue is that I need to pass through some arbitrary connection options to Excon as the API I am interfacing with uses client side SSL certs for authentication.

To make the connection with straight Excon I was using this:

@connection = Excon.new("some_url", client_cert: File.expand_path(@some_cert), client_key: File.expand_path(@some_key))

According to the Faraday documention, I should be able to do something like this:s

@connection = Faraday::Connection.new(url: "some_url", client_cert: File.expand_path(@some_cert), client_key: File.expand_path(@some_key)) do |faraday|
  faraday.adapter :excon
end

When I try that (with the 0.9 RC5 from Github), I get an undefined method client_cert= error, which leads me to believe the documentation is out of date. Does anybody know how to pass arbitrary connection options through to an adapter?

Eugene
  • 4,829
  • 1
  • 24
  • 49

1 Answers1

3

You have to pass the SSL options as a hash. This should work:

ssl_opts = {
  client_cert: File.expand_path(@some_cert),
  client_key: File.expand_path(@some_key)
}
@connection = Faraday::Connection.new(url: "some_url", ssl: ssl_opts) do |faraday|
  faraday.adapter :excon
end

This gist has some more examples for using SSL with Faraday.

Wally Altman
  • 3,535
  • 3
  • 25
  • 33
  • unfortunately, that still does not work. the ssl options do not get passed through to the excon adapter. basically it doesn't matter what i put in, nothing makes it into the connection_options here: https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/excon.rb#L6 Seems like this could possibly be a bug in Faraday... – Eugene May 14 '13 at 16:16
  • 1
    This was actually a bug in Faraday, but I made a pull request that would implement this as described. So while it is not the correct answer at this present time, it should be before too long. – Eugene May 14 '13 at 17:55