Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top