def __create_cookie(settings, userid, expire_in_secs): auth_helper = AuthTktCookieHelper( secret=settings['auth.policy.secret'], cookie_name=settings['auth.policy.cookie_name'], hashalg=settings['auth.policy.hashalg']) user_data = '' encoding_data = auth_helper.userid_type_encoders.get(type(userid)) if encoding_data: encoding, encoder = encoding_data userid = encoder(userid) user_data = 'userid_type:%s' % encoding ticket = AuthTicket(auth_helper.secret, userid, '0.0.0.0', tokens=tuple([]), user_data=user_data, time=time_mod.mktime( (datetime.now() + timedelta(seconds=expire_in_secs)).timetuple()), cookie_name=auth_helper.cookie_name, secure=auth_helper.secure, hashalg=auth_helper.hashalg) return (settings['auth.policy.cookie_name'], ticket.cookie_value())
def get_token(self, request, userid): secret = ptah.get_settings(ptah.CFG_ID_PTAH, request.registry)['secret'] remote_addr = '0.0.0.0' ticket = AuthTicket(secret, userid, remote_addr, tokens=(), user_data='', cookie_name='auth-token', secure=False) return ticket.cookie_value()
def _makeOne(self, *arg, **kw): from pyramid.authentication import AuthTicket return AuthTicket(*arg, **kw)