Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LauraKokkarinen/893a6241e18e7854a3164a9c221199b6 to your computer and use it in GitHub Desktop.
Save LauraKokkarinen/893a6241e18e7854a3164a9c221199b6 to your computer and use it in GitHub Desktop.
public async Task<string> GetAccessTokenAsync(string resourceUrl, string tenantId, string clientId, string pfxCertDirPath, string pfxCertPassword)
{
var clientCertificate = new X509Certificate2(pfxCertDirPath, pfxCertPassword);
var credential = new ClientCertificateCredential(tenantId, clientId, clientCertificate);
var accessToken = await credential.GetTokenAsync(new TokenRequestContext(scopes: [resourceUrl + "/.default"]) { });
return accessToken.Token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment