当每个请求的应用程序ID和应用程序秘密不同时,使用omniauth-facebook吗?

问题描述:

omniauth-facebook 自述文件提到了如何在初始化程序中进行设置以及如何设置诸如scope之类的选项仅根据请求.我想知道是否还可以为每个请求设置应用程序ID和应用程序密码.

The omniauth-facebook README mentions how to set it up in an initializer and how to set options like scope per request only. I wonder if it is possible to set app id and app secret per request as well.

您可以执行以下操作:

在您的omniauth.rb上,执行以下操作:

On your omniauth.rb, do this:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook,:setup => true
end

然后,您必须在控制器上定义以下内容:

Then on your controller you have to define the following:

def setup
 request.env['omniauth.strategy'].options[:client_id] = @site.facebook_key
 request.env['omniauth.strategy'].options[:client_secret] = @site.facebook_secret
 render :text => "Setup complete.", :status => 404
end

当然,您必须在route.rb上添加关联的路由.

Of course you have to add the associated routes, on your routes.rb.

  #Facebook Omniauth routes
  match '/auth/facebook/callback' => 'session#authorize_callback'
  match '/auth/facebook/setup' => 'session#setup'

祝你好运

关于. 伊万.