R – authlogic openid auto_register feature tries to duplicate registration

authlogicauthlogic-oidopenidruby-on-rails

I am trying to enable openid authentication on my website as well as use auto_register feature of latest authlogic_openid add-on.

Everything works fine until second login. The first time user is created and logged in, but after I logout and try logging in into the system with same OpenID identifier I get user registration form with errors saying that username and other fields are already taken and the form is prefilled with values of earlier data passed with openid.

Everything is implemented by authlogic/authlogic openid tutorial except for the user session model with new auto_register call:

class UserSession < Authlogic::Session::Base
  auto_register
end 

Any help much appreciated!

Best Answer

It seems like you're registering the users twice. The OpenID plugin doesn't know whether or not a user has been registered it just does SREG every time if auto_register is true. Rather than calling auto_register every time you could look up the user by openid_identifier and send auto_register(true) if they're a new user.