I have struggled with this for 2 days now:
I have Omniauth-factbook implemented correctly with Devise. Now, I want to improve it by making the Facebook authentication occurs in the popup window instead of going to facebook.com. I followed Ryan's RailsCast and add display => 'popup'
to my provider configuration in omniauth.rb
I successfully load login to facebook and got returned a hash request.authRequest, which contains information about userId.
However, when I got back to callback path (/auth/facebook/callback), I didn't get :provider and :uid from request.evn[omniauth.auth] like I used to.
Why omniauth hash was not created even when Facebook API returned the authentication hash? What can I do to fix this issue?
My controller to handle facebook callback is simple:
class ServicesController < ApplicationController
def create
auth = request.env["omniauth.auth"]
debugger
Right at the debugger, when I use IRB to check, there's no omniauth hash in request.env.
BTW, I think I turned the cookie on in my coffeescript file:
jQuery ->
$('body').prepend('<div id="fb-root"></div>')
$.ajax
url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js"
dataType: 'script'
cache: true
window.fbAsyncInit = ->
FB.init(appId: '<%= "myAppID" %>', cookie: true)
$('#facebook_signin').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
$('#facebook_signout').click (e) ->
FB.getLoginStatus (response) ->
FB.logout() if response.authResponse
true
Thank you.
Update: my omniauth.rb looks like this:
Rails.application.config.middleware.use OmniAuth::Builder do
# The following is for facebook
provider :linkedin, '3yn', 'iMJ'
provider :twitter, 'SQ', 'T5fo'
provider :facebook, '081', 'e80',
scope: "email"
end