Install appid, appsecret of omniauth-facebook gem dynamically based on subdomain

Each client in our ror application is served based on a subdomain, and they have their fbappid, fbsecretid (which runs the application for fb users). We use omniauth, omniauth-facebook to authenticate users. therefore customer1.ourapp.com serves for fb application with appid fbapp_1 and customer2.ourapp.com server with appid fbapp_2

The usual way to initialize a facebook strategy is to set the next line in the 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 the request object is not available during the initialization time. I looked at the dynamic settings using setup =>, but omniauth-facebook does not seem to support setting appid, appsecret dynamically.

How do we set app_id and app_secret from omniauth-facebook dynamically based on the request subdomain? thanks in advance

+3
source share
1 answer

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 a solution without development, with just omniauth

[edit] 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'}
+3
source

All Articles