Skip to content

Commit

Permalink
Merge pull request heartcombo#1211 from mathieuravaux/master
Browse files Browse the repository at this point in the history
Issue heartcombo#1206 fix ((TokenAuthenticatable#params_auth_hash behavior)
  • Loading branch information
josevalim committed Jul 25, 2011
2 parents 4ce9d6f + 4d91fb4 commit b7b21a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/devise/strategies/token_authenticatable.rb
Expand Up @@ -39,7 +39,11 @@ def remember_me?

# Try both scoped and non scoped keys.
def params_auth_hash
params[scope] || params
if params[scope].kind_of?(Hash) && params[scope].has_key?(authentication_keys.first)
params[scope]
else
params
end
end

# Overwrite authentication keys to use token_authentication_key.
Expand Down
11 changes: 11 additions & 0 deletions test/integration/token_authenticatable_test.rb
Expand Up @@ -13,6 +13,17 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
end
end

test 'authenticate with valid authentication token key and value through params, when params with the same key as scope exist' do
swap Devise, :token_authentication_key => :secret_token do
user = create_user_with_authentication_token
post exhibit_user_path(user), Devise.token_authentication_key => user.authentication_token, :user => { :some => "data" }

assert_response :success
assert_contain 'User is authenticated'
assert warden.authenticated?(:user)
end
end

test 'authenticate with valid authentication token key but does not store if stateless' do
swap Devise, :token_authentication_key => :secret_token, :stateless_token => true do
sign_in_as_new_user_with_token
Expand Down

0 comments on commit b7b21a0

Please sign in to comment.