简体   繁体   中英

Omniauth-facebook popup authentication does not return omniauth.auth

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

(I have to answer rather than comment while I'm new-ish here.)

You appear to be mixing up a few things. Specifying :display => 'popup' does not trigger a popup window. It is a Facebook-related option that specifies the display mode of the login form (explained here: https://developers.facebook.com/docs/reference/dialogs/oauth/ )

Turn omniauth facebook login into a popup explains some of what's going on, but you probably don't want to maintain your own popup window. Facebook's JavaScript SDK does this with the FB.login function (explained here: https://developers.facebook.com/docs/reference/javascript/FB.login/ )

It's difficult to troubleshoot without all relevant code posted. From what you wrote, it sounds like the JavaScript side is working correctly. Out of curiosity, what does your omniauth.rb initializer look like?

i did some tests and read comments abouts the railscast and you need to downgrade the gem

gem 'omniauth-facebook', '1.4.0'

If you need more information about it :

http://railscasts.com/episodes/360-facebook-authentication?view=comments#comment_159418

here the code : https://github.com/senayar/facebook_connect

hope it helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM