Created
May 11, 2024 09:21
-
-
Save LauraKokkarinen/893a6241e18e7854a3164a9c221199b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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