Skip to content

Comments

+double WWW-Authenticate response header. Resolve Issue #949#1774

Open
chidozieononiwu wants to merge 1 commit intomicrosoft:mainfrom
chidozieononiwu:bugFix/AuthHeader
Open

+double WWW-Authenticate response header. Resolve Issue #949#1774
chidozieononiwu wants to merge 1 commit intomicrosoft:mainfrom
chidozieononiwu:bugFix/AuthHeader

Conversation

@chidozieononiwu
Copy link
Member

What does this PR do?

Remove duplicate WWW-Authenticate

GitHub issue number?

#949

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where duplicate WWW-Authenticate response headers were being sent in authentication challenge responses for remote MCP servers. The issue occurred because the OnChallenge event handler was setting a custom WWW-Authenticate header but not preventing the default JWT Bearer handler from adding its own header.

Changes:

  • Added context.HandleResponse() call to prevent the default JWT Bearer handler from adding a second WWW-Authenticate header
  • Explicitly set the HTTP 401 status code before constructing the header
  • Enhanced the WWW-Authenticate header construction to include error and error_description parameters when available

@joshfree joshfree moved this from Untriaged to In Progress in Azure MCP Server Feb 20, 2026
@joshfree joshfree added this to the 2026-02 milestone Feb 20, 2026

context.Response.StatusCode = 401;

var header = $"Bearer realm=\"{request.Host}\", resource_metadata=\"{resourceMetadataUrl}\"";
Copy link
Member

Choose a reason for hiding this comment

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

missing CHANGELOG entry

context.Response.StatusCode = 401;

var header = $"Bearer realm=\"{request.Host}\", resource_metadata=\"{resourceMetadataUrl}\"";
if (!string.IsNullOrEmpty(context.Error))
Copy link
Member

Choose a reason for hiding this comment

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

missing regression test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants