Skip to content

Commit d2e90fe

Browse files
Copilothalter73
andcommitted
Address code review feedback: add error handling and remove redundant assertion
Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
1 parent 6742edd commit d2e90fe

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,15 @@ private async Task<string> GetAccessTokenAsync(HttpResponseMessage response, boo
244244
}
245245

246246
// Convert string URIs to Uri objects for the selector
247-
var authServerUris = availableAuthorizationServers.Select(s => new Uri(s)).ToList();
247+
List<Uri> authServerUris = new();
248+
foreach (var serverUriString in availableAuthorizationServers)
249+
{
250+
if (!Uri.TryCreate(serverUriString, UriKind.Absolute, out var serverUri))
251+
{
252+
ThrowFailedToHandleUnauthorizedResponse($"Invalid authorization server URI: '{serverUriString}'. Available servers: {string.Join(", ", availableAuthorizationServers)}");
253+
}
254+
authServerUris.Add(serverUri);
255+
}
248256

249257
// Select authorization server using configured strategy
250258
var selectedAuthServer = _authServerSelector(authServerUris);

tests/ModelContextProtocol.AspNetCore.Tests/OAuth/AuthTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,5 @@ public async Task ResourceMetadata_DoesNotAddTrailingSlash()
788788

789789
// Verify that the Resource property does NOT have a trailing slash added
790790
Assert.Equal(resourceWithoutTrailingSlash, metadata.Resource);
791-
Assert.DoesNotContain(resourceWithoutTrailingSlash + "/", metadata.Resource);
792791
}
793792
}

0 commit comments

Comments
 (0)