Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Faraday SSL example
connection = Faraday::Connection.new('http://example.com') do |builder|
builder.request :url_encoded # for POST/PUT params
builder.adapter :net_http
end
# same as above, short form:
connection = Faraday.new 'http://example.com'
# GET
connection.get '/posts'
# POST payload
payload = {:title => 'Example'}
connection.post '/posts', payload
# now again, over SSL
# verify_mode is automatically set to OpenSSL::SSL::VERIFY_PEER
connection = Faraday.new 'https://example.com'
# turn off SSL
# (no use-case for this, really)
connection = Faraday.new 'https://example.com', :ssl => false
# turn off peer verification
connection = Faraday.new 'https://example.com', :ssl => {:verify => false}
# other SSL options
connection = Faraday.new 'https://example.com', :ssl => {
:client_cert => ...,
:client_key => ...,
:ca_file => ...,
:ca_path => ...,
:cert_store => ...
}
@veloper

This comment has been minimized.

Copy link

commented Nov 5, 2013

Thanks, this gist rocks! (Found via google search)

@schnittchen

This comment has been minimized.

Copy link

commented Nov 25, 2013

I could not get the :ca_path option to work. So sad.

@pboling

This comment has been minimized.

Copy link

commented Jan 9, 2014

I can't get the :ssl => {:verify => false} option to work with the net/http adapter. A google makes it seem like lots of people are in the same boat :(

@strotter

This comment has been minimized.

Copy link

commented Jan 16, 2014

Re: :verify => false, I was able to get around this by requiring 'openssl' and then:

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

Probably not the best option, but helps.

@zekefast

This comment has been minimized.

Copy link

commented Apr 14, 2014

For those who can not get work some options, please, ensure that you pass Symbol keys. String keys does not works. You also could use ::Hashie::Mash to avoid bothering with difference in keys (symbolize keys from ActiveSupport should work as well).

@twilliamsark

This comment has been minimized.

Copy link

commented May 4, 2015

Newbe question. Does it support TLS?

@tamersalama

This comment has been minimized.

Copy link

commented Nov 4, 2015

Thank you @zekefast - it indeed needed symbolized keys. If you're in rails - don't forget you could use deep_symbolize_keys

@EdwinRozario

This comment has been minimized.

Copy link

commented Feb 16, 2016

I wanted to set TLS 1.2 as the networking protocol with Faraday. So i did Faraday.new(url: uid, ssl: {version: :TLSv1_2}). It works but I am not sure if this is the right configuration. Because i cant break it with Faraday.new(url: uid, ssl: {version: :TLSv10_11}).

Can someone help with the right options for ssl version.

@crystalneth

This comment has been minimized.

Copy link

commented Aug 13, 2016

The documentation on this is all wrong. Here's how to do it. This might also work at the request level.

conn = Faraday.new do |faraday|
    faraday.ssl.verify = false
end
@metaskills

This comment has been minimized.

Copy link

commented Aug 29, 2016

I had to use the following format for a gem that is both Faraday 0.8 and 0.9 tested.

Faraday.new do |faraday|
  faraday.ssl[:verify] = false
end
@mcr

This comment has been minimized.

Copy link

commented May 20, 2019

Many posts seem to think that turning off verification is a good thing, and you are struggling to do it correctly.
Might as well just now use SSL at all if you do that.
The right answer is probably that you need to set up the ca_path so that the server can be validated correctly. See for instance, https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.