Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy between logged server URL and the URL in the jpserver-*-open.html file #1301

Open
MetRonnie opened this issue Jul 13, 2023 · 1 comment
Labels

Comments

@MetRonnie
Copy link

MetRonnie commented Jul 13, 2023

Description

When the default_url contains a hash (aka fragment) (our app uses vue-router with hash-based routing), e.g. default_url = /foo/#/workspace, there is a discrepancy between the full URL logged at startup vs the full URL in the jpserver-*-open.html file.

When the server starts up and logs the URL it is using

def local_url(self):
parts = self._get_urlparts(include_token=True)
# Update with custom pieces.
if not self.sock:
parts = parts._replace(netloc=f"127.0.0.1:{self.port}")
return parts.geturl()

def _get_urlparts(self, path=None, include_token=False):
"""Constructs a urllib named tuple, ParseResult,
with default values set by server config.
The returned tuple can be manipulated using the `_replace` method.
"""

which results in

>>> parts = self._get_urlparts(include_token=True)
>>> list(parts)
[
  'http',
  'localhost:8888',
  '/foo/#/workspace',
  '',
  'token=blahblah42',
  '',
]
>>> parts.geturl()
'http://localhost:8888/foo/#/workspace?token=blahblah42'

This is incorrect as the token querystring has become part of the hash and therefore is not recognised as a querystring by the browser, and opening the URL results in the Jupyter page for logging in / entering the token manually.

Whereas the URL that gets outputted to the jpserver-xxxx-open.html file that actually gets opened is from
tornado.httputil.url_concat

def _write_browser_open_file(self, url, fh):
"""Write the browser open file."""
if self.identity_provider.token:
url = url_concat(url, {"token": self.identity_provider.token})
url = url_path_join(self.connection_url, url)

which results in

>>> url = 'foo/#/workspace'
>>> url = url_concat(url, {'token': self.token})
'foo/?token=blahblah42#/workspace'
>>> url_path_join(self.connection_url, url)
'http://localhost:8888/foo/?token=blahblah42#/workspace'

which is correct as the querystring comes before the hash and everything works properly.

Reproduce

  1. Use a default_url with a hash in it

Expected behavior

When handling default_url it should account for the possibility of a hash/fragment.

I should be able to come up with a quick fix for this, having debugged the issue to this extent.
Otherwise I would say it would be safer to handle the URL the same way in each of the two cases, rather than the current different handling.

Context

  • Operating System and version: N/A
  • Browser and version: N/A
  • Jupyter Server version: 2.7
@MetRonnie MetRonnie added the bug label Jul 13, 2023
@welcome
Copy link

welcome bot commented Jul 13, 2023

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant