0

I am relatively new to Rails and I am having problems getting omniauth-facebook to work. I have managed to add the link 'Sign in with Facebook' onto my application (details to follow), and when I click it I am taken to:

https://www.facebook.com/dialog/oauth?client_id=etc.

It doesn't load anything. Not even any helpful error messages. :( Just a blank white screen.

When I read my rails s logs, it is stuck at:

Started GET "/users/auth/facebook" for 127.0.0.1 at 2014-08-21 10:48:30 -0400 I, [2014-08-21T10:48:30.308966 #29948] INFO -- omniauth: (facebook) Request phase initiated.

The only other post I can find with a similar problem is here. I have changed the port I'm working on as suggested but it makes no difference.

So, more details:

I have been tinkering with this for several hours, using Railscasts, Omniauth documentation, and different guides around the internet. Every attempt has lead me to this same brick wall. Currently, I am following this OmniAuth overview for Facebook with Devise over at GitHub and have followed it up to adding

%li= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook)

to my layout.

I have

gem 'omniauth'

gem 'omniauth-facebook'

in my gemfile.

Have added

devise :omniauthable, :omniauth_providers => [:facebook]

to my User.rb file, added uid and provider columns to my Users table, and added

config.omniauth :facebook, 'KEY', 'SECRET'

to config/initializers/devise.rb.

This is all I have added to a very basic application, which has only the Devise User model and a few other models related to my domain.

Can someone help me figure this out? It's driving me nuts.

Edit:

I am using Rails 4.1.4 and Ruby 2.1.2 and the most recent omniauth and omniauth-facebook gems.

routes.rb

devise_for :users, :controllers => { :omniauth_callbacks => 'users/omniauth_callbacks' }
resources :users, :only => [:show, :index]
root 'main#index'

and rake routes:

                  Prefix Verb     URI Pattern                            Controller#Action
        new_user_session GET      /users/sign_in(.:format)               devise/sessions#new
            user_session POST     /users/sign_in(.:format)               devise/sessions#create
    destroy_user_session DELETE   /users/sign_out(.:format)              devise/sessions#destroy
           user_password POST     /users/password(.:format)              devise/passwords#create
       new_user_password GET      /users/password/new(.:format)          devise/passwords#new
      edit_user_password GET      /users/password/edit(.:format)         devise/passwords#edit
                         PATCH    /users/password(.:format)              devise/passwords#update
                         PUT      /users/password(.:format)              devise/passwords#update
cancel_user_registration GET      /users/cancel(.:format)                devise/registrations#cancel
       user_registration POST     /users(.:format)                       devise/registrations#create
   new_user_registration GET      /users/sign_up(.:format)               devise/registrations#new
  edit_user_registration GET      /users/edit(.:format)                  devise/registrations#edit
                         PATCH    /users(.:format)                       devise/registrations#update
                         PUT      /users(.:format)                       devise/registrations#update
                         DELETE   /users(.:format)                       devise/registrations#destroy
 user_omniauth_authorize GET|POST /users/auth/:provider(.:format)        users/omniauth_callbacks#passthru {:provider=>/facebook/}
  user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:facebook)
                   users GET      /users(.:format)                       users#index
                    user GET      /users/:id(.:format)                   users#show
                    root GET      /                                      main#index

I have added the omniauth_callbacks controller and understand what I didn't earlier - that pointing towards that controller to find actions that aren't in Devise::OmniauthController is not adding a route, as I initially thought. Anyway, this doesn't solve my Facebook problem, but I thought I'd edit this to correct my earlier misunderstanding anyway.

More edits

I got omniauth-github working with the following:

routes.rb:

devise_for :users, :controllers => { :omniauth_callbacks => 'omniauth_callbacks' }
resources :users, :only => [:show, :index]
root 'main#index'

user.rb:

devise :omniauthable, :omniauth_providers => [:facebook, :github]

omniauth_callbacks_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def github
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user
      set_flash_message(:notice, :success, :kind => "Github") if is_navigational_format?
    else
      session["devise.github_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end
end

devise.rb:

config.omniauth :github, 'KEY', 'SECRET'

I have successfully gotten Sign in with Twitter to work the same way.

I have made a facebook action for the OmniatuhsCallbackController that is the exact same as the github action, only with facebook in place of github and am still running into the same issue with facebook.

Community
  • 1
  • 1
wendybeth
  • 424
  • 4
  • 17

0 Answers0