Using Authlogic to authenticate with only a userna

2019-06-22 18:14发布

问题:

There's this mother app which is on Java (Struts), which also handles authentication. My Rails app which is being integrated into the mother app uses authlogic. Ofcourse, the requirement is, once someone logs into the mother app, they should automatically be able to access my Rails app without signing in again.

Is there any way, by using just the user id , I can authenticate the user using Authlogic?

I removed my password column in my Users table and stuck this piece of code into the User model.

acts_as_authentic do |config|
  config.check_passwords_against_database = false
  config.validate_password_field = false
  config.crypted_password_field = false
end

But I'm still not able to do what I wanted to do.I get an error indicating that the password can't be blank.Help would be appreciated! Thanks.

回答1:

Just pass a user object instead of login/password

UserSession.new(User.find_by_username('Shreyas Satish'))

(This works with rails 3 and authlogic 2.1.6)