@@ -8,23 +8,23 @@ namespace ModelContextProtocol.Authentication;
88/// </summary>
99public 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 ) ;
0 commit comments