Skip to content

Instantly share code, notes, and snippets.

@technoweenie
Created July 29, 2010 19:30
Show Gist options
  • Save technoweenie/498995 to your computer and use it in GitHub Desktop.
Save technoweenie/498995 to your computer and use it in GitHub Desktop.
less crappy implementation that fixed a bug if the base64 included whitespace in the middle
@@http_auth_headers = %w(X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization)
# gets BASIC auth info
def get_auth_data
auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) }
if auth_key.present? && request.env[auth_key].to_s =~ /^Basic\s+(.*)/m
Base64.decode64($1).split(':')[0..1]
else
[nil, nil]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment