I am using the pyramid framework with beaker as a back-end for session management, and I want to store a session_id within a signed cookie. The session-id is associated with a real user_id, and the association mappings will be stored in something like redis. Can I simply use the configuration below to achieve this? The documentation doesn't provide a full implementation and only shows an example using an unsecure session factory.
Here is my configuration file, redacted to session details:
session.type = cookie
session.data_dir = %(here)s/data/sessions/data
session.lock_dir = %(here)s/data/sessions/lock
session.key = session_key
session.secret = as98&$Hh94
session.cookie_on_exception = true
Here is my __init__.py
:
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.include('pyramid_beaker')
config.include('.models')
config.include('.routes')
config.include('polatick.models')
config.scan()
return config.make_wsgi_app()
Do I simply use the forget and remember functions in pyramid to do this properly?
I was thinking of the process going something along the lines of something simple like this:
if user_authenticates():
session_id = create_session_id()
redis.put_entry(session_id, user_id)
request.session['session_id'] = session_id
headers = remember(request, login)
return HTTPFound('/', headers=headers)
I've been following this documentation:
http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/pylons/sessions.html