Skip to content

Instantly share code, notes, and snippets.

@sordina
Created February 18, 2010 08:19
Show Gist options
  • Save sordina/307469 to your computer and use it in GitHub Desktop.
Save sordina/307469 to your computer and use it in GitHub Desktop.
Application_user = Settings[:authentication][:user]
Application_pass = Settings[:authentication][:password]
def protected! username = Application_user, password = Application_pass
unless authorized? username, password
response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth")
throw(:halt, [401, "Not authorized\n"])
end
end
def authorized? username, password
username = Settings
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [username, password]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment