Rack 1.2's request.url method is buggy, as it gets the host part from HTTP_X_FORWARDED_HOST, but the port from SERVER_PORT (which should be used in conjuction with SERVER_ADDR). This way, if the app is run behind a reverse proxy, it will create a URL with <public_host>:<private port>, and pass this to Facebook, so Facebook will redirect back to the URL with the wrong port. Upgrading Rack requires upgrade to Rails 3.1. This temporary solution configures OmniAuth using a copy of the newer version of Rack::Request.
26 lines
1.3 KiB
Ruby
26 lines
1.3 KiB
Ruby
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
# licensed under the Affero General Public License version 3 or later. See
|
|
# the COPYRIGHT file.
|
|
|
|
require_dependency "rack/fixed_request"
|
|
OmniAuth.config.full_host = lambda do |env|
|
|
request_url = Rack::FixedRequest.new(env).url
|
|
# Copied from OmniAuth::Strategy#full_host (omniauth-0.2.6)
|
|
uri = URI.parse(request_url.gsub(/\?.*$/,''))
|
|
uri.path = ''
|
|
uri.query = nil
|
|
uri.to_s
|
|
end
|
|
|
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
if SERVICES['twitter'] && SERVICES['twitter']['consumer_key'] && SERVICES['twitter']['consumer_secret']
|
|
provider :twitter, SERVICES['twitter']['consumer_key'], SERVICES['twitter']['consumer_secret']
|
|
end
|
|
if SERVICES['tumblr'] && SERVICES['tumblr']['consumer_key'] && SERVICES['tumblr']['consumer_secret']
|
|
provider :tumblr, SERVICES['tumblr']['consumer_key'], SERVICES['tumblr']['consumer_secret']
|
|
end
|
|
if SERVICES['facebook'] && SERVICES['facebook']['app_id'] && SERVICES['facebook']['app_secret']
|
|
provider :facebook, SERVICES['facebook']['app_id'], SERVICES['facebook']['app_secret'], { :scope => "publish_stream,email,offline_access",
|
|
:client_options => {:ssl => {:ca_file => AppConfig[:ca_file]}}}
|
|
end
|
|
end
|