Created
August 26, 2022 09:44
-
-
Save BenjaminAbt/b1b5468498521cce811d7c9203d7eec4 to your computer and use it in GitHub Desktop.
Microsoft Defender Bearer Token Sample Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MicrosoftDefenderBearerTokenClientProvider | |
{ | |
private const string _authority = "https://login.microsoftonline.com"; | |
private const string _audience = "https://api.securitycenter.microsoft.com"; | |
private static string[] s_scopes = new[] { $"{_audience}/.default" }; | |
public async Task<AuthenticationResult> GetToken | |
(string tenantId, string clientId, string secret) | |
{ | |
IConfidentialClientApplication app = | |
ConfidentialClientApplicationBuilder | |
.Create(clientId).WithClientSecret(secret) | |
.WithAuthority($"{_authority}/{tenantId}").Build(); | |
AuthenticationResult authResult = | |
await app.AcquireTokenForClient(s_scopes) | |
.ExecuteAsync().ConfigureAwait(false); | |
return authResult; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment