类似于apache使用的mod_auth_tkt的票证验证系统
ticket_auth的Python项目详细描述
提供类似mod_auth_tkt的哈希票证的简单库,可以是 用于存储用户身份验证详细信息。
库不能与mod_auth_tkt格式交换,因为 mod_auth_tkt不支持IPv6地址和不同的哈希 算法,而ticket_auth提供了两者。
用法
使用库的一般格式是实例化票证工厂 用于生成车票,然后创建新车票或验证现有车票 使用那个工厂的票。例如:
# The ticket factory takes a bytes argument specifying the secret # identifier, and a optional algorithm (defaults to sha512). Possible # algorithms are those specified by the python hashlib library factory = TicketFactory(b'secret', hashalg='md5') # The new function returns a new ticket (as a string). It takes a user # identifier as a argument, along with several optional arguments. The # valid_until argument is the time at which the ticket expires. valid_until = time.time() + 60 ticket = factory.new('test_id', valid_until=valid_until) # A ticket can be validated with the validate function. It returns a # TicketInfo value on success, or raises an error on failure info = factory.validate(ticket)
票证也可以通过传递 类似IP地址的对象(字符串或来自模块IP地址)作为 创建和验证字符串时的client_ip参数。例如:
valid_until = time.time() + 60 ticket = factory.new('test_id', valid_until=valid_until, client_ip='192.168.0.1') info = factory.validate(ticket, client_ip='192.168.0.1')
还可以传递一系列令牌,这些令牌将添加到票据中。 请注意,这些令牌(如用户id和用户数据)以明文形式存储 文本格式:
ticket = factory.new('test_id', valid_until=valid_until, tokens=('a', 'b'), user_data='some data')
validate函数返回的ticketinfo对象是一个名为tuple的 以下参数:摘要(散列函数输出)、用户id、令牌, 用户数据,有效期至。
许可证
图书馆的许可证是麻省理工学院的。