Support incremental scope consent (SEP-835) (#1084)

This commit is contained in:
Stephen Halter 2025-12-11 19:51:47 -08:00 • committed by GitHub
commit 31f8d20a1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using ModelContextProtocol.Authentication;
using System.Text.Encodings.Web;
@ -185,15 +186,9 @@ public partial class McpAuthenticationHandler : AuthenticationHandler<McpAuthent
// Get the absolute URI for the resource metadata
string rawPrmDocumentUri = GetAbsoluteResourceMetadataUri();
properties ??= new AuthenticationProperties();
// Store the resource_metadata in properties in case other handlers need it
properties.Items["resource_metadata"] = rawPrmDocumentUri;
// Add the WWW-Authenticate header with Bearer scheme and resource metadata
string headerValue = $"Bearer realm=\"{Scheme.Name}\", resource_metadata=\"{rawPrmDocumentUri}\"";
Response.Headers.Append("WWW-Authenticate", headerValue);
string headerValue = $"Bearer resource_metadata=\"{rawPrmDocumentUri}\"";
Response.Headers.Append(HeaderNames.WWWAuthenticate, headerValue);
return base.HandleChallengeAsync(properties);
}