Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LauraKokkarinen/83c5a6b883f68038a13d99eccc0ea00f to your computer and use it in GitHub Desktop.
Save LauraKokkarinen/83c5a6b883f68038a13d99eccc0ea00f to your computer and use it in GitHub Desktop.
using Azure.Identity;
public async Task<string> GetAccessTokenAsync(string resourceUrl, string tenantId, string clientId, string clientSecret)
{
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
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