Opened 12 years ago
Closed 10 years ago
#668 closed enhancement (fixed)
Replace beaker sessions with itsdangerous based sessions
Reported by: | Elrond | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | programming | Keywords: | sprint |
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".
What's needed?
- Remove beaker sessions from paste*.ini
- Create a class that will be our new
request.session
- 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 request.session
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)
Send cookie
- 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
Change History (9)
comment:1 by , 12 years ago
Type: | defect → enhancement |
---|
comment:2 by , 12 years ago
Description: | modified (diff) |
---|
some small changes to example pseudo code, mostly suggesting a SessionManager class.
comment:3 by , 12 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Small update: bcs / brett is working on this. I'm mostly waiting for a ping to merge his branch.
comment:4 by , 12 years ago
Brett, any updates on this? It sounds like it's close, and I'd really love to see it land!
comment:5 by , 11 years ago
Owner: | removed |
---|---|
Status: | assigned → review |
This has been merged!
I am claiming the ticket to clean up the last bits.
comment:6 by , 11 years ago
Owner: | set to |
---|---|
Status: | review → in_progress |
comment:7 by , 11 years ago
Hey Elrond,
Is there anything that's still being cleaned up or can we close this?
comment:8 by , 10 years ago
Really, I have no idea.
It's probably done, I'm guessing.
If there's something wrong, we'll file a new bug.
comment:9 by , 10 years ago
Owner: | removed |
---|---|
Resolution: | → fixed |
Status: | in_progress → closed |
This landed a long time ago. I think Elrond at one point wanted to do cleanup, but whatever was wanted either has been done or the memory of what that cleanup was has been lost to the sands of time. Regardless, things seem to be working fine now. Closed!
From #580:
This might be helpful too: http://flask.pocoo.org/snippets/51/