1

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,

  1. How to get token while I am running the web app within Visual Studio 2022 ?
  2. Is there out of the box solution available to cache the token, if No then what are the options?

Thanks.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
user584018
  • 10,186
  • 15
  • 74
  • 160

0 Answers0