Skip to content

Commit 1570fac

Browse files
committed
fix: correct OAuth authorization URL construction
1 parent 2fb66c4 commit 1570fac

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pkg/auth/oauth.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,22 @@ func NewOAuthMiddlewareWithCallbackPath(log *logger.Logger, callbackPath string)
5959
}
6060

6161
hubHost := os.Getenv("JUPYTERHUB_HOST")
62-
hubPrefix := os.Getenv("JUPYTERHUB_BASE_URL")
63-
if hubPrefix == "" {
64-
hubPrefix = "/hub/"
62+
63+
// JUPYTERHUB_BASE_URL is the base URL of the deployment (e.g., "/" or "/jupyter/")
64+
// NOT the Hub's base URL. JupyterHub strips "/hub" from the Hub's base_url
65+
// when setting this env var. We need to append "hub/" to get the Hub's base path,
66+
// just like JupyterHub's HubOAuth class does.
67+
deploymentBase := os.Getenv("JUPYTERHUB_BASE_URL")
68+
if deploymentBase == "" {
69+
deploymentBase = "/"
6570
}
66-
if !strings.HasSuffix(hubPrefix, "/") {
67-
hubPrefix += "/"
71+
if !strings.HasSuffix(deploymentBase, "/") {
72+
deploymentBase += "/"
6873
}
6974

75+
// Construct the Hub's base path by appending "hub/" to the deployment base
76+
hubPrefix := deploymentBase + "hub/"
77+
7078
return &OAuthMiddleware{
7179
clientID: clientID,
7280
apiToken: apiToken,

test/integration/oauth_callback_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ func TestOAuthCallbackForInterimPages(t *testing.T) {
4949
)
5050

5151
// Set JupyterHub environment variables pointing to mock server
52+
// Note: JUPYTERHUB_BASE_URL is the deployment base, NOT the Hub's base.
53+
// JupyterHub strips "/hub" from hub.base_url when setting this env var.
5254
cmd.Env = append(os.Environ(),
5355
"JUPYTERHUB_API_TOKEN=test-token-12345",
5456
"JUPYTERHUB_API_URL="+hubURL+"/hub/api",
5557
"JUPYTERHUB_HOST="+hubURL,
56-
"JUPYTERHUB_BASE_URL=/hub/",
58+
"JUPYTERHUB_BASE_URL=/",
5759
"JUPYTERHUB_USER=testuser",
5860
"JUPYTERHUB_SERVICE_PREFIX=/user/testuser/",
5961
"JUPYTERHUB_CLIENT_ID=jupyterhub-user-testuser",

0 commit comments

Comments
 (0)