Skip to content

Commit 2945083

Browse files
committed
Clean up scheme checks
1 parent d72221d commit 2945083

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/ModelContextProtocol/Authentication/AuthorizationDelegatingHandler.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ModelContextProtocol.Authentication.Types;
2+
using ModelContextProtocol.Utils;
23
using System.Net.Http.Headers;
34

45
namespace ModelContextProtocol.Authentication;
@@ -9,7 +10,7 @@ namespace ModelContextProtocol.Authentication;
910
public 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

Comments
 (0)