I have .net 6 web api application and this app is hosted as Azure App Service
and I am using Azure Managed Identity option to retrieve token and using Azure.Identity Version="1.7.0
var tokenCredential = new ChainedTokenCredential(
new ManagedIdentityCredential("", new TokenCredentialOptions
{
Retry =
{
Delay = TimeSpan.FromSeconds(2),
MaxDelay = TimeSpan.FromSeconds(16),
MaxRetries = 5,
Mode = RetryMode.Exponential
}
}),
new AzureCliCredential()
);
var accessToken = await tokenCredential.GetTokenAsync(new TokenRequestContext(new[] { _configuration.GetSection("AzureAd:Scope")?.Value }));
Currently I am only able to run this app as Azure App Service
since identity of the app service is registered with Azure AD app and I am not seeing any out of the box solution to cache the token.
Please suggest to solve below 2 issues,
- How to get token while I am running the web app within Visual Studio 2022 ?
- Is there out of the box solution available to cache the token, if No then what are the options?
Thanks.