0
votes

I have a classic omniauth problem, when trying to access the '/auth/twitter'.

The problem with the other solutions out there is that I can't remove :omniauthable from user.rb, because the facebook authentication won't work.

Also, If I remove the devise lines below, the twitter authentication works. It seems that there is a compatibility problem between twitter and facebook with omniauth, does anyone have a solution?

Thanks

devise.rb

require "omniauth-facebook"
config.omniauth :facebook, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET

Gemfile

# Users from facebook
gem 'omniauth'
gem 'omniauth-facebook'

omniauth.rb

OmniAuth.config.logger = Rails.logger 

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET
end

models/user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, 
         :confirmable, :omniauthable, omniauth_providers: [:facebook]
end
1

1 Answers

1
votes

When you are using OmniAuth with Devise, you have to configure OmniAuth providers in the devise.rb file.

So you should configure the omniauth-twitter gem like you are already configuring the omniauth-facebook gem:

Devise.setup do |config|
  config.omniauth :facebook, "FACEBOOK_KEY", "FACEBOOK_SECRET"
  config.omniauth :twitter, "TWITTER_KEY", "TWITTER_SECRET"
end

You can also remove the following from your code:

  1. The omniauth gem in your Gemfile.

  2. The require "omniauth-facebook" statement in your devise.rb file.

  3. The omniauth_providers: [:facebook] hash in your user.rb file.