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?

图片转代码服务由CSDN问答提供 功能建议

我们有一个Rails应用程序,它是主站点,但是我们在Golang中创建了一个单独的应用程序,可以处理很多 其他实时功能,例如视频和音频呼叫,消息传递和白板部分。

我们现在遇到的问题是,我们不知道如何在两个应用程序之间共享Web会话。 在Rails应用和Golang之间切换时。 就像从Gmail到Google Drive再到YouTube一样,会话仍保持不变,即使这些应用程序在不同的子域中运行,有时在不同的语言中也可以运行。

我能够从Rails +添加会话 设计/浏览器cookie,但cookie已加密。

请问我如何与您分享如何在自己的应用程序中解决此问题的方法? \ n

使用此答案我能够使会话Cookie既出现在React的主站点中 + Rails和React + Golang中的子域,但是cookie是加密的,我们如何解密/获取其中的值? 例如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 and then you need to make the cookie accessible from both subdomains *
    • 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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题