0
votes

I'm following Ryan bates cast #225 devise and omniauth revised...once i click the link sign up with twitter it takes me to the

api.twitter.com/oauth/authenticate?oauth_token=vJQeSrxYa6gXSFUspRP9wuzgHTgGRDoN5YjenRGnDcU

page where it says Authorize batman-fansite to use your account? when i click SIGN IN nothing happens and I do not get sent back to my site and obviously not logging me in or signing me up.

the url changes to https://api.twitter.com/oauth/authenticate

but other than that nothing happens been working on this for hours now and followed every suggestion possible.....

please help

devise.rb

       config.omniauth :twitter, ENV["I PUT MY CONSUMER KEY HERE"], ENV["I PUT MY CONSUMER PASSWORD HERE"]

I also have an

omniauth.rb

         Rails.application.config.middleware.use OmniAuth::Builder do
             provider :twitter, 'I PUT MY CONSUMER KEY HERE', 'I PUT MY CONSUMER PASSWORD HERE'
         end

ive heard some suggestions that if you delete the omniauth.rb it will work since its already in your devise.rb but if i delete OMNIAUTH.RB i get a 301 Unathorized error and does not send me to the TWITTER SIGN IN PAGE......

if i get rid of the piece of code in devise.rb(not the whole file just the vonfig.omniauth part) and keep omniauth.rb I get a routing error

heres my

user.rb

    class User < ActiveRecord::Base
     # Include default devise modules. Others available are:
     # :token_authenticatable, :confirmable,
     # :lockable, :timeoutable and :omniauthable
     devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable, :omniauthable

     # Setup accessible (or protected) attributes for your model
     attr_accessible :email, :password, :password_confirmation, :remember_me, :username

     validates_presence_of :username
     validates_uniqueness_of :username

     def self.from_omniauth(auth)
       where(auth.slice(:provider, :uid)).first_or_create do |user|
       user.provider = auth.provider
       user.uid = auth.uid
       user.username = auth.info.nickname
     end
    end

    def self.new_with_session(params, session)
      if session["devise.user_attributes"]
      new(session["devise.user_attributes"], without_protection: true) do |user|
      user.attributes = params
      user.valid?
    end
  else
  super
end
end

def password_required?
  super && provider.blank?
end

def update_with_password(params, *options)
  if encrypted_password.blank?
  update_attributes(params, *options)
else
  super
end
end
end

my omniauth_callbacks_controller.rb

 class OmniauthCallbacksController < Devise::OmniauthCallbacksController
 def all
   user = User.from_omniauth(request.env["omniauth.auth"])
   if user.persisted?
     flash.notice = "Signed in!"
    sign_in_and_redirect user
   else
     session["devise.user_attributes"] = user.attributes
    redirect_to new_user_registration_url
    end
   end
   alias_method :twitter, :all
  end

routes.rb

        devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}, 
          controllers: {omniauth_callbacks: "omniauth_callbacks"}

in my gem file

gem 'omniauth-twitter', :github => 'arunagw/omniauth-twitter'

I've tried adding omniauth gem as well but that did not do anything

and in my views i have

  = link_to "Sign in with Twitter", user_omniauth_authorize_path(:twitter) 

At twitter developer site I've registered my site added a callback url

and i made application type read and write...ive tried READ ONLY but that gets me a 401 error and Ive also tried READ WRITE AND ACCESS FIRECT MESSAGES but nothing works

only thing that send me to the actual twitter sign in page is if i check READ AND WRITE

If anyone has any suggestions PLEASE HELP

Thank you

1

1 Answers

0
votes

You have to set callback properly. if you are using localhost in your development then your callback should be

http://localhost:3000/auth/twitter/callback

You can also use IP address instead of localhost i.e. 127.0.0.1