OpenID Sample Application

Here's a follow-up to my instructions on integrating OpenID with ActsAsAuthenticated: a full, sample Ruby on Rails application that provides an example of how to use OpenID. Much like the caboose sample app(s), this is intended to be a good starting point for building your own application with OpenID baked in from the beginning.

This OpenID sample application uses DHH's open_id_authentication plugin, which has been tweaked to not require the current edge Rails. In other words, you can use this application on Rails 1.2.3 without any modifications. I modified the sample controller code from the plugin to automatically create user accounts with an OpenID login, and to only update the SRE fields for the user when first creating an account.

I'm also using Rick's restful_authentication plugin with the activation email observer commented out in environment.rb, and with the User model tweaked to allow accounts to be created without a login and password if the account is created via an OpenID login. The controller code does ask the OpenID provider for a nickname (mapped to login) and email address, but they aren't required and some OpenID providers may not provide the ability to get that extra data, so you can't really depend on the OpenID provider to provide those. I'll leave it as an exercise to the reader to figure out a way to collect an email address if responding to an activation email is desired.

Finally, Dr Nic's Gems on Rails is employed to distribute the ruby-openid gem along with the sample application, so you should be able to just unpack and run.

With the help of so many excellent developers, very little of the code in this archive is actually mine. :) However, whatever there is of my code in there is distributed under the MIT license, as is the rest of the code so generously provided by the other authors (aside from the ruby-openid gem, which is distributed under the Apache license).

Download the example Ruby on Rails OpenID application.

Comments