%PDF- %PDF-
Direktori : /opt/alt/python27/lib/python2.7/site-packages/paste/auth/ |
Current File : //opt/alt/python27/lib/python2.7/site-packages/paste/auth/auth_tkt.pyo |
� a�Nc @ s d Z d d l Z y d d l m Z Wn! e k rI d d l m Z n Xd d l Z d d l m Z d d l m Z d d l m Z d e f d � � YZ d e f d � � YZ d � Z d � Z d � Z d d � Z d e f d � � YZ d d e e d d � Z d S( s' Implementation of cookie signing as done in `mod_auth_tkt <http://www.openfusion.com.au/labs/mod_auth_tkt/>`_. mod_auth_tkt is an Apache module that looks for these signed cookies and sets ``REMOTE_USER``, ``REMOTE_USER_TOKENS`` (a comma-separated list of groups) and ``REMOTE_USER_DATA`` (arbitrary string data). This module is an alternative to the ``paste.auth.cookie`` module; it's primary benefit is compatibility with mod_auth_tkt, which in turn makes it possible to use the same authentication process with non-Python code run under Apache. i����N( t md5( t request( t quote( t unquotet AuthTicketc B sA e Z d Z d d d d e d � Z d � Z d � Z d � Z RS( s� 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. .cookie() generates a Cookie object, the str() of which is the complete cookie header to be sent. CGI usage:: token = auth_tkt.AuthTick('sharedsecret', 'username', os.environ['REMOTE_ADDR'], tokens=['admin']) print 'Status: 200 OK' print 'Content-type: text/html' print token.cookie() print ... redirect HTML ... Webware usage:: token = auth_tkt.AuthTick('sharedsecret', 'username', self.request().environ()['REMOTE_ADDR'], tokens=['admin']) self.response().setCookie('auth_tkt', token.cookie_value()) Be careful not to do an HTTP redirect after login; use meta refresh or Javascript -- some browsers have bugs where cookies aren't saved when set on a redirect. t t auth_tktc C ss | | _ | | _ | | _ d j | � | _ | | _ | d k rT t j � | _ n | | _ | | _ | | _ d S( Nt ,( t secrett useridt ipt joint tokenst user_datat Nonet time_modt timet cookie_namet secure( t selfR R R R R R R R ( ( sD /opt/alt/python27/lib/python2.7/site-packages/paste/auth/auth_tkt.pyt __init__W s c C s+ t | j | j | j | j | j | j � S( N( t calculate_digestR R R R R R ( R ( ( sD /opt/alt/python27/lib/python2.7/site-packages/paste/auth/auth_tkt.pyt digestf s c C sY d | j � t | j � t | j � f } | j rH | | j d 7} n | | j 7} | S( Ns %s%08x%s!t !( R t intR t url_quoteR R R ( R t v( ( sD /opt/alt/python27/lib/python2.7/site-packages/paste/auth/auth_tkt.pyt cookie_valuek s + c C sl t j � } | j � j d � j � j d d � | | j <d | | j d <| j rh d | | j d <n | S( Nt base64s R t /t patht trueR ( t Cookiet SimpleCookieR t encodet stript replaceR R ( R t c( ( sD /opt/alt/python27/lib/python2.7/site-packages/paste/auth/auth_tkt.pyt cookier s . ( N( t __name__t __module__t __doc__R t FalseR R R R&