11using ModelContextProtocol . Authentication . Types ;
2+ using ModelContextProtocol . Utils ;
23using System . Net . Http . Headers ;
34
45namespace ModelContextProtocol . Authentication ;
@@ -9,7 +10,7 @@ namespace ModelContextProtocol.Authentication;
910public class AuthorizationDelegatingHandler : DelegatingHandler
1011{
1112 private readonly IMcpAuthorizationProvider _authorizationProvider ;
12- private string ? _currentScheme ;
13+ private string _currentScheme ;
1314
1415 /// <summary>
1516 /// Initializes a new instance of the <see cref="AuthorizationDelegatingHandler"/> class.
@@ -31,7 +32,7 @@ public AuthorizationDelegatingHandler(IMcpAuthorizationProvider authorizationPro
3132 /// </summary>
3233 protected override async Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
3334 {
34- if ( request . Headers . Authorization == null && _currentScheme != null )
35+ if ( request . Headers . Authorization == null )
3536 {
3637 await AddAuthorizationHeaderAsync ( request , _currentScheme , cancellationToken ) ;
3738 }
@@ -87,11 +88,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
8788 {
8889 var retryRequest = await CloneHttpRequestMessageAsync ( request ) ;
8990
90- // Use the recommended scheme if provided, otherwise use our best match
91- string schemeToUse = recommendedScheme ?? bestSchemeMatch ;
92- _currentScheme = ! string . IsNullOrEmpty ( recommendedScheme ) ? recommendedScheme : bestSchemeMatch ;
93-
94- await AddAuthorizationHeaderAsync ( retryRequest , schemeToUse , cancellationToken ) ;
91+ _currentScheme = recommendedScheme ?? bestSchemeMatch ;
92+
93+ await AddAuthorizationHeaderAsync ( retryRequest , _currentScheme , cancellationToken ) ;
9594 return await base . SendAsync ( retryRequest , cancellationToken ) ;
9695 }
9796 else
0 commit comments