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 changesUser.rb(model) -- the code looks different because the sample app usesauthenticated_basemixin (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_urlto the list ofattr_accessable, otherwise thesession_controllerwon't be able to set theopen_id_url, thepassword_required?method will always return true, and you'll life will generally be difficult. authenticated_base.rb-- changepassword_required?method to include:open_id_url.nil?-- see the openIdpassword_required?method.
- add
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
beginandcompletemethods from the OpenIdsession_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_urlcolumn 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
