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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。