41.2. HELPER CLASSES
41.2 Helper Classes
class AuthTktCookieHelper(secret, |
cookie_name=’auth_tkt’, |
se- |
cure=False, |
include_ip=False, |
time- |
out=None, reissue_time=None, max_age=None, |
http_only=False, path=’/’, wild_domain=True) |
A helper class for use in third-party |
authentication policy implementations. |
See pyramid.authentication.AuthTktAuthenticationPolicy for the meanings of the constructor arguments.
class AuthTicket(secret, userid, ip, tokens=(), user_data=’‘, time=None,
cookie_name=’auth_tkt’, secure=False)
This class represents an authentication token. You must pass in the shared secret, the userid, and the IP address. Optionally you can include tokens (a list of strings, representing role names), ‘user_data’, which is arbitrary data available for your own use in later scripts. Lastly, you can override the cookie name and timestamp.
Once you provide all the arguments, use .cookie_value() to generate the appropriate authentication ticket.
Usage:
token = AuthTicket(’sharedsecret’, ’username’, os.environ[’REMOTE_ADDR’], tokens=[’admin’])
val = token.cookie_value()
exception AuthTktCookieHelper.BadTicket(msg, expected=None)
Exception raised when a ticket can’t be parsed. If we get far enough to determine what the expected digest should have been, expected is set. This should not be shown by default, but can be useful for debugging.
AuthTktCookieHelper.forget(request)
Return a set of expires Set-Cookie headers, which will destroy any existing auth_tkt cookie when attached to a response
AuthTktCookieHelper.identify(request)
Return a dictionary with authentication information, or None if no valid auth_tkt is attached to request