Skip to content

Instantly share code, notes, and snippets.

@AnnejanBarelds
Created March 4, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnnejanBarelds/55ff9f4d109c5d84e5587c39361b8d46 to your computer and use it in GitHub Desktop.
Save AnnejanBarelds/55ff9f4d109c5d84e5587c39361b8d46 to your computer and use it in GitHub Desktop.
private async Task<string> GetTokenAsync(string appId, X509Certificate2 certificate, string tenantId)
{
var app = ConfidentialClientApplicationBuilder.Create(appId)
.WithAuthority($"https://login.microsoftonline.com/{tenantId}/")
.WithCertificate(certificate)
.Build();
var scopes = new[] { "https://graph.microsoft.com/.default" };
var result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
return result.AccessToken;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment