Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BenjaminAbt/b1b5468498521cce811d7c9203d7eec4 to your computer and use it in GitHub Desktop.
Save BenjaminAbt/b1b5468498521cce811d7c9203d7eec4 to your computer and use it in GitHub Desktop.
Microsoft Defender Bearer Token Sample Provider
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