Skip to content

Instantly share code, notes, and snippets.

@markoa
Created October 19, 2010 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoa/634541 to your computer and use it in GitHub Desktop.
Save markoa/634541 to your computer and use it in GitHub Desktop.
Monkey patch for OmniAuth::Strategy to make it Rack::Config configurable. Here we also include sample middleware that sets different configuration within an app serving many domains.
module App
module Middleware
class OmniAuthConfigurator
def initialize(app)
@app = app
end
def call(env)
current_domain = env["SERVER_NAME"] || env["HTTP_X_FORWARDED_FOR"]
website = Website.find_by_domain(current_domain)
if website.present?
env["omniauth.facebook.client_id"] = website.facebook_app_id
env["omniauth.facebook.client_secret"] = website.facebook_app_secret
end
@app.call(env)
end
end
end
end
module OmniAuth
module Strategy
def call!(env)
@env = env
### The custom part that looks for Rack::Config-uration
#
client_id = @env["omniauth.#{self.name}.client_id"]
client_secret = @env["omniauth.#{self.name}.client_secret"]
if client_id
self.client.id = client_id
self.client.secret = client_secret
end
###
if request.path == "#{OmniAuth.config.path_prefix}/#{name}"
request_phase
elsif request.path == "#{OmniAuth.config.path_prefix}/#{name}/callback"
callback_phase
else
if respond_to?(:other_phase)
other_phase
else
call_app!
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment