To use different Facebook apps for authentication with Devise and OmniAuth:
- Add a setup method to Omniauth that dynamically sets the client id and secret:
# config/initializers/devise.rb
config.omniauth :facebook, nil, nil, setup: true
- Setup a route to your setup method:
# config/routes.rb
match '/auth/:provider/setup' => 'sessions#setup'
- Use the setup method to set the id and secret options in the request object:
def setup
# in this example facebook keys for different site domains are stored in Config
request.env['omniauth.strategy'].options[:client_id] = Config[domain]['appKey']
request.env['omniauth.strategy'].options[:client_secret] = Config[domain]['appSecret']
render :text => "Omniauth setup phase.", :status => 404
end
Caveat: Facebook does a lot of caching even for apps in development mode. Logging in might not immediately work – if in doubt, create a fresh facebook app and check if you can login with its id and secret.
Posted by Rin to BitCrowd (2014-03-07 15:26)