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 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"
  • ¥20 基于决策树的数字信号处理,2ask 2psk 2fsk的代码,检查下报错的原因
  • ¥20 python作业求过程
  • ¥15 wincc已组态的变量过多
  • ¥60 如图:直线与椭圆X轴平行,求直线与椭圆任意一点的相切坐标计算公式
  • ¥50 如何用python使用opencv里的cv::cudacodec::VideoWriter函数对视频进行GPU硬编码
  • ¥100 c#solidworks 二次开发 工程图自动标边线法兰 等折弯尺寸怎么标
  • ¥15 halcon DrawRegion 提示错误