We have good news for our colleagues developing on Ruby. Last week we relased the Auth0 OmniAuth Strategy that makes it a bliss to connect Ruby apps with Auth0.
OmniAuth is a Ruby authentication framework aimed to abstract away the difficulties of working with various types of authentication providers. It is meant to be hooked up to just about any system, from social networks to enterprise systems to simple username and password authentication.
Once you connect to Auth0, you can automagically accept users from anywhere: LDAP, AD, SQL, Office365, Google Apps, LiveID, Facebook, Twitter, PayPal, LinkedIn, etc.
All you need is a couple steps to get it running in your app:
1. Install the Strategy
gem install auth0
2. Initialize the auth0 gem
auth0.rb file under the
config/initializers folder with the following settings:
Rails.application.config.middleware.use OmniAuth::Builder do provider :auth0, YOUR_CLIENT_ID, YOUR_SECRET, YOUR_NAMESPACE end
3. Create a Callback Controller
rails generate controller callback store failure
callback_controller.rb under the
app/controllers folder and implement the methods
store (used to store the user profile in session), and
failure (to display error messages):
class CallbackController < ApplicationController def store session[:userinfo] = request.env['omniauth.auth'] redirect_to user_index_path end def failure @error_msg = request.params['message'] end end
Update the callback routes in the
match "auth/auth0/callback" => "callback#store" match "auth/failure" => "callback#failure"
You are essentially done!
Complete tutorial is available here. As with other tutorials, all parameters (e.g. ClientID, ClientSecret, etc.) will be replaced in the docs automagically with your own settings if you are signed up with Auth0.