Changeset 169

Show
Ignore:
Timestamp:
11/09/08 20:42:42
Author:
thejimmyg
Message:

Added a new algorithm for guessing the form action and added an authkit.form.action override

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • AuthKit/trunk/AuthKit.egg-info/PKG-INFO

    r166 r169  
    5353        0.4.3 
    5454         
    55         * Added headers to the form handling for IE. Fixes #54 
     55        * Added a new algorithm based on ideas from #61 to guess the correct action 
     56        for the form produced by the form middleware but also added support for 
     57        an authkit.form.action option which allows you to manually override 
     58        AuthKit's guess. (The OpenID middleware calls this baseurl) 
     59        * Added user_set_password() methods to users API. Fixes #64. 
     60        * Removed arabic letters from the form handler. Fixes #40. 
     61        * Added headers to the form handling for IE. Fixes #54. 
    5662        * Adding SQLAlchemy 0.5 support, uses session.add() instead of session.save() 
    5763        * The multi handler now handles WSGI applications implemented as iterators, 
  • AuthKit/trunk/CHANGELOG.txt

    r168 r169  
    440.4.3 
    55 
     6* Added a new algorithm based on ideas from #61 to guess the correct action 
     7  for the form produced by the form middleware but also added support for 
     8  an authkit.form.action option which allows you to manually override  
     9  AuthKit's guess. (The OpenID middleware calls this baseurl) 
    610* Added user_set_password() methods to users API. Fixes #64. 
    711* Removed arabic letters from the form handler. Fixes #40. 
  • AuthKit/trunk/authkit/authenticate/form.py

    r167 r169  
    5858        status="200 OK", 
    5959        method='post', 
     60        action=None, 
    6061        **p 
    6162    ): 
     
    6768            self.content_type = self.content_type + '; charset='+charset 
    6869        self.method = method 
     70        self.action = action 
    6971     
    7072    def on_authorized(self, environ, start_response): 
     
    9395        else: 
    9496            log.debug("Either username or password missing") 
    95         action = construct_url(environ) 
     97        action = self.action or construct_url(environ) 
    9698        log.debug("Form action is: %s", action) 
    9799        if self.method == 'post': 
     
    128130        host, port = host.split(':', 1) 
    129131    else: 
    130         host = environ.get('HTTP_X_FORWARDED_HOST', environ.get('HTTP_HOST')) 
    131         port = environ.get('HTTP_X_FORWARDED_PORT', environ.get('SERVER_PORT')) 
    132  
    133         # This is not a good way of determining the request scheme because 
    134         # the request could be proxied from an HTTPS server to an HTTP server 
    135         # if environ['wsgi.url_scheme'] == 'https': 
    136         #     if port == '443': 
    137         #         port = None 
    138         # elif environ['wsgi.url_scheme'] == 'http': 
    139         #     if port == '80': 
    140         #         port = None 
     132        # See if the request is proxied 
     133        host = environ.get('HTTP_X_FORWARDED_HOST', environ.get('HTTP_X_FORWARDED_FOR')) 
     134        if host is not None: 
     135            # Request was proxied, get the correct data 
     136            host = environ.get('HTTP_X_FORWARDED_HOST') 
     137            port = environ.get('HTTP_X_FORWARDED_PORT') 
     138            if port is None and environ.get('HTTP_X_FORWARDED_SSL') == 'on': 
     139                port = '443' 
     140            if not port: 
     141                log.warning( 
     142                    'No HTTP_X_FORWARDED_PORT or HTTP_X_FORWARDED_SSL found ' 
     143                    'in environment, cannot ' 
     144                    'determine the correct port for the form action. ' 
     145                )  
     146            if not host: 
     147                log.warning( 
     148                    'No HTTP_X_FORWARDED_HOST found in environment, cannot ' 
     149                    'determine the correct hostname for the form action. '  
     150                    'Using the value of HTTP_HOST instead.' 
     151                )    
     152                host = environ.get('HTTP_HOST') 
     153        else: 
     154            # Request was not proxied 
     155            if environ['wsgi.url_scheme'] == 'https': 
     156                port = 443 
     157            if host is None: 
     158                host = environ.get('HTTP_HOST') 
     159            if port is None: 
     160                port = environ.get('SERVER_PORT') 
    141161    url += host 
    142162    if port: 
     
    146166            url = 'http'+url 
    147167        else: 
    148             if environ['wsgi.url_scheme'] == 'https': 
    149                 url = 'https'+url+':%s' % port 
    150             else: 
    151                 # Assume we are running HTTP on a non-standard port 
    152                 url = 'http'+url+':%s' % port 
    153                  
     168            # Assume we are running HTTP on a non-standard port 
     169            url = 'http'+url+':%s' % port 
    154170    else: 
    155171        url = 'http'+url 
     
    198214        format='basic' 
    199215    ) 
    200     charset=auth_conf.get('charset') 
    201     method =auth_conf.get('method', 'post') 
     216    charset = auth_conf.get('charset') 
     217    method = auth_conf.get('method', 'post') 
     218    action = auth_conf.get('action') 
    202219    if method.lower() not in ['get','post']: 
    203220        raise Exception('Form method should be GET or POST, not %s'%method) 
    204     return app, {'authfunc':authfunc, 'template':template_, 'charset':charset, 'method':method}, None 
     221    return app, { 
     222        'authfunc': authfunc,  
     223        'template': template_,  
     224        'charset': charset,  
     225        'method': method, 
     226        'action': action, 
     227    }, None 
    205228 
    206229def make_form_handler( 
     
    226249        charset=auth_handler_params['charset'], 
    227250        method=auth_handler_params['method'], 
     251        action=auth_handler_params['action'], 
    228252    ) 
    229253    app.add_checker('form', status_checker) 
  • AuthKit/trunk/examples/docs/form.py

    r121 r169  
    1414    form_authenticate_user_encrypt_secret = 'some secret string', 
    1515    form_charset='UTF-8', 
     16    # For overriding proxied defaults: 
     17    # form_action = 'http://localhost/forms/private', 
    1618    cookie_signoutpath = '/signout', 
    1719)