Created
March 23, 2016 19:00
-
-
Save badosu/b40ea12b033178dceaf0 to your computer and use it in GitHub Desktop.
Basic HTTP Auth with Roda
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
auth = Rack::Auth::Basic::Request.new(env) | |
unless auth.provided? | |
# env['warden'].custom_failure! # If you're using warden avoid intercepting 401 | |
r.halt [401, {'Content-Type' => 'text/plain', 'Content-Length' => '0', 'WWW-Authenticate' => 'Basic realm="Restricted Area"'}, []] | |
end | |
unless auth.basic? | |
r.halt [400, {'Content-Type' => 'text/plain', 'Content-Length' => '0'}, []] | |
end | |
if auth.credentials == %w(admin abc123) | |
env['REMOTE_USER'] = auth.username | |
else | |
# env['warden'].custom_failure! # If you're using warden avoid intercepting 401 | |
r.halt [401, {'Content-Type' => 'text/plain', 'Content-Length' => '0', 'WWW-Authenticate' => 'Basic realm="Restricted Area"'}, []] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment