2014-02-18 45 views
2

事實證明,使用Devise(身份驗證gem)(session_controllerafter_sign_in_path_for)登錄後獲得會話ID(與session[:session_id])在第一次重定向前後不會返回相同的內容,登錄後。設計rails會話ID

有人能解釋我爲什麼嗎? 有沒有什麼辦法可以在重定向之前獲得最終會話ID

回答

0

FYI從嘖嘖蜂(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 

調用destroy_session和set_session在 ActionDispatch implementented ::會議::的CookieStore)

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

當然是。請記住,在 身份驗證後,管理員正在更改session_id以防止會話修復攻擊,因此在覆蓋設計控制器時,除了禁用:續訂會話選項之外,您還應手動更改session_id以及 。這將做到:

session.options [:ID = session.instance_variable_get(:@由).generate_sid session.options [:更新] =假