Skip to content

Commit 9420013

Browse files
committed
Update McpAuthenticationOptions.cs
1 parent 7c6e406 commit 9420013

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

src/ModelContextProtocol.AspNetCore/Authentication/McpAuthenticationOptions.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ public class McpAuthenticationOptions : AuthenticationSchemeOptions
1111
{
1212
private static readonly Uri DefaultResourceMetadataUri = new("/.well-known/oauth-protected-resource", UriKind.Relative);
1313

14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="McpAuthenticationOptions"/> class.
16+
/// </summary>
17+
public McpAuthenticationOptions()
18+
{
19+
// Initialize the base property instead of hiding it with 'new'
20+
base.ForwardAuthenticate = "Bearer";
21+
22+
// Initialize properties in constructor instead of using property initializers
23+
ResourceMetadataUri = DefaultResourceMetadataUri;
24+
ResourceMetadata = new ProtectedResourceMetadata();
25+
26+
// Initialize events
27+
Events = new McpAuthenticationEvents();
28+
}
29+
1430
/// <summary>
1531
/// Gets or sets the events used to handle authentication events.
1632
/// </summary>
@@ -20,21 +36,13 @@ public class McpAuthenticationOptions : AuthenticationSchemeOptions
2036
set { base.Events = value; }
2137
}
2238

23-
/// <summary>
24-
/// Gets or sets the scheme to use for forward authentication.
25-
/// </summary>
26-
/// <remarks>
27-
/// This is currently set as a constant to avoid adding a package dependency.
28-
/// </remarks>
29-
public new string ForwardAuthenticate { get; set; } = "Bearer";
30-
3139
/// <summary>
3240
/// The URI to the resource metadata document.
3341
/// </summary>
3442
/// <remarks>
3543
/// This URI will be included in the WWW-Authenticate header when a 401 response is returned.
3644
/// </remarks>
37-
public Uri ResourceMetadataUri { get; set; } = DefaultResourceMetadataUri;
45+
public Uri ResourceMetadataUri { get; set; }
3846

3947
/// <summary>
4048
/// Gets or sets the static protected resource metadata.
@@ -44,7 +52,7 @@ public class McpAuthenticationOptions : AuthenticationSchemeOptions
4452
/// supported scopes, and other information needed for clients to authenticate.
4553
/// This property is used when <see cref="ResourceMetadataProvider"/> is not set.
4654
/// </remarks>
47-
public ProtectedResourceMetadata ResourceMetadata { get; set; } = new ProtectedResourceMetadata();
55+
public ProtectedResourceMetadata ResourceMetadata { get; set; }
4856

4957
/// <summary>
5058
/// Gets or sets a delegate that dynamically provides resource metadata based on the HTTP context.

0 commit comments

Comments
 (0)