Skip email validation for omniauth-twitter on devise 2.0

后端 未结 4 1261
Happy的楠姐
Happy的楠姐 2020-12-08 22:01

I\'m using devise 2.0 and gem omniauth-twitter

The problem is that twitter does not send an email in response, so the model user of my application validates that the

相关标签:
4条回答
  • 2020-12-08 22:33

    A solution is explained thoroughly here: http://asciicasts.com/episodes/236-omniauth-part-2

    And on GitHub: https://github.com/fertapric/rails3-mongoid-devise-omniauth/wiki/How-To:-Retrieve-email-information-(middle-step)-from-providers-like-Twitter-or-LinkedIn

    For some reason, this question shows up higher in Google's ranks than these links, so I thought I'd add them to the answers.

    0 讨论(0)
  • 2020-12-08 22:41

    I am facing the same problem, Twitter doesn't give you the email via oauth, you have to think in another way to obtain the email. The only solution that I figured out, is override the callback and use the twitter data to autocomplete a form and give the user the chance to complete his mail by himself and then sign up and save the user in the database.

    Look the following question:

    Is there a way to get an user's email ID after verifying his/her Twitter identity using OAuth?

    0 讨论(0)
  • 2020-12-08 22:49

    Add this to your User model:

    def email_required?
      super && provider.blank?
    end
    

    You can use an equivalent method for the password:

    def password_required?
      super && provider.blank?
    end
    

    This should override the field requirements when using Omniauth providers.

    0 讨论(0)
  • 2020-12-08 22:51

    You need to remove the presence validation of the email field. Follow this post and see if that works. Sorry for the late response, hope this helps.

    0 讨论(0)
提交回复
热议问题