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.

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

报告相同问题?

悬赏问题

  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
  • ¥15 Mac(标签-IDE|关键词-File) idea
  • ¥15 潜在扩散模型的Unet特征提取
  • ¥15 iscsi服务无法访问,如何解决?
  • ¥15 感应式传感器制作的感应式讯响器