OpenID Sample Application

11 May 2007

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.


Actions

Informations

6 responses to “OpenID Sample Application”

BrianC (12:05:00) :

Awesome. Worked right out of the box for me. Very much appreciated.

Olav (10:48:43) :

Thanks a lot. :)

Tom (13:35:22) :

I get the following error:
undefined method `url’ for #
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/cgi_process.rb:139:in `method_missing’
#{RAILS_ROOT}/vendor/plugins/open_id_authentication/lib/open_id_authentication.rb:133:in `open_id_redirect_url’
#{RAILS_ROOT}/vendor/plugins/open_id_authentication/lib/open_id_authentication.rb:92:in `begin_open_id_authentication’
#{RAILS_ROOT}/vendor/plugins/open_id_authentication/lib/open_id_authentication.rb:76:in `authenticate_with_open_id’
#{RAILS_ROOT}/app/controllers/session_controller.rb:40:in `open_id_authentication’
#{RAILS_ROOT}/app/controllers/session_controller.rb:8:in `create’

Not pretty. A quick google search reveals that I’m not the only one having this problem, but I didn’t find a solution. I have no idea, what ‘url’ method it’s talking about – didn’t find that in the source.
Any hint is appreciated..

Lau (08:24:20) :

Tom, I think it’s because you need edge rails. Version 1.2.3 won’t do.

Ben (08:56:44) :

Actually, you don’t need edge rails with the zip I provide. I have modified the plugin to not depend on the url method provided in edge rails. Tom, I’m guessing you aren’t using my zip file.

links for 2007-05-26, or so says Harry Love (08:21:47) :

[...] BenCurtis.com ยป OpenID Sample Application (tags: rubyonrails openid authentication) Tags: Found Objects [...]