如何在Rails应用程序之外使用Rails会话存储?

时间:2022-12-10 07:18:49

I am interested in deploying a Node.js along side my Rails application server. Just as a reference, I plan on using socket.IO to create a chat server, so users will be able to chat inside of my web application.

我有兴趣在我的Rails应用服务器旁边部署Node.js.作为参考,我计划使用socket.IO创建聊天服务器,这样用户就可以在我的Web应用程序内聊天。

My current application uses Authlogic to authenticate users. I would like to ensure that only a user cannot read other users' messages, so I will need to authenticate the user session somehow. My Node.js will have access to my database, and I know Rails can store the sessions inside of the database, so I would like to use this feature to authenticate chat users. The problem is, I have no idea how to go about doing that. I'm not even sure what information is present in the session, and I do not know how I can use this information to authenticate a user.

我当前的应用程序使用Authlogic对用户进行身份验证。我想确保只有用户无法读取其他用户的消息,因此我需要以某种方式验证用户会话。我的Node.js可以访问我的数据库,我知道Rails可以将会话存储在数据库中,所以我想使用这个功能来验证聊天用户。问题是,我不知道如何去做。我甚至不确定会话中有什么信息,我不知道如何使用这些信息来验证用户。

Thanks in advance!

提前致谢!

1 个解决方案

#1


1  

The rails session is tricky to use from other languages: it's just a serialised ruby object and pretty much the only documentation for the marshal format is the implementation/rubyspec.

从其他语言使用rails会话很棘手:它只是一个序列化的ruby对象,而且marshal格式的唯一文档就是implementation / ruby​​spec。

However authlogic doesn't actually store anything in the session: it has a separate cookie (user_credentials by default, assuming your model is User) The data in that cookie is "#{user.persistence_token}::#{user.id}", so you should be able to easily verify this from your js code

但是authlogic实际上并没有在会话中存储任何内容:它有一个单独的cookie(默认情况下为user_credentials,假设您的模型是User)该cookie中的数据是“#{user.persistence_token} ::#{user.id}” ,所以你应该能够从你的js代码轻松验证这一点

#1


1  

The rails session is tricky to use from other languages: it's just a serialised ruby object and pretty much the only documentation for the marshal format is the implementation/rubyspec.

从其他语言使用rails会话很棘手:它只是一个序列化的ruby对象,而且marshal格式的唯一文档就是implementation / ruby​​spec。

However authlogic doesn't actually store anything in the session: it has a separate cookie (user_credentials by default, assuming your model is User) The data in that cookie is "#{user.persistence_token}::#{user.id}", so you should be able to easily verify this from your js code

但是authlogic实际上并没有在会话中存储任何内容:它有一个单独的cookie(默认情况下为user_credentials,假设您的模型是User)该cookie中的数据是“#{user.persistence_token} ::#{user.id}” ,所以你应该能够从你的js代码轻松验证这一点