private async Task <string> GetToken(string authority, string resource, string scope) { var clientAssertionCertPfx = CertificateHelper.FindCertificateByThumbprint(CertificateThumbprint); ClientAssertionCertificate assertionCert = new ClientAssertionCertificate(AzureADClientId, clientAssertionCertPfx); AuthenticationResult result = null; AuthenticationContext context = new AuthenticationContext(authority, TokenCache.DefaultShared); if (assertionCert != null) { result = await context.AcquireTokenAsync(resource, assertionCert); } if (result == null) { throw new InvalidOperationException("Failed to obtain the access token"); } return(result.AccessToken); }