Skip to content

Commit

Permalink
Use default user token when running under JupyterHub
Browse files Browse the repository at this point in the history
When running under a JupyterHub, only the currently running
notebook server process is accessible from the browser (via
the proxy), so only the token set for the current server will work.
Any additional servers running (via jupyter-server-proxy) will
still need this token, so multiple servers running in a JupyterHub
(a currently unknown pattern) can't work anyway.

So when we are running in a JupyterHub, we just use the provided
token in the share URL. No network call is made.

Fixes #10
  • Loading branch information
yuvipanda committed Nov 19, 2021
1 parent 1c71b79 commit 7aaae98
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ const plugin: JupyterFrontEndPlugin<void> = {
commands.addCommand(CommandIDs.share, {
label: trans.__('Share Jupyter Server Link'),
execute: async () => {
const results: { token: string }[] = await requestAPI<any>('servers');
let results: { token: string }[];
if (PageConfig.getOption('hubUser') !== '') {
// We are running on a JupyterHub, so let's just use the token set in PageConfig.
// Any extra servers running on the server will still need to use this token anyway,
// as all traffic (including any to jupyter-server-proxy) needs this token.
results = [{ token: PageConfig.getToken() }];
} else {
results = await requestAPI<any>('servers');
}

const links = results.map(server => {
return URLExt.normalize(
Expand Down

0 comments on commit 7aaae98

Please sign in to comment.