Skip to content

Commit 58a7a3d

Browse files
committed
Update AuthorizationHelpers.cs
1 parent 0abea22 commit 58a7a3d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ModelContextProtocol/Authentication/AuthorizationHelpers.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ModelContextProtocol.Utils;
1+
using Microsoft.Extensions.Logging;
2+
using Microsoft.Extensions.Logging.Abstractions;
23
using ModelContextProtocol.Utils.Json;
34
using System.Text.Json;
45

@@ -10,15 +11,18 @@ namespace ModelContextProtocol.Authentication;
1011
public class AuthorizationHelpers
1112
{
1213
private readonly HttpClient _httpClient;
14+
private readonly ILogger _logger;
1315
private static readonly Lazy<HttpClient> _defaultHttpClient = new(() => new HttpClient());
1416

1517
/// <summary>
1618
/// Initializes a new instance of the <see cref="AuthorizationHelpers"/> class.
1719
/// </summary>
1820
/// <param name="httpClient">The HTTP client to use for requests. If null, a default HttpClient will be used.</param>
19-
public AuthorizationHelpers(HttpClient? httpClient = null)
21+
/// <param name="logger">The logger to use. If null, a NullLogger will be used.</param>
22+
public AuthorizationHelpers(HttpClient? httpClient = null, ILogger? logger = null)
2023
{
2124
_httpClient = httpClient ?? _defaultHttpClient.Value;
25+
_logger = logger ?? NullLogger.Instance;
2226
}
2327

2428
/// <summary>
@@ -42,8 +46,9 @@ public AuthorizationHelpers(HttpClient? httpClient = null)
4246
McpJsonUtilities.JsonContext.Default.ProtectedResourceMetadata,
4347
cancellationToken).ConfigureAwait(false);
4448
}
45-
catch (Exception)
49+
catch (Exception ex)
4650
{
51+
_logger.LogError(ex, $"Failed to fetch protected resource metadata from {metadataUrl}");
4752
return null;
4853
}
4954
}

0 commit comments

Comments
 (0)