OmniAuth策略Facebook NoAuthorizationCodeError(必须通过`code`参数或签名请求(通过`signed_request`参数): [英] OmniAuth Strategies Facebook NoAuthorizationCodeError (must pass either a `code` parameter or a signed request (via `signed_request` parameter):

查看:235
本文介绍了OmniAuth策略Facebook NoAuthorizationCodeError(必须通过`code`参数或签名请求(通过`signed_request`参数):的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误:

 OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (must pass either a 
`code` parameter or a signed request (via `signed_request` parameter or a 
`fbsr_XXX` cookie)):

它不会一直在。它有一段时间,通过airbrake通知。

Its not coming all the time. Its coming once in a while, notified by airbrake.

这个谷歌搜索有很多链接,但无法找到一个正确的解决方案..任何人?
omniauth.rb在initializers目录下:

There are lot of links for this on google search but not able to find out a proper solution.. Anyone? omniauth.rb under initializers directory:

OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}, :scope => 'user_about_me,email,publish_actions,user_location,publish_stream,offline_access,user_interests,user_likes,user_hometown', :display => 'popup'}      

  OmniAuth.config.on_failure = Proc.new do |env|
    #this will invoke the omniauth_failure action in SessionsController.
    "SessionsController".constantize.action(:omniauth_failure).call(env)
  end         
end

PS:我正在使用facebook javascript sdk与 facebook-omniauth

PS: I am using facebook javascript sdk with facebook-omniauth

推荐答案

我也在使用带有omniauth-facebook的FB JS SDK时遇到了这个错误。
我通过发送带有GET的signed_request参数来修复它,如下所示:

I recently encountered this error when also using the FB JS SDK with omniauth-facebook. I fixed it by sending the signed_request parameter with the GET as shown below:

$(document).bind("fb.loaded", function() {
  FB.getLoginStatus(function(response) {

    console.log('FB STATUS: ' + response.status);
    if(response.status == "connected") {

      console.log("FB AUTHED");

      location.href =
        '/auth/facebook/callback?' +
        $.param({ signed_request: response.authResponse.signedRequest })
      });

    }
  });
});

当用户在登录FB但不是您的网站时访问您的网站时,会发生此情况。经常需要签署后续的请求到omniauth回调:

The scenario occurs when a user visits your site when already logged into FB but not your site. One often needs to sign the subsequent request to the omniauth callback:

Request URL:
http://localhost:3000/auth/facebook/callback?signed_request=QXZa2TPs8JiSgSAQkrS7Y7ObPZQDYLcU_JNvD6Wru_o.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUURjQXdZUdVOMEFmd1RCbjRDQWp4eHpKcWRoRllOS1owLVZpa2pKTUQxSU1UbHJzbmEyMVNUUUtOLWl6b1dJOXJVRWUyWTBNd3ViZ1JxcmZJQmVMRDNOREI2M1EwREtqVzJCeVxTU2ZMR1foWlVwOEVlX0dMVUtwYUlqcWlaQ2FSc1h5c0NBNHdyZDBxbk4taU1haWp2cVFIX19QdUhxaldFcUtYZDc1LS1oZmptcTg4QVVuemVJdDJ4S2VOd3VPZG9vOGtaQkZlZmctZ2FDMk9CNl8wZ24iLCJpc3N1ZWRfYXQiOjEzNTg5NzQ4NzMsInVzZXJfaWQiOiIxMDYwMTg4NyJ9`

如果使用AJAX,则需要这样的:

If using AJAX, you would need something like this:

      $.get(
        '/auth/facebook/callback',
        { signed_request: response.authResponse.signedRequest },
        function(json) {
          alert("received logged in response");
      });

这篇关于OmniAuth策略Facebook NoAuthorizationCodeError(必须通过`code`参数或签名请求(通过`signed_request`参数):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆