基于子域动态设置appnia,omniauth-facebook gem的appsecret

时间:2012-04-19 11:10:39

标签: ruby-on-rails facebook omniauth

我们的ror应用程序中的每个客户都是基于子域服务的,他们有自己的fbappid,fbsecretid(为客户提供fb应用程序)。我们使用omniauth,omniauth-facebook来验证用户。 所以customer1.ourapp.com通过appid fbapp_1和一个fb app提供服务    使用appid fbapp_2的customer2.ourapp.com服务器

正常的facebook策略初始化方法是将以下行放在初始化程序中

config.omniauth :facebook, APP_ID, SECRET, {:scope => 'publish_stream}

我们需要根据子域设置APP_ID,SECRET,但看起来请求对象在初始化时不可用 我使用setup =>查看了选项的动态设置。但omniauth-facebook似乎并不支持动态appidcret的设置。

我们如何根据请求的子域动态设置omniauth-facebook的app_id和app_secret?提前谢谢

1 个答案:

答案 0 :(得分:3)

由于您正在使用设计,请尝试

config.omniauth  :facebook, :setup => lambda{
      current_domain = // Get current domain
      config = // Get config
      env['omniauth.strategy'].options[:client_id] = config[current_domain][Rails.env]["app_id"]
      env['omniauth.strategy'].options[:client_secret] = config[current_domain][Rails.env]["app_secret"]
    }

http://webcache.googleusercontent.com/search?q=cache:zmBqDAomJ84J:blog.cedricbousmanne.com/+&cd=2&hl=en&ct=clnk 提供没有设计的解决方案,只需omniauth

[编辑] 摘录自工作代码

config.omniauth :facebook, {:setup => lambda{|env|
   env['omniauth.strategy'].options[:client_id] = $institute_tenant.fbappid
   env['omniauth.strategy'].options[:client_secret] = $institute_tenant.fbappsecret
}, :auth_type => 'https', :scope => 'email'}
相关问题