From 44830ead1c88e1c45124133ce3e2ed9f890f42de Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Fri, 11 Jun 2010 10:25:39 +0430 Subject: Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. [#4818 state:resolved] This reverts commit 330a89072a493aafef1e07c3558964477f85adf0. --- .../lib/action_dispatch/middleware/session/abstract_store.rb | 7 ++++++- actionpack/lib/action_dispatch/middleware/session/cookie_store.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/middleware/session') diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 3e8d64b0c6..040a83f7a6 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -121,7 +121,12 @@ module ActionDispatch unless options[:expire_after].nil? cookie[:expires] = Time.now + options.delete(:expire_after) end - + + if options[:domain] == :all + top_level_domain = env["HTTP_HOST"].split('.')[-2..-1].join('.') + options[:domain] = ".#{top_level_domain}" + end + request = ActionDispatch::Request.new(env) set_cookie(request, cookie.merge!(options)) end diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 92a86ee229..0fc63d026f 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -34,6 +34,14 @@ module ActionDispatch # integrity defaults to 'SHA1' but may be any digest provided by OpenSSL, # such as 'MD5', 'RIPEMD160', 'SHA256', etc. # + # * :domain: Restrict the session cookie to certain domain level. + # If you use a schema like www.example.com and wants to share session + # with user.example.com set :domain to :all + # + # :domain => nil # Does not sets cookie domain. (default) + # :domain => :all # Allow the cookie for the top most level + # domain and subdomains. + # # To generate a secret key for an existing application, run # "rake secret" and set the key in config/environment.rb. # -- cgit v1.2.3