Multiple Beaker Sessions with Pylons

20 views
Skip to first unread message

Michael Naber

unread,
Mar 20, 2010, 4:08:12 AM3/20/10
to pylons-discuss
What is the right way to go about creating more than one Beaker
session? I see the need to do this because I would like to have one
session that is secure (cookie over ssl only) and another one that is
not secure.

Thanks,
Michael

DD

unread,
Apr 5, 2010, 7:24:08 PM4/5/10
to pylons-...@googlegroups.com
I have the same problem (need 2 different sessions).

It seems that one approach to do this will be to write a SessionManager,
similar to CacheManager and then modify the SessionMiddleware to use it
instead of directly using the Session object. My knowledge on this is
limited, but if someone can outline what's the best way to do this, I
can definitely take a shot it.

DD

DD

unread,
Apr 5, 2010, 7:56:25 PM4/5/10
to pylons-...@googlegroups.com
Another approach, without doing too many changes:

In middleware.py, right before it initializes the main session from config:

session2_opts = {
'session.type': 'cookie',
'session.key': 'sess2',
'session.cookie_expires': True,
'session.auto': True,
'session.domain': config['session.domain'],
'session.secure': False,
}
app = SessionMiddleware(app, environ_key='beaker.session2', config
= session2_opts)
app = SessionMiddleware(app, config)

And then access this session object using:
s2 = environ['beaker.session2']
s2['param'] = val
....

You can create the new session directly in middleware. It does not read
the config file (but can be made to do so pretty easily).

DD.

Reply all
Reply to author
Forward
0 new messages