diff --git a/src/Microsoft.Identity.Web.GraphServiceClient/GraphAuthenticationProvider.cs b/src/Microsoft.Identity.Web.GraphServiceClient/GraphAuthenticationProvider.cs index a02f96c31..5ba95be17 100644 --- a/src/Microsoft.Identity.Web.GraphServiceClient/GraphAuthenticationProvider.cs +++ b/src/Microsoft.Identity.Web.GraphServiceClient/GraphAuthenticationProvider.cs @@ -23,7 +23,7 @@ internal class GraphAuthenticationProvider : IAuthenticationProvider private const string AuthorizationHeaderKey = "Authorization"; readonly IAuthorizationHeaderProvider _authorizationHeaderProvider; readonly GraphServiceClientOptions _defaultAuthenticationOptions; - private readonly string[] _graphUris = ["graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de", "microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com", "graph.microsoft-ppe.com"]; + private static readonly AllowedHostsValidator _allowedGraphHostsValidator = new(["graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de", "microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com", "graph.microsoft-ppe.com"]); readonly IEnumerable _defaultGraphScope = ["https://graph.microsoft.com/.default"]; /// @@ -83,9 +83,8 @@ public async Task AuthenticateRequestAsync( authorizationHeaderProviderOptions = graphServiceClientOptions; } - AllowedHostsValidator allowedHostsValidator = new(_graphUris); // Add the authorization header - if (allowedHostsValidator.IsUrlHostValid(request.URI) && !request.Headers.ContainsKey(AuthorizationHeaderKey)) + if (_allowedGraphHostsValidator.IsUrlHostValid(request.URI) && !request.Headers.ContainsKey(AuthorizationHeaderKey)) { string authorizationHeader = await _authorizationHeaderProvider.CreateAuthorizationHeaderAsync( authorizationHeaderProviderOptions!.RequestAppToken ? _defaultGraphScope : scopes!, diff --git a/tests/E2E Tests/GraphServiceClientTests/GraphServiceClientTests.cs b/tests/E2E Tests/GraphServiceClientTests/GraphServiceClientTests.cs index b2b494747..aaeb1c586 100644 --- a/tests/E2E Tests/GraphServiceClientTests/GraphServiceClientTests.cs +++ b/tests/E2E Tests/GraphServiceClientTests/GraphServiceClientTests.cs @@ -66,7 +66,6 @@ async Task TestAsync() o.RequestAppToken = true; }); }); - } [Fact]