我正在尝试设置omniauth与facebook签名,这是我的设置:
路线:
devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
app / controllers / callbacks_controller.rb中的
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def failure
redirect_to root_path
end
在config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'],
scope: 'email,user_birthday', display: 'popup'
end
如果我点击链接:/users/auth/facebook/
(因为我已经登录到facebook帐户,并且已经有一个用户在数据库中使用电子邮件,就像在facebook中使用的电子邮件一样)
这是发生的网络调用:
http://mywebapp.com/users/auth/facebook/
https://www.facebook.com/dialog/oauth?client_id=xxxxxx&display=popup&redirect_uri=http%3A%2F%2Fmywebapp.com%2Fusers%2Fauth%2Ffacebook%2Fcallback&response_type=code&scope=email%2Cuser_birthday&state=xxxxxx
http://mywebapp.com/users/auth/facebook/callback?code=xxxxxx-xxxxxx-xxxxxx-8phIgyflA_NgL-9-FTkXxwUv-xxxxxx-xxxxxx&state=xxxxxx
然后,浏览器中的最终网址为:
http://mywebapp.com/en#_=_
没有登录,也没有任何Flash消息。
那么,我该如何调试用户为什么不登录?