【问题标题】:Set appid, appsecret of omniauth-facebook gem dynamically based on subdomain基于子域动态设置omniauth-facebook gem的appid、appsecret
【发布时间】:2012-04-19 11:10:39
【问题描述】:

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

facebook 策略初始化的正常方式是将下面一行放入初始化器中

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

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

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

【问题讨论】:

    标签: ruby-on-rails facebook omniauth


    【解决方案1】:

    既然你用的是devise,那就试试吧

    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'}
    

    【讨论】:

    • 这不起作用,config.omniauth :facebook 需要另外两个参数(设计 1.4.9)
    • @Victor 希望这能回答你的问题?
    猜你喜欢
    • 2016-03-20
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 2014-05-23
    • 2012-03-05
    相关资源
    最近更新 更多