如果我们位于同一域下,有没有办法与 .net 应用程序共享 Rails 会话?
最终,我们希望为两个应用程序提供单点登录,一个是 Rails 应用程序,另一个是 .net。
有没有办法使用 devise 和 cookie 会话存储登录 Rails 应用程序,并让 .net 读取此 cookie 来确定哪个用户登录了?如果有帮助的话,我们愿意切换会话存储。
我们希望在 Rails 中保留所有身份验证,但使用 cookie 会话来允许或拒绝对 .net 应用程序的访问。
Ultimately we want single sign-on for two applications, one is a rails app and one .net.
Is there a way login to a rails application using devise and cookie session store, and have a .net read this cookie to determine what user is logged in? We are open to switching session stores if that would help.
We would like to keep all auth in Rails, but use the cookie session to allow or deny access to .net application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你绝对可以做到这一点。
如果会话仅存储在 cookie 中,那么您所需要做的就是像 Rails 一样解析 cookie。查看
ActionDispatch::Request::Cookies
以更好地了解 Rails 如何使用 Cookie。另一方面,如果您将会话存储在 Memcache、Redis、Mysql(或任何其他外部存储)中,您可以从 cookie 获取会话 ID,然后在外部存储中查找它。这可能更容易,也更干燥一些。
只要您有权访问会话 cookie,您就应该能够在 .NET 应用程序中镜像 Rails 会话操作代码并“共享”会话。我鼓励您首先深入了解 Rails 如何处理会话。
Yes, you definitely can do this.
If the session is stored solely in cookies then all you need to do is parse the cookies like rails does. Take a look at
ActionDispatch::Request::Cookies
to get a better feel for how rails uses cookies.If on the other hand you store the session in Memcache, Redis, Mysql (or any other external store) you can get the session id from the cookie then look it up in the external store. This is probably easier and slightly more DRY.
As long as you have access to the session cookies you should be able to mirror the Rails session manipulation code in your .NET application and "share" session. I encourage you to start by reading deeper into how Rails handles session.