def get(self, path): """ Inject the user's KBase cookie before trying to look up a file. One of our big use cases bypasses the typical Jupyter login mechanism. """ client_ip = self.request.remote_ip http_headers = self.request.headers ua = http_headers.get('User-Agent', 'unknown') auth_cookie = self.cookies.get(auth_cookie_name, None) if auth_cookie: token = urllib.unquote(auth_cookie.value) else: raise web.HTTPError( status_code=401, log_message='No auth cookie, denying access', reason='Authorization required for Narrative access') if token != kbase_env.auth_token: init_session_env(get_user_info(token), client_ip) log_event(g_log, 'session_start', { 'user': kbase_env.user, 'user_agent': ua }) """ get renders the notebook template if a name is given, or redirects to the '/files/' handler if the name is not given. """ path = path.strip('/') cm = self.contents_manager # will raise 404 on not found try: model = cm.get(path, content=False) except web.HTTPError as e: raise # if e.status_code == 404 and 'files' in path.split('/'): # # 404, but '/files/' in URL, let FilesRedirect take care of it # return FilesRedirectHandler.redirect_to_files(self, path) # else: # raise if model['type'] != 'notebook': # not a notebook, redirect to files return FilesRedirectHandler.redirect_to_files(self, path) name = url_escape(path.rsplit('/', 1)[-1]) path = url_escape(path) self.write( self.render_template('notebook.html', notebook_path=path, notebook_name=path, kill_kernel=False, mathjax_url=self.mathjax_url))
def _init_session(request, cookies): client_ip = request.remote_ip http_headers = request.headers ua = http_headers.get('User-Agent', 'unknown') auth_cookie = cookies.get(auth_cookie_name) if auth_cookie is not None: token = urllib.unquote(auth_cookie.value) else: raise web.HTTPError(status_code=401, log_message='No auth cookie, denying access', reason='Authorization required for Narrative access') if token != kbase_env.auth_token: init_session_env(get_user_info(token), client_ip) log_event(g_log, 'session_start', {'user': kbase_env.user, 'user_agent': ua})
def get(self): """ Initializes the KBase session from the cookie passed into it. """ # cookie_regex = re.compile('([^ =|]+)=([^\|]*)') client_ip = self.request.remote_ip http_headers = self.request.headers ua = http_headers.get('User-Agent', 'unknown') # save client ip in environ for later logging kbase_env.client_ip = client_ip auth_cookie = self.cookies.get(auth_cookie_name, None) if auth_cookie: token = urllib.unquote(auth_cookie.value) auth_info = dict() try: auth_info = get_user_info(token) except Exception as e: app_log.error( "Unable to get user information from authentication token!" ) raise # re-enable if token logging info is needed. # if app_log.isEnabledFor(logging.DEBUG): # app_log.debug("kbase cookie = {}".format(cookie_val)) # app_log.debug("KBaseLoginHandler.get: user_id={uid} token={tok}" # .format(uid=auth_info.get('user', 'none'), # tok=token)) init_session_env(auth_info, client_ip) self.current_user = kbase_env.user log_event(g_log, 'session_start', { 'user': kbase_env.user, 'user_agent': ua }) app_log.info("KBaseLoginHandler.get(): user={}".format(kbase_env.user)) if self.current_user: self.redirect(self.get_argument('next', default=self.base_url)) else: self.write('This is a test?')
def _init_session(request, cookies): client_ip = request.remote_ip http_headers = request.headers ua = http_headers.get("User-Agent", "unknown") auth_cookie = cookies.get(auth_cookie_name) if auth_cookie is not None: token = urllib.parse.unquote(auth_cookie.value) else: raise web.HTTPError( status_code=401, log_message="No auth cookie, denying access", reason="Authorization required for Narrative access", ) if token != kbase_env.auth_token: init_session_env(get_user_info(token), client_ip) log_event(g_log, "session_start", { "user": kbase_env.user, "user_agent": ua })
def get(self): """ Initializes the KBase session from the cookie passed into it. """ # cookie_regex = re.compile('([^ =|]+)=([^\|]*)') client_ip = self.request.remote_ip http_headers = self.request.headers ua = http_headers.get('User-Agent', 'unknown') # save client ip in environ for later logging kbase_env.client_ip = client_ip auth_cookie = self.cookies.get(auth_cookie_name, None) if auth_cookie: token = urllib.unquote(auth_cookie.value) auth_info = dict() try: auth_info = get_user_info(token) except Exception as e: app_log.error("Unable to get user information from authentication token!") raise # re-enable if token logging info is needed. # if app_log.isEnabledFor(logging.DEBUG): # app_log.debug("kbase cookie = {}".format(cookie_val)) # app_log.debug("KBaseLoginHandler.get: user_id={uid} token={tok}" # .format(uid=auth_info.get('user', 'none'), # tok=token)) init_session_env(auth_info, client_ip) self.current_user = kbase_env.user log_event(g_log, 'session_start', {'user': kbase_env.user, 'user_agent': ua}) app_log.info("KBaseLoginHandler.get(): user={}".format(kbase_env.user)) if self.current_user: self.redirect(self.get_argument('next', default=self.base_url)) else: self.write('This is a test?')