Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal sealed partial class ClientOAuthProvider : McpHttpClient
/// </summary>
private const string BearerScheme = "Bearer";
private const string ProtectedResourceMetadataWellKnownPath = "/.well-known/oauth-protected-resource";
private static readonly string HttpsPlusHttpScheme = $"{Uri.UriSchemeHttps}+{Uri.UriSchemeHttp}";

private readonly Uri _serverUrl;
private readonly Uri _redirectUri;
Expand Down Expand Up @@ -342,10 +343,13 @@ private async Task<AuthorizationServerMetadata> GetAuthServerMetadataAsync(Uri a
ThrowFailedToHandleUnauthorizedResponse($"No authorization_endpoint was provided via '{wellKnownEndpoint}'.");
}

if (metadata.AuthorizationEndpoint.Scheme != Uri.UriSchemeHttp &&
metadata.AuthorizationEndpoint.Scheme != Uri.UriSchemeHttps)
string authorizationEndpointScheme = metadata.AuthorizationEndpoint.Scheme;

if (authorizationEndpointScheme != Uri.UriSchemeHttp &&
authorizationEndpointScheme != Uri.UriSchemeHttps &&
authorizationEndpointScheme != HttpsPlusHttpScheme)
{
ThrowFailedToHandleUnauthorizedResponse($"AuthorizationEndpoint must use HTTP or HTTPS. '{metadata.AuthorizationEndpoint}' does not meet this requirement.");
ThrowFailedToHandleUnauthorizedResponse($"AuthorizationEndpoint must use HTTP, HTTPS, or HTTPS+HTTP. '{metadata.AuthorizationEndpoint}' does not meet this requirement.");
}

metadata.ResponseTypesSupported ??= ["code"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace ModelContextProtocol.Client;
/// </summary>
public sealed class HttpClientTransportOptions
{
private static readonly string HttpsPlusHttpScheme = $"{Uri.UriSchemeHttps}+{Uri.UriSchemeHttp}";

/// <summary>
/// Gets or sets the base address of the server for SSE connections.
/// </summary>
Expand All @@ -25,9 +27,13 @@ public required Uri Endpoint
{
throw new ArgumentException("Endpoint must be an absolute URI.", nameof(value));
}
if (value.Scheme != Uri.UriSchemeHttp && value.Scheme != Uri.UriSchemeHttps)
string scheme = value.Scheme;

if (scheme != Uri.UriSchemeHttp &&
scheme != Uri.UriSchemeHttps &&
scheme != HttpsPlusHttpScheme)
{
throw new ArgumentException("Endpoint must use HTTP or HTTPS scheme.", nameof(value));
throw new ArgumentException("Endpoint must use HTTP, HTTPS, or HTTPS+HTTP scheme.", nameof(value));
}

field = value;
Expand Down