Simple OmniAuth-Twitter cannot create a new user due to validation

I freely follow Railscasts Simple OmniAuth http://railscasts.com/episodes/241-simple-omniauth to create my Twitter login. When I try to log in and create a new user via twitter, I get the following message:

Validation failed: Password can't be blank, Name is not valid., Email can't be blank, Email is not valid. 

If I click the refresh button, I get the following error:

 OAuth::Unauthorized 401 Unauthorized 

I already set the callback url to http: http://127.0.0.1:3000/auth/twitter/callback , but I still get this message. I am testing a local host.

I modeled my users after the Hartl registries http://ruby.railstutorial.org/ruby-on-rails-tutorial-book , and my website project requires users to have fields filled in.

Unlike railscasts, I created a new method for controlling omniauth inputs:

sessions_controller.rb

 def omniauth_create auth = request.env["omniauth.auth"] user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth) session[:user_id] = user.id redirect_to user end 

user.rb

 def self.create_with_omniauth(auth) create! do |user| user.provider = auth["provider"] user.uid = auth["uid"] user.name = auth["info"]["name"] end end 

Question: How to bypass the checks?

So far I have been trying to use skip_before_filter :authenticate, :only => [:omniauth_create] , but that did not work.

Thanks.

0
source share
1 answer

There are two ways to skip checks. Either you can skip them all by passing :validate => false to the create method (usually this is Bad Idea), or you can change your checks to something like the following:

user.rb

 validates_confirmation_of :password, :if => :password_required? def password_required? !provider.blank? && super end 
+1
source

Source: https://habr.com/ru/post/1437038/


All Articles