【问题标题】:Share session between two rails 4 application with different subdomain在具有不同子域的两个 Rails 4 应用程序之间共享会话
【发布时间】:2016-06-20 22:02:03
【问题描述】:

我有两个 rails 4 应用程序在共享父域 example.compdf.example.comstudio.example.com)上运行。应用程序部署在 AWS 上,并将会话存储在共享 Memcached 中。

studio.example.com 的页面上,pdf.example.com 的页面加载到iframe 中,覆盖了整个可见区域。现在,当用户与 iframe 内容交互时,studio.example.com 中创建的会话应该重置,因为在 pdf.example.com` 页面中不应在studio.example.com 中发生超时。

studio.example.com 应用程序使用设备进行身份验证。

这里是用于在studio.example.com的memcached中存储会话的配置

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

有很多资源(下面列出的很少)解决了这种情况,但它们都使用CookieStore。对于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

编辑 确切的场景在前面讨论过here

【问题讨论】:

    标签: ruby-on-rails-4 devise single-sign-on


    【解决方案1】:

    http://dev.mikamai.com/post/75476602797/sharing-session-between-your-rails-4x-app-and 中建议的解决方案有效。

    在两个应用程序中都执行以下操作

    1. 在两个应用程序中设置相同的secret_key_base
    2. session_store.rb 中配置相同的键和域 Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 30.minutes, key: '_common_key', domain: ".example.com"

    3. production.rb Dalli::ElastiCache.new('tripartite.q1ssrz.cfg.usw2.cache.amazonaws.com:11211) config.cache_store = :dalli_store, elasticache.servers 中使用dalli 启用缓存

    【讨论】:

    • 此方法适用于两个不同的域,例如我想将 x.com 会话存储共享到 y.com,我可以这样做吗?
    猜你喜欢
    • 2018-08-29
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多