Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add key option to rememberable_options

closes #2218
  • Loading branch information...
commit d3f8bd6cae3e8c24074914c422952684fcaa3ea4 1 parent 0642e2f
@nashby nashby authored
View
2  lib/devise.rb
@@ -43,7 +43,7 @@ module Strategies
# True values used to check params
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
- # Custom domain for cookies. Not set by default
+ # Custom domain or key for cookies. Not set by default
mattr_accessor :rememberable_options
@@rememberable_options = {}
View
10 lib/devise/controllers/rememberable.rb
@@ -23,14 +23,14 @@ def initialize(warden)
def remember_me(resource)
scope = Devise::Mapping.find_scope!(resource)
resource.remember_me!(resource.extend_remember_period)
- cookies.signed["remember_#{scope}_token"] = remember_cookie_values(resource)
+ cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)
end
# Forgets the given resource by deleting a cookie
def forget_me(resource)
scope = Devise::Mapping.find_scope!(resource)
resource.forget_me!
- cookies.delete("remember_#{scope}_token", forget_cookie_values(resource))
+ cookies.delete(remember_key(resource, scope), forget_cookie_values(resource))
end
protected
@@ -47,6 +47,10 @@ def remember_cookie_values(resource)
:expires => resource.remember_expires_at
)
end
+
+ def remember_key(resource, scope)
+ resource.rememberable_options.fetch(:key, "remember_#{scope}_token")
+ end
end
end
-end
+end
View
4 lib/devise/strategies/rememberable.rb
@@ -41,7 +41,7 @@ def remember_me?
end
def remember_key
- "remember_#{scope}_token"
+ mapping.to.rememberable_options.fetch(:key, "remember_#{scope}_token")
end
def remember_cookie
@@ -52,4 +52,4 @@ def remember_cookie
end
end
-Warden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)
+Warden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)
View
7 test/integration/rememberable_test.rb
@@ -57,6 +57,13 @@ def cookie_expires(key)
end
end
+ test 'generate remember token with a custom key' do
+ swap Devise, :rememberable_options => { :key => "v1lat_token" } do
+ user = sign_in_as_user :remember_me => true
+ assert request.cookies["v1lat_token"]
+ end
+ end
+
test 'generate remember token after sign in setting session options' do
begin
Rails.configuration.session_options[:domain] = "omg.somewhere.com"
Please sign in to comment.
Something went wrong with that request. Please try again.