Skip to content

Commit 526eeab

Browse files
authored
Merge pull request #110 from ryanlovett/jsp-pr301
Rewrite /auth-sign-in redirect.
2 parents 80c1db1 + b739a27 commit 526eeab

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

jupyter_rsession_proxy/__init__.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ def get_icon_path():
2929
os.path.dirname(os.path.abspath(__file__)), 'icons', 'rstudio.svg'
3030
)
3131

32+
def rewrite_auth(response, request):
33+
'''
34+
As of rstudio-server 1.4ish, it would send the client to /auth-sign-in
35+
rather than what the client sees as the full URL followed by
36+
/auth-sign-in. See rstudio/rstudio#8888. We rewrite the response by
37+
sending the client to the right place.
38+
'''
39+
for header, v in response.headers.get_all():
40+
if header == "Location" and v.startswith("/auth-sign-in"):
41+
# Visit the correct page
42+
response.headers[header] = request.uri + v
43+
3244
def setup_rserver():
3345
def _get_env(port):
3446
return dict(USER=getpass.getuser())
@@ -65,29 +77,21 @@ def _get_cmd(port):
6577
'--www-verify-user-agent=0',
6678
'--secure-cookie-key-file=' + ntf.name,
6779
'--server-user=' + getpass.getuser(),
80+
'--www-root-path={base_url}rstudio/',
81+
f'--database-config-file={db_config()}'
6882
]
6983

70-
# Add additional options for RStudio >= 1.4.x. Since we cannot
71-
# determine rserver's version from the executable, we must use
72-
# explicit configuration. In this case the environment variable
73-
# RSESSION_PROXY_RSTUDIO_1_4 must be set.
74-
if os.environ.get('RSESSION_PROXY_RSTUDIO_1_4', False):
75-
# base_url has a trailing slash
76-
cmd.append('--www-root-path={base_url}rstudio/')
77-
cmd.append(f'--database-config-file={db_config()}')
78-
7984
return cmd
8085

8186
server_process = {
8287
'command': _get_cmd,
8388
'environment': _get_env,
89+
'rewrite_response': rewrite_auth,
8490
'launcher_entry': {
8591
'title': 'RStudio',
8692
'icon_path': get_icon_path()
8793
}
8894
}
89-
if os.environ.get('RSESSION_PROXY_RSTUDIO_1_4', False):
90-
server_process['launcher_entry']['path_info'] = 'rstudio/auth-sign-in?appUrl=%2F'
9195
return server_process
9296

9397
def setup_rsession():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
keywords=['Jupyter'],
1111
classifiers=['Framework :: Jupyter'],
1212
install_requires=[
13-
'jupyter-server-proxy>=3.1.0'
13+
'jupyter-server-proxy>=3.2.0'
1414
],
1515
entry_points={
1616
'jupyter_serverproxy_servers': [

0 commit comments

Comments
 (0)