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
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'
}
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.
精彩评论