1

每次新用户(或测试用户)从 facebook(画布)访问我的应用程序时,他都会得到一个空白页面。

如果用户直接导航到应用程序,它就可以工作。比用户从 facebook 获得权限对话框并且必须授予请求的权限。在此之后,用户可以从 facebook canvas 或直接从 *www.MY_APP.com* 使用该应用程序。

我对这个问题的了解:

  1. 它发生在未授予facebook 应用程序权限的新/测试用户身上
  2. 它仅在从 facebook 画布直接访问时发生。

我认为无法从 facebook 显示权限对话框,但我不知道为什么。

我的应用程序是使用 ruby​​ rails 开发的,并使用 OmniAuth 1.4.0 进行登录。

gem 文件

gem 'omniauth'
gem 'omniauth-facebook', '1.4.0'
gem 'oauth2'
gem 'koala'

路线.rb:

match '/canvas'                  => 'sessions#facebook_canvas'
match '/auth/:provider/callback' => 'sessions#create',             :as => :create_session

omn​​iauth.rb 初始化程序:

Rails.application.config.middleware.use OmniAuth::Builder do
  OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
  provider :facebook, APP_ID, APP_SECRET,
       {:scope   => 'email, user_groups, friends_groups, read_stream, read_friendlists, friends_likes, friends_status, offline_access',
        :display => 'popup',
        :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}} }
end

session_controller :

# modified sample code from OmniAuth to handle the signed request
def facebook_canvas
   session[:canvas]         = true
   session[:signed_request] = params[:signed_request]
   # we just redirect to /auth/facebook here which will parse the
   # signed_request FB sends us, asking for auth if the user has
   # not already granted access, or simply moving straight to the
   # callback where they have already granted access.
   #
   # we pass the state parameter which we can detect in our callback
   # to do custom rendering/redirection for the canvas app page
   redirect_to "/auth/facebook?signed_request=#{request.params['signed_request']}&state=canvas"
end

# create a session, when the user 
def create
   auth = request.env["omniauth.auth"]
   user = User.from_omniauth(env["omniauth.auth"])
   if user  
      session[:fb_token] = auth["credentials"]["token"] if auth['provider'] == 'facebook'     
      redirect_to_target_or_default root_url #, :notice => "Logged in successfully."
      redirect_to confirm_abg_path(:user => user.id)
   else
      flash.now[:alert] = "Invalid login or password."
      redirect_to root_url
   end
end

我希望任何人都可以帮助我。

4

0 回答 0