Skip to content

Instantly share code, notes, and snippets.

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