omniauth 0.2.6 具有多个域名 [英] omniauth 0.2.6 with multiple domain names
问题描述
我的网络应用程序使用了不同的域名(www.example.heroku.com、www.example2.com 和 www.example3.com).身份验证使用 Omniauth 0.2.6
I am using different domain names for my web application (www.example.heroku.com, www.example2.com and www.example3.com). Authentication is with Omniauth 0.2.6
如果我希望我的用户通过 Facebook 进行身份验证,我需要为每个域名使用不同的 Facebook 应用帐户,因此需要不同的应用 ID 和密钥.
If I want my users to authenticate via Facebook, I need a different Facebook app account for each domain name, so a different app ID and secret key.
在 omniauth 初始值设定项(provider :facebook, "APP_ID", "APP_SECRET")中定义应用 ID 和密钥时,我该如何:
When defining the app ID and secret key in the omniauth initializer (provider :facebook, "APP_ID", "APP_SECRET"), how can I:
定义多个应用 id/keys
define multiple app ids/keys
或有条件地定义当前域名的id/keys
or define the ids/keys conditionally to the current domain name
我一整天都在尝试但没有成功......
I've been trying all day without success...
推荐答案
此设置已在 设置阶段
您现在必须在您的 omniauth.rb 中进行设置
You now have to set this up in your omniauth.rb
provider_keys = YAML.load_file(File.join(Rails.root, 'config', 'provider_keys.yml'))
SETUP_PROC = lambda do |env|
env['omniauth.strategy'].options[:client_id] = provider_keys[Rails.env]['facebook'][server_name]['consumer_key']
env['omniauth.strategy'].options[:client_secret] = provider_keys[Rails.env]['facebook'][server_name]['consumer_secret']
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, setup: SETUP_PROC
end
你的 provider_keys.yml 看起来像这样
and your provider_keys.yml will look something like this
development:
facebook:
www.example.heroku.com:
consumer_key: 'xxxxxxxx'
consumer_secret: 'xxxxxxxx'
www.example.com:
consumer_key: 'xxxxxxx'
consumer_secret: 'xxxxxxx'
这篇关于omniauth 0.2.6 具有多个域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!