Skip to content

Instantly share code, notes, and snippets.

@tjh
Created May 20, 2010 14:18
Show Gist options
  • Save tjh/407605 to your computer and use it in GitHub Desktop.
Save tjh/407605 to your computer and use it in GitHub Desktop.
# This method allows the app to figure out what username and password were passed
# via basic http auth. Because calling #authenticate_or_request_with_http_basic will
# fail if no password was sent, I had to hack in my own check (taken from the Rails
# source) to make sure that they tried to auth.
def get_credentials
log_it
# Grabbed from the rails source...if the user sent auth data...
if ( request.env['HTTP_AUTHORIZATION'] ||
request.env['X-HTTP_AUTHORIZATION'] ||
request.env['X_HTTP_AUTHORIZATION'] ||
request.env['REDIRECT_X_HTTP_AUTHORIZATION']
) then
authenticate_or_request_with_http_basic do |username, password|
@username = username
@password = password
end
end
true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment