Skip to content

Instantly share code, notes, and snippets.

@alexbaldwin
Created November 6, 2013 00:29
Show Gist options
  • Save alexbaldwin/7328855 to your computer and use it in GitHub Desktop.
Save alexbaldwin/7328855 to your computer and use it in GitHub Desktop.
Rails 4 Basic Auth via ENV variable. Add this to your ApplicationController. Set the BASIC_AUTH ENV variable to enable.
before_filter :authenticate
protected
def authenticate
return true unless ENV['BASIC_AUTH']
authenticate_or_request_with_http_basic do |username, password|
username == "" && password == ENV['BASIC_AUTH']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment