Regeneration of all flask sessions without logging out

Basically, I want to regenerate each session using a new set of keys, without logging in again. How can i do this?

edited for clarity

So let's say we use redis as a backend for sessions and we store cookies on the client side. A cookie consists only of a session identifier. This session identifier corresponds to a session on redis. After initializing the session by writing a session (APP) in our application, for each request context, we can get the session of the current user using

from flask import session 

After the administrator changes some general settings in the application, I am ready to restore the session of each current user, which can be seen only for the current user, again

 from flask import session 

This is as far as I know.

For example, suppose a user session value is defined as

 session['arbitrary_key'] = not_important_database_function() 

After the administrator changes some things in the application, I need to reload the key in the current user session with

 session['arbitrary_key'] = not_important_database_function() 

Because after making admin changes it will give a different value. After that, I modify session.modified as true. I want to know how I can change arbitrary_key in EVERY USER's sessions. Because I do not have enough information on how to get each session and change them from a flask.

If I delete sessions from redis, users need to re-authenticate. I do not want them to be re-checked. I just want the back sessions to change because I use some information inside the user session that needs to be extracted from redis, so I don't need to call not_important_database_function for each request.

I hope you have enough information so that at least you will NOT answer, but also NOT down, so that I can continue to search for a solution to my problem.

I do not share code fragments because no code fragment is useful for my case.

+5
source share

Source: https://habr.com/ru/post/1265382/


All Articles