Rails & OpenID with Caboo.se Sample App

Jun 06 by Andre

Integrating OpenID authentication into the Caboo.se sample Rails app turns out to be pretty straightforward. My approach was to start with a clean install of the Caboose sample app (version 3), and add code as necessary from the code generated by Eastmedia's Restful OpenId Authentication Plugin (http://svn.eastmedia.com/svn/bantay/plugins/trunk/restful_open_id_authentication).

Assuming that you are starting with the Sample app, here are the files you need to change:

Models

  • authenticated_system.rb -- no changes
  • User.rb (model) -- the code looks different because the sample app uses authenticated_base mixin (a more encapsulated approach), but I it ends up being nearly identical to the User model in the OpenId plugin. Some quick changes:
    • add open_id_url to the list of attr_accessable, otherwise the session_controller won't be able to set the open_id_url, the password_required? method will always return true, and you'll life will generally be difficult.
    • authenticated_base.rb -- change password_required? method to include: open_id_url.nil? -- see the openId password_required? method.
  • application.rb - no changes

users_controller.rb

  • no changes. The OpenId UserController includes AuthenticatedSystem, but sampleapp includes that in application.rb. The upshot: you can use the sampleApps more complete users_controller directly

session_controller.rb

  • add line: open_id_consumer :required => [:email, :nickname]
  • copy begin and complete methods from the OpenId session_controller.rb

routes.rb

  • add map.resource :session, :collection => { :begin => :post, :complete => :get }

migrations

  • add AddOpenIdTables migration from the OpenId plugin, including the open_id_url column to users

views

  • session/new.rhtml -- replace with the OpenId equivalent
  • user/new.rhtml -- this file is an easy merge, just look for additions in the OpenId new.rhtml

Post a comment

 
This is so filters can reject the spam-bots. Thanks!