I've followed Railscast #235 to try and set up a minimal Facebook authentication.
I've first set up a Twitter authentication, as done by Ryan himself. That worked flawlessly.
I then moved on to adding a Facebook login. However, after authorizing the app the redirect to /auth/facebook/callback
fails with:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
I am working on localhost. I didn't set up any SSL within the app. What am I doing wrong?
OmniAuth is a library that standardizes multi-provider authentication for web applications. It was created to be powerful, flexible, and do as little as possible. Any developer can create strategies for OmniAuth that can authenticate users via disparate systems.
Omniauth allows you to easily integrate more than sixty authentication providers, including Facebook, Google, Twitter and GitHub.
OmniWhat?? OmniAuth. It's a gem for Ruby on Rails. And it's great, for you and your users! You can learn more about it here, but basically it allows your users to sign up/log in to your app using a third-party provider (e.g. Facebook, Google, Github, etc.)
The real problem is that Faraday (which Omniauth/Oauth use for their HTTP calls) is not wasn't setting the ca_path variable for OpenSSL. At least on Ubuntu, most root certs are stored in "/etc/ssl/certs". Since Faraday isn't wasn't setting this variable (and currently does not have a method to do so), OpenSSL isn't wasn't finding the root certificate for Facebook's SSL certificate.
I've submitted a pull request to Faraday which will add support for this variable and hopefully they will pull in this change soon. Until then, you can monkeypatch faraday to look like this or use my fork of Faraday. After that, you should specify version 0.3.0 of the OAuth2 gem in your Gemspec which supports the passing of SSL options through to Faraday. All you need to do now is upgrade to Faraday 0.6.1, which supports passing of the ca_path variable and upgrade to OmniAuth 0.2.2, which has the proper dependencies for OAuth2. You'll then be able to properly fix this issue by just adding the following to your Omniauth initializer:
Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}} end
So, to recap:
Hopefully the next releases of both Faraday and Omniauth will incorporate this solution.
Thanks to KirylP above for setting me on the right path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With