Skip to content

Commit

Permalink
Disable HTTP Authentication by default. You can turn it on in the ini…
Browse files Browse the repository at this point in the history
…tializer.
  • Loading branch information
josevalim committed Aug 23, 2010
1 parent 617b95f commit b8ab9a8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* deprecations
* sign_out_all_scopes defaults to true as security measure
* http authenticatable is disabled by default

* enhancements
* Added OAuth 2 support
Expand Down
4 changes: 2 additions & 2 deletions lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ module Strategies

# If http authentication is enabled by default.
mattr_accessor :http_authenticatable
@@http_authenticatable = true
@@http_authenticatable = false

# If http authentication is used for ajax requests. True by default.
# If http headers should be returned for ajax requests. True by default.
mattr_accessor :http_authenticatable_on_xhr
@@http_authenticatable_on_xhr = true

Expand Down
8 changes: 1 addition & 7 deletions lib/devise/failure_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def respond
elsif warden_options[:recall]
recall
else
debug!
redirect
end
end
Expand All @@ -53,11 +52,6 @@ def redirect

protected

def debug!
return unless Rails.logger.try(:debug?)
Rails.logger.debug "[Devise] Could not sign in #{scope}: #{i18n_message.inspect}."
end

def i18n_message(default = nil)
message = warden.message || warden_options[:message] || default || :unauthenticated

Expand All @@ -74,7 +68,7 @@ def redirect_url
end

def http_auth?
!Devise.navigational_formats.include?(request.format.to_sym) || (request.xhr? && Devise.http_authenticatable_on_xhr)
!Devise.navigational_formats.include?(request.format.to_sym) || (Devise.http_authenticatable_on_xhr && request.xhr?)
end

def http_auth_body
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/strategies/authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Authenticatable < Base
attr_accessor :authentication_hash, :password

def valid?
valid_for_http_auth? || valid_for_params_auth?
valid_for_params_auth? || valid_for_http_auth?
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/templates/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
# Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true

# Tell if authentication through HTTP Basic Auth is enabled. True by default.
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
# config.http_authenticatable = true

# Set this to true to use Basic Auth for AJAX requests. True by default.
# If http headers should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true

# The realm used in Http Basic Authentication
Expand Down
2 changes: 1 addition & 1 deletion test/rails_app/config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# config.params_authenticatable = true

# Tell if authentication through HTTP Basic Auth is enabled. True by default.
# config.http_authenticatable = true
config.http_authenticatable = true

# The realm used in Http Basic Authentication
# config.http_authentication_realm = "Application"
Expand Down

0 comments on commit b8ab9a8

Please sign in to comment.