Skip to content

Commit 31f8d20

Browse files
authored
Support incremental scope consent (SEP-835) (#1084)
1 parent 828d51e commit 31f8d20

File tree

9 files changed

+782
-394
lines changed

9 files changed

+782
-394
lines changed

src/ModelContextProtocol.AspNetCore/Authentication/McpAuthenticationHandler.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.Extensions.Logging;
44
using Microsoft.Extensions.Options;
5+
using Microsoft.Net.Http.Headers;
56
using ModelContextProtocol.Authentication;
67
using System.Text.Encodings.Web;
78

@@ -185,15 +186,9 @@ protected override Task HandleChallengeAsync(AuthenticationProperties properties
185186
// Get the absolute URI for the resource metadata
186187
string rawPrmDocumentUri = GetAbsoluteResourceMetadataUri();
187188

188-
properties ??= new AuthenticationProperties();
189-
190-
// Store the resource_metadata in properties in case other handlers need it
191-
properties.Items["resource_metadata"] = rawPrmDocumentUri;
192-
193189
// Add the WWW-Authenticate header with Bearer scheme and resource metadata
194-
string headerValue = $"Bearer realm=\"{Scheme.Name}\", resource_metadata=\"{rawPrmDocumentUri}\"";
195-
Response.Headers.Append("WWW-Authenticate", headerValue);
196-
190+
string headerValue = $"Bearer resource_metadata=\"{rawPrmDocumentUri}\"";
191+
Response.Headers.Append(HeaderNames.WWWAuthenticate, headerValue);
197192
return base.HandleChallengeAsync(properties);
198193
}
199194

src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ internal static string MakeNewSessionId()
275275
RandomNumberGenerator.Fill(buffer);
276276
return WebEncoders.Base64UrlEncode(buffer);
277277
}
278+
278279
internal static async Task<JsonRpcMessage?> ReadJsonRpcMessageAsync(HttpContext context)
279280
{
280281
// Implementation for reading a JSON-RPC message from the request body
@@ -291,7 +292,6 @@ internal static string MakeNewSessionId()
291292
return message;
292293
}
293294

294-
295295
internal static Task RunSessionAsync(HttpContext httpContext, McpServer session, CancellationToken requestAborted)
296296
=> session.RunAsync(requestAborted);
297297

src/ModelContextProtocol.Core/Authentication/AuthenticatingMcpHttpClient.cs

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)