diff --git a/dask_labextension/dashboardhandler.py b/dask_labextension/dashboardhandler.py index 2118613..bdddefd 100644 --- a/dask_labextension/dashboardhandler.py +++ b/dask_labextension/dashboardhandler.py @@ -29,6 +29,14 @@ async def get(self, url) -> None: try: client = httpclient.AsyncHTTPClient() + # Extract query (if any) from URL, this will then be appended after path. + # This allows using (eg) "?token=[...]" in URL for authentication. + if "?" in url: + pos = url.find("?") + url, query = url[:pos], url[pos:] + else: + query = "" + # First check for the individual-plots endpoint at user-provided url. # We don't check for the root URL because that can trigger a lot of # object creation in the bokeh document. @@ -36,7 +44,7 @@ async def get(self, url) -> None: effective_url = None individual_plots_url = url_path_join( url, - "individual-plots.json", + f"individual-plots.json{query}", ) try: self.log.debug( @@ -73,6 +81,14 @@ async def get(self, url) -> None: individual_plots = json.loads(individual_plots_response.body) + # If there was query in original URL, append to URLs returned + if query: + for name, plot_url in individual_plots.items(): + individual_plots[name] = f"{plot_url}{query}" + url = f"{url}{query}" + if effective_url: + effective_url = f"{effective_url}{query}" + self.set_status(200) self.finish( json.dumps(