Lately I had some problems with invalid callback url I was getting on my production server (shared host). Omniauth in response included port used internally by nginx (eg. this could be the case eg. when you have varnish in front of you web server) - after browsing the source code of omniauth gem I have found out that you can easily fix if without even touching webserver configuration (and I didn’t had access to it anyway :P).

So take a look at strategy.rb, you have there method full_host and as you see below in the first place it tries to fetch it’s value from user’s configuration.

# omniauth/lib/omniauth/strategy.rb
def full_host
  case OmniAuth.config.full_host
    when String
      OmniAuth.config.full_host
    when Proc
      OmniAuth.config.full_host.call(env)
    else
      uri = URI.parse(request.url.gsub(/\?.*$/,''))
      uri.path = ''
      uri.query = nil
      #sometimes the url is actually showing http inside rails because the other layers (like nginx) have handled the ssl termination.
      uri.scheme = 'https' if request.ssl?
      uri.to_s
  end
end

So to fix it you can add to your production environment something like this:

# config/environments/production.rb
OmniAuth.config.full_host = "http://example.com"

Yep - that’s all :).