Created
July 11, 2014 19:37
-
-
Save chills42/6e5ee23b41a358c48d10 to your computer and use it in GitHub Desktop.
Faraday client certificate authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I'm starting with a .pfx, so the first step is to get it to a .pem caintaining the cert and key | |
# This can be done using the following command | |
# | |
# openssl pkcs12 -in certs/mycert.pfx -out certs/mycert.pem -nodes | |
# | |
require 'faraday' | |
require 'openssl' | |
# create an x509 certificate | |
def cert_object | |
OpenSSL::X509::Certificate.new File.read('certs/mycert.pem') | |
end | |
# create PKey | |
def key_object | |
OpenSSL::PKey.read File.read('certs/mycert.pem') | |
end | |
# build the connection object | |
connection = Faraday::Connection.new 'https://my.secure.site.dev', ssl: { | |
client_cert: get_cert, | |
client_key: get_key, | |
verify: false | |
} | |
connection.post do |req| | |
req.url '/secure-endpoint' | |
req.body = "secret data" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment