Using has_secure_password and oauth authentication (like facebook)

I'm interested in using both of these authentication schemes, but setting a custom model to has_secure_password

force the validation to password_digest

. I'm curious if there is a standard way to create a user via oauth mechanism this way for rails 3.1.x with omniauth-facebook. How to bite into the value test

in password_digest or whatever? Or perhaps turning off stateful checks when used with has_secure_password (although I don't know how to do this and would appreciate help).

I see there is a commit for oauthed_user ( https://github.com/rails/rails/blob/master/activemodel/test/models/oauthed_user.rb ) but I'm not sure how this should be used.

thanks for any info / advice

+3


source to share


1 answer


Well I don't know a standard way to do this, but I did it in my application and it works great

def create
  if user_is_from_omniauth?
    @user.password = SecureRandom.hex(9)
  end
  @user.save
end

      



And now you have to log in without using a password For this it is recommended to put a boolean value in your database so that it does not ask for the old password in case of a password change or forgets the password

0


source







All Articles