使用Azure表存储或CosmosDB表API的Flask会话
flask-session-azure的Python项目详细描述
使用Azure表存储(或cosmsdb table API)的Flask会话
此模块可用作Azure表存储或Azure CosmosDB的烧瓶会话处理程序。 所有存储的数据都使用AES加密进行加密。
用法示例:
importflaskfromflask_session_azureimportstorage_account_interfaceapp=flask.Flask(__name__)app.secret_key="MyVerySecretEnryptionKeyForEverything"# must be at least 16 characters, the longer the betterconnection_string="DefaultEndpointsProtocol=https;AccountName=someAccount;AccountKey=someKey;EndpointSuffix=core.windows.net"app.session_interface=storage_account_interface(connection_string)
这将在一个名为flasksession
的表中存储会话数据,分区键为default_session
。如果该表尚不存在,将在第一次存储会话时创建该表。
您可以在创建会话接口时覆盖这些默认值:
如果您在Azure函数或Azure Web服务中使用此功能,那么您肯定已经在环境变量AzureWebJobsStorage
中拥有一个存储帐户连接:
importosimportflaskfromflask_session_azureimportstorage_account_interfaceapp=flask.Flask(__name__)app.secret_key="MyVerySecretEnryptionKeyForEverything"# must be at least 16 characters, the longer the betterconnection_string=os.environ.get("AzureWebjobsStorage")app.session_interface=storage_account_interface(connection_string)
变更日志
0.4.3
- 修正了密钥长度和密钥包含非asci字符的问题
0.4.2
- 修复了“samesite”cookie值未设置(即设置为无)时的问题。如果没有设置它,它现在被设置为Lax以在azure函数中工作(参见https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite)
0.4.1
- 首次公开发行
- 项目
标签: