Skip to content

Instantly share code, notes, and snippets.

@mwlang
Created August 23, 2013 10:45
Show Gist options
  • Select an option

  • Save mwlang/6317945 to your computer and use it in GitHub Desktop.

Select an option

Save mwlang/6317945 to your computer and use it in GitHub Desktop.
If you configure basic or digest authorization on Apache/Lighthttpd/nginx, when a user is authenticated, the "REMOTE_USER" is set to the user that was authenticated. This Rack middleware lets you do development outside of a web server by setting REMOTE_USER automatically. Useful for Intranet based websites that are authenticated against Active D…
# Injects a default REMOTE_USER into the headers so your Ruby app sees someone as being
# "logged in" (authenticated) as would normally happen when the web server has been configured
# to do basic or digest authentication before passing through to the web app.
module Rack
class EnsureRemoteUser
def initialize(app)
logger.debug "Ensure REMOTE_USER module initialized!"
@app = app
end
def call(env)
unless env['REMOTE_USER']
env['REMOTE_USER'] = 'DEVELOPER'
logger.warn "Setting REMOTE_USER to 'DEVELOPER'"
end
@app.call(env)
end
end
end
##
# If you're running Sinatra/Padrino or Rails,
# you can load this module only in development mode by calling
# the "use" method only in that environment's block like so:
#
configure :development do
use Rack::EnsureRemoteUser
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment