views:

174

answers:

1

Warp Drive is a nice way to package an entire Rails application into a Gem for use in other Rails applications. I've gotten Warp Drive to work for a blogging engine I'm creating. There's just one problem - Authlogic OpenID authentication fails.

I created a bare-bones OpenID example application. I can compile to a gem with no problems:

$ warpify
$ rake warp_drive:compile

I then installed the compiled gem on my system. Creating a blank Rails project, I ran:

$ install_warp_drive rails-openid

You can get this project here.

In my blank Rails projects, I needed to configure gems through environment.rb (I'm probably doing this the wrong way):

config.gem "authlogic"
config.gem "authlogic-oid", :lib => "authlogic_openid"
config.gem "ruby-openid", :lib => "openid"

To get the blank Rails application working, I ran rake db:migrate, then through the console I added a user with an :openid_identifier field set to one that I control. So far so good. But trying to create a new session fails with this error:

    Processing UserSessionsController#create (for 127.0.0.1 at 2009-12-31 11:35:59) [POST]
    Parameters: {"commit"=>"Login", "user_session"=>{"openid_identifier"=>"richdev.myopenid.com"}, "authenticity_token"=>"BcsIKNpumqZrTV/bdSLQ6szBvq6kpaAIxJRmYgxySLU="}
    OpenIdAuthentication::Association Load (0.3ms)   SELECT * FROM "open_id_authentication_associations" WHERE ("open_id_authentication_associations"."server_url" = 'http://www.myopenid.com/server') 
    Generated checkid_setup request to http://www.myopenid.com/server with assocication {HMAC-SHA1}{4b3cf228}{mWlzhg==}
    Redirected to http://www.myopenid.com/server?openid.assoc_handle=%7BHMAC-SHA1%7D%7B4b3cf228%7D%7BmWlzhg%3D%3D%7D&openid.ax.mode=fetch_request&openid.identity=http%3A%2F%2Frichdev.myopenid.com%2F&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Flocalhost%3A3001%2Fuser_sessions%2Fcreate%3Ffor_session%3D1%26_method%3Dpost%26open_id_complete%3D1%26openid1_claimed_id%3Dhttp%253A%252F%252Frichdev.myopenid.com%252F%26rp_nonce%3D2009-12-31T19%253A35%253A59ZUEd2eN&openid.trust_root=http%3A%2F%2Flocalhost%3A3001%2F
    Completed in 15ms (DB: 0) | 302 Found [http://localhost/user_sessions]


    Processing ApplicationController#index (for 127.0.0.1 at 2009-12-31 11:36:00) [POST]
    Parameters: {"openid.mode"=>"id_res", "openid.return_to"=>"http://localhost:3001/user_sessions/create?for_session=1&_method=post&open_id_complete=1&openid1_claimed_id=http%3A%2F%2Frichdev.myopenid.com%2F&rp_nonce=2009-12-31T19%3A35%3A59ZUEd2eN", "openid.sig"=>"l+tfFAmeKsskHKlOYRoZF7yHM7Q=", "rp_nonce"=>"2009-12-31T19:35:59ZUEd2eN", "openid.op_endpoint"=>"http://www.myopenid.com/server", "for_session"=>"1", "openid.response_nonce"=>"2009-12-31T19:36:00ZBhX5fE", "openid1_claimed_id"=>"http://richdev.myopenid.com/", "openid.identity"=>"http://richdev.myopenid.com/", "open_id_complete"=>"1", "openid.assoc_handle"=>"{HMAC-SHA1}{4b3cf228}{mWlzhg==}", "openid.signed"=>"assoc_handle,identity,mode,op_endpoint,response_nonce,return_to,signed"}

    ActionController::MethodNotAllowed (Only get, put, and delete requests are allowed.):


    Rendered rescues/_trace (96.3ms)
    Rendered rescues/_request_and_response (0.5ms)
    Rendering rescues/layout (method_not_allowed)

The problem seems to occur during the redirect back from the openid provider, at which point ApplicationController#index gets called, instead of UserSessionsController#create. I'm not sure if this is an OpenID issue or a Warp Drive issue.

How can I bundle an Authlogic/OpenID application as a Warp Drive Gem and get authentication to work successfully?

Update: Adding an explicit resource definition for user_session fixes the problem. In routes.rb:

map.resources :user_sessions

Not sure why, and this doesn't seem to be required for any other controller.

A: 

Two things worked:

  1. Add an explicit user_session resource definition in routes.rb:

    map.resources :user_sessions

  2. Remove default routes in routes.rb of the app using the warp drive gem.

Rich Apodaca