def callback(self, environ, server_env, start_response, cookie, sid, info): _debug = server_env["DEBUG"] _service = self.__class__.__name__ logger.debug("[do_%s] environ: %s" % (_service, environ)) logger.debug("[do_%s] query: %s" % (_service, info)) session = server_env["CACHE"][sid] if session: req_info = session["req_info"] else: req_info = None try: result = self.phaseN(environ, info, server_env, sid) logger.debug("[do_%s] response: %s" % (_service, result)) if isinstance(session, list): # in process start_response(result[0], result[1]) return result[2] (success, identity, session) = result try: req_info = session["req_info"] except KeyError: pass except Exception, exc: exception_log() resp = err_response(server_env, req_info, exc) return resp(environ, start_response)
def auth_choice(path, environ, start_response, sid, server_env): """ :param path: The local part or the URL :param environ: WSGI environment :param start_response: The start_response function :param sid: A key into the session cache :param server_env: :return: A WSGI response """ logger.debug("[auth_choice]") if path.startswith("/"): path = path[1:] _dic = key = None func_name = None for key, _dict in server_env["service"].items(): if match(path, _dict["saml_endpoint"]): _dic = _dict func_name = "begin" break elif match(path, _dict["social_endpoint"]): _dic = _dict func_name = "callback" break _dic["DOMAIN"] = server_env["DOMAIN"] if _dic is None: return not_found(environ, start_response, 'Unknown service: %s' % path) logger.debug("[auth_choice] service: %s, function: %s" % (key, func_name)) logger.debug("environ: %s" % environ) environ['idpproxy.url_args'] = local_path(path) _cache = server_env["CACHE"] if func_name == "callback": # Callback from the Social service try: query = parse_qs(environ["QUERY_STRING"]) except KeyError: return not_found(environ, start_response, 'Missing argument') logger.debug("[auth_choice] query: %s" % query) try: entity_id = _cache[sid]["entity_id"] except KeyError: exception_log() return bad_request(environ, start_response, "Unknown session") else: # This is the SAML endpoint # Should I support mote then HTTP redirect _dict = unpack_redirect(environ) if _dict is None: return bad_request(environ, start_response, "Request missing") try: query = _dict["SAMLRequest"] except KeyError: return bad_request(environ, start_response, "Request missing") if query: logger.debug("Query: %s" % query) try: req_info = server_env["idp"].parse_authn_request(query, BINDING_HTTP_REDIRECT) except KeyError: exception_log() return bad_request(environ, start_response, "Expected SAML request") except Exception, exc: exception_log() return bad_request(environ, start_response, "Faulty SAML request: %s" % exc) try: req_info.relay_state = _dict["RelayState"] except KeyError: pass logger.debug("type req_info: %s message: %s" % (type(req_info), type(req_info.message))) entity_id = req_info.sender() _cache.set(sid, {"req_info": req_info, "entity_id": entity_id}) else:
def auth_choice(path, environ, start_response, sid, server_env): """ :param path: The local part or the URL :param environ: WSGI environment :param start_response: The start_response function :param sid: A key into the session cache :param server_env: :return: A WSGI response """ logger.debug("[auth_choice]") if path.startswith("/"): path = path[1:] _dic = key = None func_name = None for key, _dict in server_env["service"].items(): if match(path, _dict["saml_endpoint"]): _dic = _dict func_name = "begin" break elif match(path, _dict["social_endpoint"]): _dic = _dict func_name = "callback" break _dic["DOMAIN"] = server_env["DOMAIN"] if _dic is None: return not_found(environ, start_response, 'Unknown service: %s' % path) logger.debug("[auth_choice] service: %s, function: %s" % (key, func_name)) logger.debug("environ: %s" % environ) environ['idpproxy.url_args'] = local_path(path) _cache = server_env["CACHE"] if func_name == "callback": # Callback from the Social service try: query = parse_qs(environ["QUERY_STRING"]) except KeyError: return not_found(environ, start_response, 'Missing argument') logger.debug("[auth_choice] query: %s" % query) try: entity_id = _cache[sid]["entity_id"] except KeyError: exception_log() return bad_request(environ, start_response, "Unknown session") else: # This is the SAML endpoint # Should I support mote then HTTP redirect _dict = unpack_redirect(environ) if _dict is None: return bad_request(environ, start_response, "Request missing") try: query = _dict["SAMLRequest"] except KeyError: return bad_request(environ, start_response, "Request missing") if query: logger.debug("Query: %s" % query) try: req_info = server_env["idp"].parse_authn_request( query, BINDING_HTTP_REDIRECT) except KeyError: exception_log() return bad_request(environ, start_response, "Expected SAML request") except Exception, exc: exception_log() return bad_request(environ, start_response, "Faulty SAML request: %s" % exc) try: req_info.relay_state = _dict["RelayState"] except KeyError: pass logger.debug("type req_info: %s message: %s" % (type(req_info), type(req_info.message))) entity_id = req_info.sender() _cache.set(sid, {"req_info": req_info, "entity_id": entity_id}) else: