Skip to content

Commit fe0d8ba

Browse files
committed
Update for consistency
1 parent a0cd4ad commit fe0d8ba

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

samples/ProtectedMCPClient/BasicOAuthAuthorizationProvider.cs renamed to samples/ProtectedMCPClient/BasicOAuthProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ProtectedMCPClient;
1414
/// caching or any advanced token protection - it acquires a token and server metadata and holds it
1515
/// in memory as-is. This is NOT PRODUCTION READY and MUST NOT BE USED IN PRODUCTION.
1616
/// </summary>
17-
public class BasicOAuthAuthorizationProvider : ITokenProvider
17+
public class BasicOAuthProvider : IMcpCredentialProvider
1818
{
1919
/// <summary>
2020
/// The Bearer authentication scheme.
@@ -38,7 +38,7 @@ public class BasicOAuthAuthorizationProvider : ITokenProvider
3838
private AuthorizationServerMetadata? _authServerMetadata;
3939

4040
/// <summary>
41-
/// Initializes a new instance of the <see cref="BasicOAuthAuthorizationProvider"/> class.
41+
/// Initializes a new instance of the <see cref="BasicOAuthProvider"/> class.
4242
/// </summary>
4343
/// <param name="serverUrl">The MCP server URL.</param>
4444
/// <param name="httpClient">The HTTP client to use for OAuth requests. If null, a default HttpClient will be used.</param>
@@ -47,7 +47,7 @@ public class BasicOAuthAuthorizationProvider : ITokenProvider
4747
/// <param name="clientSecret">OAuth client secret.</param>
4848
/// <param name="redirectUri">OAuth redirect URI.</param>
4949
/// <param name="scopes">OAuth scopes.</param>
50-
public BasicOAuthAuthorizationProvider(
50+
public BasicOAuthProvider(
5151
Uri serverUrl,
5252
HttpClient? httpClient,
5353
AuthorizationHelpers? authorizationHelpers,

samples/ProtectedMCPClient/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static async Task Main(string[] args)
2525

2626
// Create the token provider with our custom HttpClient,
2727
// letting the AuthorizationHelpers be created automatically
28-
var tokenProvider = new BasicOAuthAuthorizationProvider(
28+
var tokenProvider = new BasicOAuthProvider(
2929
new Uri(serverUrl),
3030
httpClient,
3131
null, // AuthorizationHelpers will be created automatically

src/ModelContextProtocol/Authentication/AuthorizationDelegatingHandler.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ namespace ModelContextProtocol.Authentication;
88
/// </summary>
99
public class AuthorizationDelegatingHandler : DelegatingHandler
1010
{
11-
private readonly ITokenProvider _authorizationProvider;
11+
private readonly IMcpCredentialProvider _credentialProvider;
1212
private string _currentScheme;
1313
private static readonly char[] SchemeSplitDelimiters = { ' ', ',' };
1414

1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="AuthorizationDelegatingHandler"/> class.
1717
/// </summary>
18-
/// <param name="authorizationProvider">The provider that supplies authentication tokens.</param>
19-
public AuthorizationDelegatingHandler(ITokenProvider authorizationProvider)
18+
/// <param name="credentialProvider">The provider that supplies authentication tokens.</param>
19+
public AuthorizationDelegatingHandler(IMcpCredentialProvider credentialProvider)
2020
{
21-
Throw.IfNull(authorizationProvider);
21+
Throw.IfNull(credentialProvider);
2222

23-
_authorizationProvider = authorizationProvider;
23+
_credentialProvider = credentialProvider;
2424

2525
// Select first supported scheme as the default
26-
_currentScheme = _authorizationProvider.SupportedSchemes.FirstOrDefault() ??
27-
throw new ArgumentException("Authorization provider must support at least one authentication scheme.", nameof(authorizationProvider));
26+
_currentScheme = _credentialProvider.SupportedSchemes.FirstOrDefault() ??
27+
throw new ArgumentException("Authorization provider must support at least one authentication scheme.", nameof(credentialProvider));
2828
}
2929

3030
/// <summary>
@@ -65,14 +65,14 @@ private async Task<HttpResponseMessage> HandleUnauthorizedResponseAsync(
6565
string schemeUsed = originalRequest.Headers.Authorization?.Scheme ?? _currentScheme ?? string.Empty;
6666
if (!string.IsNullOrEmpty(schemeUsed) &&
6767
serverSchemes.Contains(schemeUsed) &&
68-
_authorizationProvider.SupportedSchemes.Contains(schemeUsed))
68+
_credentialProvider.SupportedSchemes.Contains(schemeUsed))
6969
{
7070
bestSchemeMatch = schemeUsed;
7171
}
7272
else
7373
{
7474
// Find the first server scheme that's in our supported set
75-
bestSchemeMatch = serverSchemes.Intersect(_authorizationProvider.SupportedSchemes, StringComparer.OrdinalIgnoreCase).FirstOrDefault();
75+
bestSchemeMatch = serverSchemes.Intersect(_credentialProvider.SupportedSchemes, StringComparer.OrdinalIgnoreCase).FirstOrDefault();
7676

7777
// If no match was found, either throw an exception or use default
7878
if (bestSchemeMatch is null)
@@ -81,19 +81,19 @@ private async Task<HttpResponseMessage> HandleUnauthorizedResponseAsync(
8181
{
8282
throw new InvalidOperationException(
8383
$"No matching authentication scheme found. Server supports: [{string.Join(", ", serverSchemes)}], " +
84-
$"Provider supports: [{string.Join(", ", _authorizationProvider.SupportedSchemes)}].");
84+
$"Provider supports: [{string.Join(", ", _credentialProvider.SupportedSchemes)}].");
8585
}
8686

8787
// If the server didn't specify any schemes, use the provider's default
88-
bestSchemeMatch = _authorizationProvider.SupportedSchemes.FirstOrDefault();
88+
bestSchemeMatch = _credentialProvider.SupportedSchemes.FirstOrDefault();
8989
}
9090
}
9191

9292
// If we have a scheme to try, use it
9393
if (bestSchemeMatch != null)
9494
{
9595
// Try to handle the 401 response with the selected scheme
96-
var (handled, recommendedScheme) = await _authorizationProvider.HandleUnauthorizedResponseAsync(
96+
var (handled, recommendedScheme) = await _credentialProvider.HandleUnauthorizedResponseAsync(
9797
response,
9898
bestSchemeMatch,
9999
cancellationToken).ConfigureAwait(false);
@@ -174,7 +174,7 @@ private async Task AddAuthorizationHeaderAsync(HttpRequestMessage request, strin
174174
{
175175
if (request.RequestUri != null)
176176
{
177-
var token = await _authorizationProvider.GetCredentialAsync(scheme, request.RequestUri, cancellationToken).ConfigureAwait(false);
177+
var token = await _credentialProvider.GetCredentialAsync(scheme, request.RequestUri, cancellationToken).ConfigureAwait(false);
178178
if (!string.IsNullOrEmpty(token))
179179
{
180180
request.Headers.Authorization = new AuthenticationHeaderValue(scheme, token);

src/ModelContextProtocol/Authentication/ITokenProvider.cs renamed to src/ModelContextProtocol/Authentication/IMcpCredentialProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ModelContextProtocol.Authentication;
44
/// Defines an interface for providing authentication for requests.
55
/// This is the main extensibility point for authentication in MCP clients.
66
/// </summary>
7-
public interface ITokenProvider
7+
public interface IMcpCredentialProvider
88
{
99
/// <summary>
1010
/// Gets the collection of authentication schemes supported by this provider.

src/ModelContextProtocol/Protocol/Transport/SseClientTransport.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ public SseClientTransport(SseClientTransportOptions transportOptions, HttpClient
5656
/// Initializes a new instance of the <see cref="SseClientTransport"/> class with authentication support.
5757
/// </summary>
5858
/// <param name="transportOptions">Configuration options for the transport.</param>
59-
/// <param name="authorizationProvider">The authorization provider to use for authentication.</param>
59+
/// <param name="credentialProvider">The authorization provider to use for authentication.</param>
6060
/// <param name="loggerFactory">Logger factory for creating loggers used for diagnostic output during transport operations.</param>
6161
/// <param name="baseMessageHandler">Optional. The base message handler to use under the authorization handler.
6262
/// If null, a new <see cref="HttpClientHandler"/> will be used. This allows for custom HTTP client pipelines (e.g., from HttpClientFactory)
63-
/// to be used in conjunction with the token-based authentication provided by <paramref name="authorizationProvider"/>.</param>
64-
public SseClientTransport(SseClientTransportOptions transportOptions, ITokenProvider authorizationProvider, ILoggerFactory? loggerFactory = null, HttpMessageHandler? baseMessageHandler = null)
63+
/// to be used in conjunction with the token-based authentication provided by <paramref name="credentialProvider"/>.</param>
64+
public SseClientTransport(SseClientTransportOptions transportOptions, IMcpCredentialProvider credentialProvider, ILoggerFactory? loggerFactory = null, HttpMessageHandler? baseMessageHandler = null)
6565
{
6666
Throw.IfNull(transportOptions);
67-
Throw.IfNull(authorizationProvider);
67+
Throw.IfNull(credentialProvider);
6868

6969
_options = transportOptions;
7070
_loggerFactory = loggerFactory;
7171
Name = transportOptions.Name ?? transportOptions.Endpoint.ToString();
7272

73-
var authHandler = new AuthorizationDelegatingHandler(authorizationProvider)
73+
var authHandler = new AuthorizationDelegatingHandler(credentialProvider)
7474
{
7575
InnerHandler = baseMessageHandler ?? new HttpClientHandler()
7676
};

0 commit comments

Comments
 (0)