Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ const DefaultRedirectURI = "https://mcp.docker.com/oauth/callback"
// - Uses token_endpoint_auth_method="none" for public clients
// - Includes redirect_uris pointing to mcp-oauth proxy
// - Requests authorization_code and refresh_token grant types
func PerformDCR(ctx context.Context, discovery *Discovery, serverName string) (*ClientCredentials, error) {
//
// redirectURI: The OAuth callback URI to register. If empty, uses DefaultRedirectURI.
func PerformDCR(ctx context.Context, discovery *Discovery, serverName string, redirectURI string) (*ClientCredentials, error) {
if discovery.RegistrationEndpoint == "" {
return nil, fmt.Errorf("no registration endpoint found for %s", serverName)
}

// Use provided redirectURI, fallback to default if empty
if redirectURI == "" {
redirectURI = DefaultRedirectURI
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the redirect url is specified, should we add a check that it's either 127.0.0.1 or mcp.docker.com? Might avoid a situation where an attacker passes in their own url

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should drop the localhost since an attacker can override it


// Build DCR request for PUBLIC client
registration := DCRRequest{
ClientName: fmt.Sprintf("MCP Gateway - %s", serverName),
RedirectURIs: []string{DefaultRedirectURI},
RedirectURIs: []string{redirectURI},
TokenEndpointAuthMethod: "none", // PUBLIC client (no client secret)
GrantTypes: []string{"authorization_code", "refresh_token"},
ResponseTypes: []string{"code"},
Expand Down
8 changes: 4 additions & 4 deletions dcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestPerformDCR_PublicClient(t *testing.T) {
Scopes: []string{"read", "write"},
}

// Perform DCR
creds, err := PerformDCR(context.Background(), discovery, "test-server")
// Perform DCR (empty redirectURI uses default)
creds, err := PerformDCR(context.Background(), discovery, "test-server", "")
// Verify no error
if err != nil {
t.Fatalf("DCR failed: %v", err)
Expand Down Expand Up @@ -82,8 +82,8 @@ func TestPerformDCR_NoRegistrationEndpoint(t *testing.T) {
RegistrationEndpoint: "", // Empty - DCR not supported
}

// Attempt DCR
creds, err := PerformDCR(context.Background(), discovery, "test-server")
// Attempt DCR (empty redirectURI uses default)
creds, err := PerformDCR(context.Background(), discovery, "test-server", "")

// Verify error occurred
if err == nil {
Expand Down