dongtuoji5396 2018-10-04 23:32
浏览 65
已采纳

在Rails 5.2应用程序和Golang之间共享Web会话

We have a Rails app which is the main site, but we created a separate app in Golang that handles a lot of other real-time functionalities like Video and Audio Calls, Messaging and Whiteboard sections.

The problem we have now is we don't know how to share web sessions between the 2 apps. When you switch in between the Rails app to Golang. Just like going from Gmail to Google Drive to YouTube, the session remains the same even though these apps run in different subdomains and sometimes different languages.

I was able to add the session from Rails + Devise/Warden into the browser cookie but the cookie is encrypted. How do I decrypt or use this cookie to authenticate the user in Go?

Could you guys please share with me how you would approach solving this problem in your own app?

Using this answer I was able to get the session cookie to appear both in the main site in React + Rails and the subdomain in React + Golang, but the cookie is encrypted, how do we decrypt/get the values in there? for example the user_id?

  • 写回答

1条回答 默认 最新

  • doujianzhi3358 2018-10-05 05:40
    关注

    You can share the session between two backends (regardless of the backends) using redis datastore as central shared memory.

    So, whenever you create a new session in Rails or Go app:

    • Create a session-id(UUID for ex.) a59eb448-d268-413e-a837-b5aefc65a4b2
    • You will store your session details in redis with that unique session id (a59eb448-d268-413e-a837-b5aefc65a4b2).
    • You store your session id in a cookie shared between the two platforms domains. So if it was rails.mydomain.com and go.mydomain.com then you need to make the cookie accessible from both subdomains *.mydomain.com.
    • When a user with this cookie access any of your platform. You can read the session-id from his cookies and use it to query redis and get session info (user_id, etc.).

    This way you can have shared session across different subdomains in the client side using cookies and shared across different backends in the server side using redis.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 添加组件无法加载页面,某块加载卡住
  • ¥15 网络科学导论,网络控制
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错