Created
March 14, 2012 08:17
-
-
Save yaotti/2035065 to your computer and use it in GitHub Desktop.
sinatraでBasic認証 ref: http://qiita.com/items/3170
This file contains 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
helpers do | |
def protected! | |
unless authorized? | |
response['WWW-Authenticate'] = %(Basic realm="Restricted Area") | |
throw(:halt, [401, "Not authorized\n"]) | |
end | |
end | |
def authorized? | |
@auth ||= Rack::Auth::Basic::Request.new(request.env) | |
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['changeme', 'changeme'] | |
end | |
end | |
get '/protected' do | |
protected! | |
"Protected page" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment