Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1353

Show
Ignore:
Timestamp:
09/11/06 13:28:34
Author:
fumanchu
Message:

Docstrings + tweaks for new auth.py.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/auth.py

    r1352 r1353  
    1  
    21import cherrypy 
    3 from cherrypy._cptools import Tool  
    42 
    53from httpauth import parseAuthorization, checkResponse, basicAuth, digestAuth 
    64 
    7 def check_auth(realm, users): 
    8     # Check if the user-agent provides an authorization header 
    9     # containing credentials 
     5 
     6def check_auth(users): 
     7    """If an authorization header contains credentials, return True, else False.""" 
    108    if 'authorization' in cherrypy.request.headers: 
    119        # make sure the provided credentials are correctly set 
     
    1311        if ah is None: 
    1412            raise cherrypy.HTTPError(400, 'Bad Request') 
    15   
     13         
    1614        # fetch the user password 
    1715        password = users.get(ah["username"], None) 
    18   
     16         
    1917        # validate the authorization by re-computing it here 
    2018        # and compare it with what the user-agent provided 
    2119        if checkResponse(ah, password, method=cherrypy.request.method): 
    2220            return True 
    23          
     21     
    2422    return False 
    25   
     23 
    2624def basic_auth(realm, users): 
    27     if check_auth(realm, users): 
     25    """If auth fails, raise 401 with a basic authentication header. 
     26     
     27    realm: a string containing the authentication realm. 
     28    users: a dict of the form: {username: password}. 
     29    """ 
     30    if check_auth(users): 
    2831        return 
    2932     
     
    3235     
    3336    raise cherrypy.HTTPError(401, "You are not authorized to access that resource")  
    34   
     37 
    3538def digest_auth(realm, users): 
    36     if check_auth(realm, users): 
     39    """If auth fails, raise 401 with a digest authentication header. 
     40     
     41    realm: a string containing the authentication realm. 
     42    users: a dict of the form: {username: password}. 
     43    """ 
     44    if check_auth(users): 
    3745        return 
    3846     

Hosted by WebFaction

Log in as guest/cpguest to create tickets