Skip to content

Instantly share code, notes, and snippets.

@karmi
Created August 1, 2009 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karmi/159604 to your computer and use it in GitHub Desktop.
Save karmi/159604 to your computer and use it in GitHub Desktop.
# Overload Clearance's `deny_access` methods to allow authentication with HTTP-Auth for eg. API access
# Modeled after technoweenie's restful_authentication
# http://github.com/technoweenie/restful-authentication/blob/7235d9150e8beb80a819923a4c871ef4069c6759/generators/authenticated/templates/authenticated_system.rb#L74-76
#
# In lib/clearance_http_auth.rb
module Clearance
module Authentication
module InstanceMethods
def deny_access(flash_message = nil, opts = {})
store_location
flash[:failure] = flash_message if flash_message
respond_to do |format|
format.html { redirect_to new_session_url }
format.any(:json, :xml) do
authenticate_or_request_with_http_basic('My app API') do |login, password|
@_current_user = ::User.authenticate(login, password)
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment