Skip to content

Instantly share code, notes, and snippets.

@dylan-asos
Created April 3, 2019 16:35
Show Gist options
  • Save dylan-asos/2042c927fc6fd849111561fdcb226b08 to your computer and use it in GitHub Desktop.
Save dylan-asos/2042c927fc6fd849111561fdcb226b08 to your computer and use it in GitHub Desktop.
public class MetricsApiAccessTokenProvider
{
private readonly CredentialConfiguration _settings;
public MetricsApiAccessTokenProvider(CredentialConfiguration settings)
{
_settings = settings;
}
public async Task<string> GetAccessToken()
{
var clientCredentials = new ClientCredential(_settings.ClientId, _settings.Secret);
var context = new AuthenticationContext($"https://login.microsoftonline.com/{_settings.TenantId}");
var result = await context.AcquireTokenAsync("https://monitoring.azure.com/", clientCredentials);
return result.AccessToken;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment