使用itsdangerous的morepath身份策略。
项目描述
用法
import morepath
from more.itsdangerous import IdentityPolicy
class App(morepath.App):
pass
@App.identity_policy()
def get_identity_policy():
return IdentityPolicy()
@App.verify_identity()
def verify_identity(identity):
# trust the identity established by the identity policy (we could keep
# checking if the user is really in the database here - or if it was
# removed in the meantime)
return True
有关Morepath的安全模型和查看注释源代码的更多信息,请参阅http://morepath.readthedocs.org/en/latest/security.html
https://github.com/morepath/more.itsdangerous/blob/master/more/itsdangerous/identity_policy.py
IdentityPolicy类旨在扩展,因为每个人的需求都不同。它简单地提供了一个使用itsdangerous将身份存储为已签名cookie的方法。
开发中的用法
默认情况下,more.itsdangerous创建的cookie是HttpOnly和Secure。
如果您有不同的需求或正在运行开发服务器,您可能需要更改身份策略的配置
@App.identity_policy()
def get_identity_policy():
# make the cookies work under http, not just https
return IdentityPolicy(secure=False)
请注意,这只能在开发中使用。在当今时代,您不希望在http上传输cookie!
运行测试
安装tox并运行它
pip install tox tox
限制测试到特定的Python版本
tox -e py27
约定
More Itsdangerous尽可能遵循PEP8。要测试它,请运行
tox -e pep8
More Itsdangerous使用语义版本控制
构建状态
覆盖率
最新PyPI发布
许可证
more.itsdangerous在修订的BSD许可证下发布
变更日志
0.0.2 (2016-04-18)
添加与Morepath 0.14+的兼容性。[henri-hulski]
0.0.1 (2015-04-29)
初始发布 [href]