Rails 3 - 如何将身份验证令牌传递给 Sproutcore 等客户端框架
我正在考虑开发一个带有 Rails 3 后端的 Sproutcore 客户端 Web 应用程序。我设想的问题之一是必须在 Sproutcore 和 Rails 之间的通信中传递身份验证令牌。
CSRF令牌何时重新生成?是基于每个会话吗?是否可以禁用登录请求的真实性检查,然后将身份验证令牌从登录传回并将其存储在客户端以供将来的请求?
I'm looking into developing a Sproutcore client-side webapp with a Rails 3 backend. One of the problems I'm envisioning is having to pass the authentication token along with the communication between Sproutcore and Rails.
When is the CSRF token regenerated? Is it on a per-session basis? Would it be okay to disable the authenticity check for login requests, then pass the authentication token back from the login and store it on the client side for future requests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论用户是否登录,您都可以加载真实性令牌。它与会话一起存储,并且在用户登录后不会更改,并且您不需要禁用真实性检查。我使用此代码片段来设置 JavaScript 变量:
You can load the authenticity token whether the user is logged in or not. It's stored with the session and would not change after a user logs in and you don't need to disable the authenticity check. I use this snippet to set a javascript variable: