Skip to content

Instantly share code, notes, and snippets.

@ashayh
Created November 25, 2012 04:56
Show Gist options
  • Select an option

  • Save ashayh/4142448 to your computer and use it in GitHub Desktop.

Select an option

Save ashayh/4142448 to your computer and use it in GitHub Desktop.
Rails HTTP Auth plus SSL
# in controller_name.rb :
before_filter :http_auth
# in application_controller.rb :
def http_auth
authenticate_or_request_with_http_basic do |username, password|
username == "user" && password == "password"
end
end
# in 'script/rails' , insert the following before the APP_PATH line
# On ubuntu, find the certs in /etc/ssl/certs/
require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
IO.read(File.expand_path("ssl-cert-snakeoil.key"))),
:SSLCertificate => OpenSSL::X509::Certificate.new(
IO.read(File.expand_path("ssl-cert-snakeoil.pem"))),
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment