views:

197

answers:

2

I'm creating a rails app that will run on the same domain as an older app. I would like to be able to use the restful login functionality of the older app to authenticate users for the new app. Ideally, the user could login to the old app and then have access to the new app. I'm running two mongrel instances for each app. Any help is much appreciated

A: 

If you use the same version of the authentication plugin you can use a different database to authenticate against.

Rails doesn't handle multiple database connections so you'll have to use a hack like this: Multiple Database Connections in Ruby on Rails.

Then install the exact same plugin as you have in the old app so that it uses the same database schema. Then in the User model switch the database connection to the old database.

Lolindrath
Thanks lolindrath. Would this setup allow a shared session between the apps, so that if a user logged into the older app and then clicked on a link to the newer app they would not have to login again? I was under the impression this setup would allow authentication to the same database but not shared sessions across apps.
chase
+1  A: 

So I figured it out. Connecting to the user database (as lolindrath suggested) to allow the newer app to have access to the user database gets us half way there. The user can now login to the newer app with restful just like the old app, but the authentication doesn't transfer from one app to the other. To allow a single login to work for both apps, you have to copy the cookie session data from the older app to the newer app.

So, in the ./config/initializers/sessiont_store.rb file paste the below data from the old app to the new app (older versions of rails has it in the ./config/environment.rb file):

ActionController::Base.session = {
    :domain      => '.localhost.com',
    :session_key => '_Project_name_session',
    :secret      => '09808ajdsfkljdfwu309jas3longerkey'
    }
chase