Created
February 18, 2010 08:19
-
-
Save sordina/307469 to your computer and use it in GitHub Desktop.
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
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