Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class GraphAuthenticationProvider : IAuthenticationProvider
private const string AuthorizationHeaderKey = "Authorization";
readonly IAuthorizationHeaderProvider _authorizationHeaderProvider;
readonly GraphServiceClientOptions _defaultAuthenticationOptions;
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"]);
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"];
readonly IEnumerable<string> _defaultGraphScope = ["https://graph.microsoft.com/.default"];

Expand Down Expand Up @@ -83,9 +84,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
Loading