Reputation: 283
Each customer in our ror app is served based on subdomain and they have their fbappid, fbsecretid (whichi powers the customers fb app). We use omniauth, omniauth-facebook for authenticating users. so customer1.ourapp.com serves an fb app with appid fbapp_1 and customer2.ourapp.com server with appid fbapp_2
normal way of initialization of facebook strategy is putting the following line in a initializer
config.omniauth :facebook, APP_ID, SECRET, {:scope => 'publish_stream}
We need to set APP_ID, SECRET based on the subdomain, but it looks like request object is not avaiable at the initializer time I looked into the dynamic setting of options using setup=> but omniauth-facebook doesnt seem to support setting of appid, appsecret dynamically.
How do we set the app_id and app_secret of omniauth-facebook dynamically based on subdomain of the request? thanks in advance
Upvotes: 3
Views: 1177
Reputation: 112
Since you are using devise, try
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 provides the solution without devise, with just omniauth
[edited] Excerpt from working code
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'}
Upvotes: 3