Rails, Ruby, Rack, and Google OpenID via OmniAuth

A great new OpenID library for Ruby web apps (Rails, Sinatra, Rack, etc) has recently hit the scene.  The OmniAuth library supports a plethora of authentication systems, including Twitter, Facebook, Google Apps, and OpenID.  OmniAuth is Rack based, and it's easy to slip right into your web app.

While it does support OpenID, OmniAuth requires just a bit of manual configuration to support Google's OpenID endpoint.

You can use Google OpenID with OmniAuth and your Rails 3 web app:

For your Gemfile:


gem 'omniauth'


For your config/initializers/omniauth.rb:


Rails.application.config.middleware.use OmniAuth::Builder do
  provider :openid, nil, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end

What's up with the nil? That tells the OpenID gem to use the memory store, which is the default. You can use any OpenID Store that you wish (complete list of OpenID stores).

Direct your users to /auth/google

For the rest of the options and workflow, consult the OmniAuth Wiki.

Thanks to OmniAuth for making it really easy to add third party authentication to your Ruby powered web app!

For those not using OmniAuth, I've written a full end to end tutorial on Rails and Google OpenID integration.

Popular posts from this blog

Lists and arrays in Dart

Converting Array to List in Scala

Null-aware operators in Dart