Created
August 23, 2013 10:45
-
-
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…
This file contains hidden or 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
| # 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