Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LauraKokkarinen/ad723b60c7bb6f29be6bb197ef5e827b to your computer and use it in GitHub Desktop.
Save LauraKokkarinen/ad723b60c7bb6f29be6bb197ef5e827b to your computer and use it in GitHub Desktop.
using Azure.Identity;
public async Task<string> GetAccessTokenAsync(string resourceUrl)
{
var credential = new DefaultAzureCredential(); // Or new ManagedIdentityCredential();
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