Help with figuring out session resets on JSON login and account creation flows #280
-
So far so good implementing a hybrid Rails + SPA auth system. There is some key features for my use case that I can't figure out yet. I have an authentication authorization layer which uses I can handle the "redirect back" after authentication on frontend routes (fully client side) but I'm missing this for trying to access views on RoR. My attempted solution is to store the attempted route on the session, since my cookie shares a common domain with the SPA then sharing the session through frontends is not an issue. So, when trying to access a protected route I set a session value but after a successful authentication flow (login or account creation) the session is reset (I think) and my return_to session value no longer exists. My instincts believe that a new session is being created when logging in, is there a way to persist and update the session instead? Or can I assign new session values based on the reset session? Does this sound like a correct way to handle this? I've thought of including the redirect url or path through the url (query params) but it would be a bit ugly since my auth flows go through multiple routes and it sounds insecure to redirect attacks. Edit: Digging in a bit more I found out that on login the session is being cleared. This would be a rodauth thing rather than a rails-rodauth feature, tho I lack the knowledge about the internals to figure out if it's ok to avoid resetting the session. Does the omniauth login follow the same logic? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Rodauth resets the session after login because it's a good general security practice, as it should prevent session hijacking. Did you try using Rodauth login's native functionality for returning to originally requested location, turned on by setting login_return_to_requested_location? true
login_response do
json_response[:return_to] = saved_login_redirect if saved_login_redirect
super()
end |
Beta Was this translation helpful? Give feedback.
Rodauth resets the session after login because it's a good general security practice, as it should prevent session hijacking. Did you try using Rodauth login's native functionality for returning to originally requested location, turned on by setting
login_return_to_requested_location? true
? Though JSON API will not show redirect locations, so you'd have to expose it in the JSON response, something like: