繁体   English   中英

设计Rails会话ID

[英]Devise rails session ID

事实证明,在登录后,在使用Devise(身份验证gem)(在session_controllerafter_sign_in_path_for )登录后获得会话ID(带有session[:session_id] )不会在第一次重定向前后返回相同的结果,在。

有人能解释我为什么吗? 有什么办法可以重定向之前获取最终的会话ID?

仅供参考,来自Gee-Bee( https://github.com/Gee-Bee ):

https://github.com/plataformatec/devise/issues/3706

 Is anyone can explain me why ? 

我会尽力。 简而言之:

 Devise has nothing to do with it Warden has something to do with it - it's setting :renew option on session, after setting user (proxy, spec) Actual action takes place in in Rake::Session::Abstract#commit_session which updates session_id (by 

调用在ActionDispatch :: Session :: CookieStore中实现的destroy_session和set_session)

 Is there any way to get the final session ID before redirecting ? 

当然是啦。 请记住,Warden会在身份验证后更改session_id,以防止会话固定攻击,因此,在禁用的devise控制器中,除了禁用:renew session选项之外,您还应该手动更改session_id。 这样可以:

session.options [:id] = session.instance_variable_get(:@ by).generate_sid session.options [:renew] = false

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM