However if we want to build a user authentication alternative for our own webservices through OAuth, it is important to verify the authenticity of the OAuth provider. We will use HTTPS/SSL since Facebook provides that.
Michael Bleigh has posted this helpful example for Rails 2.3:http://wiki.github.com/intridea/oauth2/rails-23-webserver-example
warning: peer certificate won't be verified in this SSL session
This is fine if you are only polling data, but I needed to verify the provider. After some looking around the OAuth gem and Faraday, I found the site parameter, if given a hash, is treated as the options hash.
Download the certificate authority file from: http://curl.haxx.se/ca/cacert.pem and place it somewhere appropriate.
def client
ca_file = File.join('ca_file_path')
@client ||= OAuth2::Client.new(
'appid', 'app_secret',
{
# Faraday treats the site param if it is a hash as the options hash
:site => {
:url=>'https://graph.facebook.com',
:ssl=>{
:verify=>OpenSSL::SSL::VERIFY_PEER,
:ca_file =>ca_file
}
},
# doesnt have to be NetHttp
:adapter => :NetHttp}
)
endAnd that should work!
No comments:
Post a Comment