Can I share a cookie between multiple domains pointing to the same Rails application?

I have x.com pointing to apple.y.com , and separately, also one.y.com and two.y.com . I want a user who visits x.com, one.y.com or two.y.com to share the same sessions. Is it possible? If not, what is the best compromise?

+3
source share
2 answers

one.y.comand two.y.comcan share cookies by setting cookies for the domain .y.com. This will transmit cookies in all subdomains y.com.

x.com cookie y.com. , , - http://www.codeguru.com/csharp/csharp/cs_internet/article.php/c19417/Sharing-Cookies-Across-Domains.htm ( ASP.net, RoR).

+1

, , cookie , . . Rails 2.3.5 , Rails 3, .

config/initializers/session_store.rb , :

# ActionController::Base.session_store = :active_record_store

.

, , , :

ActionController::Base.session = {
  :key         => '_myapp_session',
  :secret      => 'some really long string of hex'
}

, :

config/environments/development.rb

config.action_controller.session = { 
  :domain => ".rails.local" 
}

config/environments/production.rb

config.action_controller.session = { 
  :domain => ".myapp.com" 
}
0

Source: https://habr.com/ru/post/1749371/


All Articles