Open Closed

Use Azure Redis with DefaultAzureCredential instead of connection string #10492


User avatar
0
thanhlg created

Hi ABP team, We want to authenticate to Azure Redis Cache using DefaultAzureCredential as described in Microsoft’s documentation Azure Cache for Redis - .NET developer guide, not via a connection string that contains credential data (e.g. password). Currently, ABP’s Redis integration 1 only supports configuration via connection string. We need to use DefaultAzureCredential (e.g. Managed Identity in Azure) for secretless, secure authentication. Could you please:

  1. Confirm whether ABP has (or plans) built-in support for Azure Redis with DefaultAzureCredential / TokenCredential.
  2. If not, provide guidance or a sample on how to override the default Redis cache configuration so we can use Microsoft.Azure.StackExchangeRedis with ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()) and register it correctly with AddStackExchangeRedisCache (e.g. in ConfigureServicesAsync), without breaking existing ABP caching behavior.

2 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • (1) Built-in support / plans

      • In ABP Framework v10.0.3, there is no built-in, ABP-specific switch for “Azure Redis authentication via DefaultAzureCredential / TokenCredential” (i.e., no first-class ABP abstraction that exposes ConfigureForAzureWithTokenCredentialAsync(...)).
      • What ABP does support is: ABP’s caching builds on ASP.NET Core distributed cache, so you can configure Redis using the underlying Microsoft.Extensions.Caching.StackExchangeRedis options yourself (including RedisCacheOptions.ConfigurationOptions), and ABP will continue to work on top of it.
    • (2) Guidance: override Redis cache configuration (keep ABP behavior)

      1. Keep using ABP’s Redis integration package/module (Volo.Abp.Caching.StackExchangeRedis) so you don’t lose ABP features like GetManyAsync / SetManyAsync.
      2. Override the Redis cache setup by configuring RedisCacheOptions and providing a fully-built StackExchange.Redis.ConfigurationOptions (instead of using options.Configuration / connection string).
      3. In that configuration delegate, call the Azure Redis helper that applies Entra ID auth (token credential) and other Azure-required settings.

      Example (in your Blazor Server Web module; works the same idea in any ABP module):

    using Azure.Identity;
      using Microsoft.Extensions.Caching.StackExchangeRedis;
      using StackExchange.Redis;
      using Volo.Abp.Modularity;
    
      [DependsOn(typeof(Volo.Abp.Caching.StackExchangeRedis.AbpCachingStackExchangeRedisModule))]
      public class MyBlazorServerWebModule : AbpModule
      {
          public override void ConfigureServices(ServiceConfigurationContext context)
          {
              var configuration = context.Services.GetConfiguration();
    
              // Configure the underlying Microsoft RedisCacheOptions that ABP builds on.
              context.Services.Configure<RedisCacheOptions>(options =>
              {
                  // 1) Build ConfigurationOptions without password
                  // Put only host/port/ssl/etc here (no secrets).
                  // Example value: "mycache.redis.cache.windows.net:6380,ssl=True,abortConnect=False"
                  var redisEndpoint = configuration["Redis:Endpoint"];
    
                  var configOptions = ConfigurationOptions.Parse(redisEndpoint);
    
                  // 2) Apply Azure Redis Entra ID auth using DefaultAzureCredential (Managed Identity etc.)
                  // This method is provided by Microsoft.Azure.StackExchangeRedis package.
                  // NOTE: This is async; if your helper is async-only, prefer the non-async overload if available,
                  // or ensure the package provides a sync alternative.
                  configOptions.ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential())
                               .GetAwaiter()
                               .GetResult();
    
                  // 3) Assign to RedisCacheOptions
                  options.ConfigurationOptions = configOptions;
              });
          }
      }
    

    Notes that keep ABP caching behavior intact:

    • ABP will still resolve and use IDistributedCache as usual; your change only affects how Redis is connected/authenticated.
    • Don’t replace ABP’s caching services with your own implementation—just configure RedisCacheOptions as above.

    Sources (validated):

    • https://abp.io/docs/latest/framework/fundamentals/redis-cache
    • https://abp.io/community/articles/94old5rm

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Here is abp redis module code:

    public class AbpCachingStackExchangeRedisModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();
    
            var redisEnabled = configuration["Redis:IsEnabled"];
            if (string.IsNullOrEmpty(redisEnabled) || bool.Parse(redisEnabled))
            {
                context.Services.AddStackExchangeRedisCache(options =>
                {
                    var redisConfiguration = configuration["Redis:Configuration"];
                    if (!redisConfiguration.IsNullOrEmpty())
                    {
                        options.Configuration = redisConfiguration;
                    }
                });
    
                context.Services.Replace(ServiceDescriptor.Singleton<IDistributedCache, AbpRedisCache>());
            }
        }
    }
    

    You can call the AddStackExchangeRedisCache again to override/set more configuration.

    Thanks.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.3.0-preview. Updated on March 02, 2026, 08:48
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.