Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/oauth/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ func BuildRFC8414MetadataURLs(authServerURL string) []string {

// Also try legacy path (appending .well-known after path) for backward compatibility
// Example: https://auth.smithery.ai/googledrive/.well-known/oauth-authorization-server
legacyURL := strings.TrimSuffix(authServerURL, "/") + "/.well-known/oauth-authorization-server"
// Strip only the query and fragment: the userinfo (basic-auth
// credentials) must stay, as it did before.
legacy := *u
legacy.RawQuery = ""
legacy.ForceQuery = false
legacy.Fragment = ""
legacy.RawFragment = ""
legacyURL := strings.TrimSuffix(legacy.String(), "/") + "/.well-known/oauth-authorization-server"
urls = append(urls, legacyURL)

// Also try base URL without path suffix for servers like Cloudflare that host
Expand Down
27 changes: 27 additions & 0 deletions internal/oauth/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,33 @@ func TestBuildRFC8414MetadataURLs(t *testing.T) {
"https://logs.mcp.cloudflare.com/.well-known/oauth-authorization-server", // This one works for Cloudflare
},
},
{
name: "URL with path and query string",
authServerURL: "https://host.example.com/mcp?token=abc",
expectedURLs: []string{
"https://host.example.com/.well-known/oauth-authorization-server/mcp",
"https://host.example.com/mcp/.well-known/oauth-authorization-server",
"https://host.example.com/.well-known/oauth-authorization-server",
},
},
{
name: "URL with userinfo keeps it on the legacy URL",
authServerURL: "https://alice:secret@host.example.com/mcp",
expectedURLs: []string{
"https://host.example.com/.well-known/oauth-authorization-server/mcp",
"https://alice:secret@host.example.com/mcp/.well-known/oauth-authorization-server",
"https://host.example.com/.well-known/oauth-authorization-server",
},
},
{
name: "URL with userinfo and query string",
authServerURL: "https://alice:secret@host.example.com/mcp?token=abc",
expectedURLs: []string{
"https://host.example.com/.well-known/oauth-authorization-server/mcp",
"https://alice:secret@host.example.com/mcp/.well-known/oauth-authorization-server",
"https://host.example.com/.well-known/oauth-authorization-server",
},
},
{
name: "GitHub OAuth URL without path",
authServerURL: "https://github.com",
Expand Down
Loading