Replace beaker sessions with itsdangerous based sessions
|Reported by:||Elrond||Owned by:|
|Cc:||Christopher Allan Webber||Parent Tickets:|
Description (last modified by )
We want to switch from beaker sessions to itsdangerous based sessions.
Why? We should come up with a better list of reaasons than "The core developers like this idea".
- Remove beaker sessions from paste*.ini
- Create a class that will be our new
- Create code to create such an instance from a received cookie.
- Create code to send a (modified) session as a cookie to the client.
Some more Details
Create a class that will be our new
Some pseudo code:
class MGSession(dict): def save(self): self.send_new_cookie = True def delete(self): self.clear() self.save()
Create Session Instance from cookie
Here's some pseudo code to do that. It includes code for future "revocation support". Because we do not store anything locally any more, one can only forcibly block sessions by blacklisting. In the first step, its okay to document the needed approach in the code.
class SessionManager(object): def load_session_from_cookie(request, cookie_name): cookie = request.get_cookie(cookie_name) if not cookie: request.session = MGSession() return m = BadCookie.query.filter_by(cookie = cookie) if m: _log.warn("Bad cookie received: %s", m.reason) raise BadRequest() parsed_dict = self.signer.loads(cookie, max_age=...) requestion.session = MGSession(parsed_dict)
- Only send a cookie, if an update is needed
- If the session is empty delete the cookie on the client (
MGSession.delete()was called probably)
- Bonus points: Consider sending a new cookie, if the old one is going to expire soon