1
votes

I have two rails 4 application running on shared parent domain example.com(pdf.example.com and studio.example.com). The applications are deployed on AWS and storing session in shared Memcached.

On a page of studio.example.com, a page of pdf.example.com is loaded in iframe which covers the entire visible area. Now when user interacts with iframe content, session created in studio.example.com should reset in a sense that timeout should not happen in studio.example.com while sitting in pdf.example.com` pages.

The studio.example.com application uses devise for authentication.

Here is the configuration used to store session in memcached in studio.example.com

config/initializers/session_store.rb

Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 30.minutes

config/environments/production.rb config/environments/development.rb

config.cache_store = :dalli_store

There are many resources out there(few listed below) addressing this scenario but all of them are using CookieStore. What sort of configuration would be different for CacheStore?

  1. http://dev.mikamai.com/post/75476602797/sharing-session-between-your-rails-4x-app-and
  2. http://excid3.com/blog/sharing-a-devise-user-session-across-subdomains-with-rails-3/
  3. https://robots.thoughtbot.com/how-to-share-a-session-between-sinatra-and-rails

EDIT Exact scenario was discussed here earlier.

1

1 Answers

2
votes

The solution suggested in http://dev.mikamai.com/post/75476602797/sharing-session-between-your-rails-4x-app-and worked.

In both applications do following

  1. Set same secret_key_base in both applications
  2. Configure same key and domain in session_store.rb Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 30.minutes, key: '_common_key', domain: ".example.com"

  3. Enable caching with dalli in production.rb Dalli::ElastiCache.new('tripartite.q1ssrz.cfg.usw2.cache.amazonaws.com:11211) config.cache_store = :dalli_store, elasticache.servers