Permalink
Browse files

Enable basic auth if the env BASIC_AUTH_PASSWORD variable is set.

  • Loading branch information...
christiannelson committed Dec 27, 2012
1 parent c62f473 commit 438dd0e1e969059aaea36f3011a4680622c24e5c
Showing with 11 additions and 1 deletion.
  1. +11 −1 app_prototype/config.ru
View
@@ -1,8 +1,18 @@
# This file is used by Rack-based servers to start the application.
-require ::File.expand_path('../config/environment', __FILE__)
+require ::File.expand_path('../config/environment', __FILE__)
# Disable buffering for real time logging, see: https://devcenter.heroku.com/articles/logging#writing-to-your-log
$stdout.sync = true
+# Optional Basic Auth - Enabled if BASIC_AUTH_PASSWORD is set. User is optional (any value will be accepted).
+BASIC_AUTH_USER = ENV['BASIC_AUTH_USER']
+BASIC_AUTH_PASSWORD = ENV['BASIC_AUTH_PASSWORD']
+
+if BASIC_AUTH_PASSWORD
+ use Rack::Auth::Basic do |username, password|
+ password == BASIC_AUTH_PASSWORD && (BASIC_AUTH_USER.blank? || username == BASIC_AUTH_USER)
+ end
+end
+
run AppPrototype::Application

0 comments on commit 438dd0e

Please sign in to comment.