[PYTHON] Secret key generation when using EncryptedCookieStorage with aiohttp_session

memorandum.

The secret key when using EncryptedCookieStorage for aiohttp_session is a 32-byte bytes-like object or it. Must be a base64 encoded string.

$ pip install cryptography
from cryptography.fernet import Fernet

print(Fernet.generate_key().decode())

In aiohttp, set as follows. (The generated secret key is put in the environment variable SESSION_SECRET)

from aiohttp import web
from aiohttp_session import session_middleware
from aiohttp_session.cookie_storage import EncryptedCookieStorage

session_storage = EncryptedCookieStorage(os.environ.get('SESSION_SECRET'))

app = web.Application(middlewares=[session_middleware(session_storage)])

Recommended Posts

Secret key generation when using EncryptedCookieStorage with aiohttp_session
When using optparse with iPython
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
How to deal with SessionNotCreatedException when using Selenium
Precautions when using google-cloud library with GAE / py
What are you using when testing with Python?
Precautions when using sqlite3 on macOS Sierra (10.12) with multiprocessing
Troublesome story when using Python3 with VScode on ubuntu
I got an error when using Tensorboard with Pytorch
When using Union type with pydantic, combine it with Literal