def callback(environ, start_response): try: return _callback(environ, start_response) finally: configFile = environ[CONFIG_FILE_KEY] configName = environ[CONFIG_NAME_KEY] config = Config(configFile, configName) cfg = config.read() store = FileStore(cfg=cfg) # Perform required cleanup task. Given the difficulty of controlling threads # in WSGI having an invocation at the end of the call back is an acceptable trade-off # This might have to be improved later... store.cleanup()
def _callback(environ, start_response): """ The callback, to wit, this will take the oauth token returned by the server, swap it for an access token then get the cert, storing it as an asset. """ # Standard canonical way to interpret the request values is to run the wsgi environment # through the cgi module form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ, keep_blank_values=1) # Get data from fields token = unquote(form.getvalue('oauth_token', None)) v = unquote(form.getvalue('oauth_verifier', None)) configFile = environ[CONFIG_FILE_KEY] configName = environ[CONFIG_NAME_KEY] logging.info('using cfg file=' + environ['oa4mp.config.file'] + ', name=' + environ['oa4mp.config.name']) config = Config(configFile, configName) cfg = config.read() logit(environ, "skin=" + cfg["skin"]) id = None fileStore = FileStore(cfg) if environ.has_key('HTTP_COOKIE'): for cookie in map(strip, re.split(';', environ['HTTP_COOKIE'])): try: (key, value) = re.split('=', cookie) if key == CERT_REQUEST_ID: id = value if fileStore.get(id) != None: # jump out once you find the first one that works. # If they have cruft in their browser # such as from repeated failed earlier attempts, # we can't figure which is the right one break else: logit(environ, 'No asset found for id=' + id + ', skipping it.') except ValueError, e: logging.exception('Benign error parsing cookie=' + cookie + '. Skipping...')
def _callback(environ, start_response): """ The callback, to wit, this will take the oauth token returned by the server, swap it for an access token then get the cert, storing it as an asset. """ # Standard canonical way to interpret the request values is to run the wsgi environment # through the cgi module form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ, keep_blank_values=1) # Get data from fields token = unquote(form.getvalue('oauth_token', None)) v = unquote(form.getvalue('oauth_verifier', None)) configFile = environ[CONFIG_FILE_KEY] configName = environ[CONFIG_NAME_KEY] logging.info('using cfg file=' + environ['oa4mp.config.file'] + ', name=' + environ['oa4mp.config.name']) config = Config(configFile, configName) cfg = config.read() logit(environ, "skin=" + cfg["skin"]) id = None fileStore = FileStore(cfg) if environ.has_key('HTTP_COOKIE'): for cookie in map(strip, re.split(';', environ['HTTP_COOKIE'])): try: (key, value ) = re.split('=', cookie) if key == CERT_REQUEST_ID: id = value if fileStore.get(id) != None: # jump out once you find the first one that works. # If they have cruft in their browser # such as from repeated failed earlier attempts, # we can't figure which is the right one break else: logit(environ,'No asset found for id=' + id + ', skipping it.') except ValueError, e: logging.exception('Benign error parsing cookie=' + cookie + '. Skipping...')