Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 error with twitter/Facebook authentication. Devise

I am working with devise, and I am trying to allow users to signup using twitter/facebook. I am very confused because I keep getting \ No route matches {:controller=>"authentications", :action=>"passthru", :provider=>:twitter, :format=>nil} missing required keys: [:provider]

Routes.rb

 devise_for :users,controllers: {omniauth_callbacks: "authentications", registrations: "registrations"}

AuthenticationController.rb

class AuthenticationsController < ApplicationController
  def index
    @authentications = Authentication.all
  end

  def create
    @authentication = Authentication.new(params[:authentication])
    if @authentication.save
      redirect_to authentications_url, :notice => "Successfully created authentication."
    else
      render :action => 'new'
    end
  end

  def destroy
    @authentication = Authentication.find(params[:id])
    @authentication.destroy
    redirect_to authentications_url, :notice => "Successfully destroyed authentication."
  end
  def twitter
raise omni = request.env["omniauth.auth"].to_yaml
end
end
like image 896
user2206030 Avatar asked Dec 02 '22 22:12

user2206030


2 Answers

I assume you've something like the below in the User model; because of this, you are getting this routing error.

devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable,
         :validatable, :omniauthable,
         :omniauth_providers => [:facebook],
         :omniauth_providers => [:twitter]

Change it to the following:

devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable,
         :validatable, :omniauthable,
         :omniauth_providers => [:facebook, :twitter]
like image 65
Deepak Lamichhane Avatar answered Dec 26 '22 02:12

Deepak Lamichhane


I was following the omniauth example on github and I had

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

but needed to only have the one devise line as follows:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable, :omniauth_providers => [:google]
end
like image 35
Michael Avatar answered Dec 26 '22 00:12

Michael