def consent(environ, start_response): _oas = environ["oic.oas"] params_str = get_or_post(environ) params = dict(urlparse.parse_qsl(params_str)) return _oas.consent_endpoint(**params)(environ, start_response)
def revoke_access_token(environ, start_response): _oas = environ["oic.oas"] params_str = get_or_post(environ) params = dict(urlparse.parse_qsl(params_str)) return _oas.revoke_access_token_endpoint(**params)(environ, start_response)
def application(environ, start_response): session = environ['beaker.session'] path = environ.get('PATH_INFO', '').lstrip('/') if path == "robots.txt": return static(environ, start_response, "static/robots.txt") if path.startswith("static/"): return static(environ, start_response, path) if path == "logout": session.invalidate() resp = SeeOther("static/log_out_message.html") return resp(environ, start_response) if path == "as": session["callback"] = True request = parse_qs(get_or_post(environ)) _cli = CONSUMER[unquote(request["authzsrv"][0])] session["client"] = _cli resp = SeeOther(_cli.begin(RP_CONF.BASE, path)) return resp(environ, start_response) if path == "rp": session["callback"] = True request = parse_qs(get_or_post(environ)) _cli = CONSUMER[unquote(request["iss"][0])] session["client"] = _cli resp = SeeOther(_cli.begin(RP_CONF.BASE, path)) return resp(environ, start_response) if path == "authz_cb": _cli = session["client"] request = get_or_post(environ) aresp = _cli.handle_authorization_response(request) rargs = {"code": aresp["code"]} atresp = _cli.do_access_token_request(request_args=rargs) #extra_args=None, http_args=None,) # Access token should be stored somewhere for later usage Token[atresp["state"]] = atresp resp = Response("Got access token: %s" % atresp["access_token"]) return resp(environ, start_response) return as_choice(environ, start_response)
def handle(self, environ, tester, sid, path, qs=''): _sh = tester.sh if qs: msg = qs else: try: msg = get_or_post(environ) except AttributeError: msg = {} filename = self.kwargs['profile_handler'](_sh).log_path( sid, _sh['conv'].test_id) _sh['conv'].entity_id = sid return tester.do_next(msg, filename, profile_handler=self.kwargs['profile_handler'], path=path)
def wrapper(environ, start_response): data = get_or_post(environ) cookies = environ.get("HTTP_COOKIE", "") resp = func(request=data, cookie=cookies) return resp(environ, start_response)
def application(self, environ, start_response): session = environ['beaker.session'] jlog = JLog(logger, session.id) path = environ.get('PATH_INFO', '').lstrip('/') jlog.info({"remote_addr": environ["REMOTE_ADDR"], "path": path}) # self.events.store(EV_REQUEST, path) try: sh = session['session_info'] except KeyError: sh = SessionHandler(**self.kwargs) #sh.session_init() session['session_info'] = sh info = WebIh(session=sh, **self.kwargs) info.environ = environ info.start_response = start_response tester = WebTester(info, sh, **self.kwargs) if 'path' in self.kwargs and path.startswith(self.kwargs['path']): _path = path[len(kwargs['path']) + 1:] else: _path = path if _path == "robots.txt": return static_mime("static/robots.txt", environ, start_response) elif _path.startswith("static/"): return static_mime(_path, environ, start_response) if _path == "list": try: qs = parse_qs(get_or_post(environ)) except Exception as err: jlog.error({'message': err}) qs = {} else: if qs: sh['test_conf'] = dict([(k, v[0]) for k, v in qs.items()]) # self.session_conf[sh['sid']] = sh else: return self.init_session(tester, sh) logger.info('test_conf: {}'.format(sh['test_conf'])) if 'start_page' not in sh['test_conf']: resp = BadRequest('You MUST provide a start_page') return resp(environ, start_response) info.profile = tester.sh.profile = qs['response_type'][0] sh.session_init() if 'test_id' in qs: (res, _path) = self.run_test(tester, qs['test_id'][0], sh['sid'], environ, start_response) if res: return res else: res = tester.display_test_list() return res elif _path == '' or _path == 'config': return self.init_session(tester, sh) elif _path in self.kwargs['flows'].keys(): # Run flow # Will use the same test configuration try: _ = tester.sh['test_conf'] except KeyError: return self.init_session(tester, sh) try: _sid = tester.sh['sid'] except KeyError: _sid = self.store_session_handler(sh) # First time around this should not be set try: _ = self.session_conf[_sid]['flow'] except KeyError: pass else: return self.init_session(tester, sh, _path) (res, _path) = self.run_test(tester, _path, _sid, environ, start_response) if res: return res elif _path == 'display': return info.flow_list() elif _path == "opresult": try: _display_path = '/{}/display'.format(self.kwargs['path']) except KeyError: _display_path = '/display' resp = SeeOther( "{}#{}".format(_display_path, self.pick_grp(sh['conv'].test_id))) return resp(environ, start_response) elif _path.startswith("test_info"): p = _path.split("/") try: return info.test_info(p[1]) except KeyError: return info.not_found() elif _path == 'all': for test_id in sh['flow_names']: resp = tester.run(test_id, **self.kwargs) if resp is True or resp is False: continue elif resp: return resp(environ, start_response) else: resp = ServiceError('Unkown service error') return resp(environ, start_response) return tester.display_test_list() # Whatever gets here should be of the form <session_id>/<path> try: sid, _path = _path.split('/', 1) except ValueError: pass else: if _path.startswith("static/"): return static_mime(_path, environ, start_response) try: _sh = self.session_conf[sid] except KeyError: resp = ServiceError("Unknown session") return resp(environ, start_response) tester.sh = _sh if 'HTTP_AUTHORIZATION' in environ: _sh['conv'].events.store('HTTP_AUTHORIZATION', environ['HTTP_AUTHORIZATION']) _p = _path.split('?') _sh['conv'].events.store('http request', '{} /{}'.format( environ['REQUEST_METHOD'], _path)) if _p[0] in _sh['conv'].entity.endpoints(): resp = self.handle(environ, tester, sid, *_p) self.session_conf[sid] = tester.sh # The only redirect should be the one to the redirect_uri if isinstance(resp, SeeOther): if self.internal: # res = self.see_other_to_get(resp, sh) # res is probably a redirect # send the user back to the test list page return info.flow_list() else: return resp(environ, start_response) elif isinstance(resp, Response): return resp(environ, start_response) else: return resp for endpoint, service in self.endpoints.items(): if _path == endpoint: jlog.info({"service": service}) try: resp = self.handle(environ, tester, sid, service) return resp(environ, start_response) except Exception as err: print("%s" % err) message = traceback.format_exception(*sys.exc_info()) print(message) jlog.exception(err) resp = ServiceError("%s" % err) return resp(environ) jlog.debug({"unknown side": path}) resp = NotFound("Couldn't find the side you asked for!") return resp(environ, start_response)
def application(self, environ, start_response): session = environ['beaker.session'] jlog = JLog(logger, session.id) path = environ.get('PATH_INFO', '').lstrip('/') jlog.info({"remote_addr": environ["REMOTE_ADDR"], "path": path}) # self.events.store(EV_REQUEST, path) try: sh = session['session_info'] except KeyError: sh = SessionHandler(**self.kwargs) #sh.session_init() session['session_info'] = sh info = WebIh(session=sh, **self.kwargs) info.environ = environ info.start_response = start_response tester = WebTester(info, sh, **self.kwargs) if 'path' in self.kwargs and path.startswith(self.kwargs['path']): _path = path[len(kwargs['path']) + 1:] else: _path = path if _path == "robots.txt": return static_mime("static/robots.txt", environ, start_response) elif _path.startswith("static/"): return static_mime(_path, environ, start_response) if _path == "list": try: qs = parse_qs(get_or_post(environ)) except Exception as err: jlog.error({'message': err}) qs = {} else: if qs: sh['test_conf'] = dict([(k, v[0]) for k, v in qs.items()]) # self.session_conf[sh['sid']] = sh else: return self.init_session(tester, sh) logger.info('test_conf: {}'.format(sh['test_conf'])) if 'start_page' not in sh['test_conf']: resp = BadRequest('You MUST provide a start_page') return resp(environ, start_response) info.profile = tester.sh.profile = qs['response_type'][0] sh.session_init() if 'test_id' in qs: (res, _path) = self.run_test(tester, qs['test_id'][0], sh['sid'], environ, start_response) if res: return res else: res = tester.display_test_list() return res elif _path == '' or _path == 'config': return self.init_session(tester, sh) elif _path in self.kwargs['flows'].keys(): # Run flow # Will use the same test configuration try: _ = tester.sh['test_conf'] except KeyError: return self.init_session(tester, sh) try: _sid = tester.sh['sid'] except KeyError: _sid = self.store_session_handler(sh) # First time around this should not be set try: _ = self.session_conf[_sid]['flow'] except KeyError: pass else: return self.init_session(tester, sh, _path) (res, _path) = self.run_test(tester, _path, _sid, environ, start_response) if res: return res elif _path == 'display': return info.flow_list() elif _path == "opresult": try: _display_path = '/{}/display'.format(self.kwargs['path']) except KeyError: _display_path = '/display' resp = SeeOther("{}#{}".format(_display_path, self.pick_grp(sh['conv'].test_id))) return resp(environ, start_response) elif _path.startswith("test_info"): p = _path.split("/") try: return info.test_info(p[1]) except KeyError: return info.not_found() elif _path == 'all': for test_id in sh['flow_names']: resp = tester.run(test_id, **self.kwargs) if resp is True or resp is False: continue elif resp: return resp(environ, start_response) else: resp = ServiceError('Unkown service error') return resp(environ, start_response) return tester.display_test_list() # Whatever gets here should be of the form <session_id>/<path> try: sid, _path = _path.split('/', 1) except ValueError: pass else: if _path.startswith("static/"): return static_mime(_path, environ, start_response) try: _sh = self.session_conf[sid] except KeyError: resp = ServiceError("Unknown session") return resp(environ, start_response) tester.sh = _sh if 'HTTP_AUTHORIZATION' in environ: _sh['conv'].events.store('HTTP_AUTHORIZATION', environ['HTTP_AUTHORIZATION']) _p = _path.split('?') _sh['conv'].events.store( 'http request', '{} /{}'.format(environ['REQUEST_METHOD'], _path)) if _p[0] in _sh['conv'].entity.endpoints(): resp = self.handle(environ, tester, sid, *_p) self.session_conf[sid] = tester.sh # The only redirect should be the one to the redirect_uri if isinstance(resp, SeeOther): if self.internal: # res = self.see_other_to_get(resp, sh) # res is probably a redirect # send the user back to the test list page return info.flow_list() else: return resp(environ, start_response) elif isinstance(resp, Response): return resp(environ, start_response) else: return resp for endpoint, service in self.endpoints.items(): if _path == endpoint: jlog.info({"service": service}) try: resp = self.handle(environ, tester, sid, service) return resp(environ, start_response) except Exception as err: print("%s" % err) message = traceback.format_exception(*sys.exc_info()) print(message) jlog.exception(err) resp = ServiceError("%s" % err) return resp(environ) jlog.debug({"unknown side": path}) resp = NotFound("Couldn't find the side you asked for!") return resp(environ, start_response)