Created
October 19, 2010 16:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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