Skip to content

Commit

Permalink
Lozensky/perf fix graph service client (#3251)
Browse files Browse the repository at this point in the history
* Moving validator to static member
  • Loading branch information
JoshLozensky authored Feb 22, 2025
1 parent ae4211e commit bbe8494
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> _defaultGraphScope = ["https://graph.microsoft.com/.default"];

/// <summary>
Expand Down Expand Up @@ -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!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ async Task TestAsync()
o.RequestAppToken = true;
});
});

}

[Fact]
Expand Down

0 comments on commit bbe8494

Please sign in to comment.