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?

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top