An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
AuthenticationFailure occurs because Azure Managed Redis does not accept a raw Entra ID access token in the Password field. Instead, use the Microsoft.Azure.StackExchangeRedis extensions, which handle token acquisition and connection configuration for Azure Managed Redis.
Key points from the sample:
- Use
Microsoft.Azure.StackExchangeRedisandDefaultAzureCredential. - Do not set
Passwordmanually. - Call
ConfigureForAzureWithTokenCredentialAsynconConfigurationOptionsbefore connecting.
A minimal version of the diagnostics endpoint using the supported pattern:
using Azure.Identity;
using Microsoft.Azure.StackExchangeRedis;
using StackExchange.Redis;
app.MapGet("/diagnostics/redis", async (IConfiguration config) =>
{
var result = new Dictionary<string, object>();
try
{
var endpoint = config.GetValue<string>("Redis:Endpoint");
var options = new ConfigurationOptions
{
EndPoints = { endpoint },
// Optional: logging, SSL, etc. are handled by ConfigureForAzureWithTokenCredentialAsync
};
// This wires up Entra ID token-based auth correctly
await options.ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential());
using var redis = await ConnectionMultiplexer.ConnectAsync(options);
var db = redis.GetDatabase();
var ping = await db.PingAsync();
result["redisPing"] = ping.ToString();
await db.StringSetAsync("diagnostic_test", "ok");
var value = await db.StringGetAsync("diagnostic_test");
result["redisWriteRead"] = value.ToString();
return Results.Ok(result);
}
catch (Exception ex)
{
result["error"] = ex.Message;
result["stackTrace"] = ex.StackTrace;
return Results.Problem(JsonSerializer.Serialize(result));
}
});
Configuration (for local development):
{
"Redis": {
"Endpoint": "<your-redis-name>.<region>.redis.azure.net:10000"
}
}
Additional checks:
- Ensure the App Service’s managed identity (or service principal) is added as a Redis user under Authentication → Microsoft Entra Authentication → User or service principal on the Azure Managed Redis resource.
- For local testing, run
az loginsoDefaultAzureCredentialcan obtain a token. - Keep the connection multiplexer as a singleton in production (for example, via DI) rather than creating it per request, as shown in the ASP.NET sample.
Using this pattern aligns with the official Azure Managed Redis samples and resolves the AuthenticationFailure caused by passing the token as a password.
References: