File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -268,8 +268,12 @@ private static async Task<IDatabase> InitializeRedis(IOptions<AppSettings> optio
268268 configurationOptions . Ssl = true ;
269269 configurationOptions . AbortOnConnectFail = false ;
270270
271- // Configure Azure Active Directory authentication using managed identity
272- await configurationOptions . ConfigureForAzureWithTokenCredentialAsync ( new DefaultAzureCredential ( ) ) ;
271+ // Use the user-assigned managed identity for Entra ID authentication.
272+ // DefaultAzureCredential without a client ID would use the system-assigned identity,
273+ // which does not have a Redis access policy assigned.
274+ var managedIdentityAppId = options . Value . AzureManagedIdentityApplicationId ;
275+ var credential = new ManagedIdentityCredential ( clientId : managedIdentityAppId ) ;
276+ await configurationOptions . ConfigureForAzureWithTokenCredentialAsync ( credential ) ;
273277
274278 var connection = await ConnectionMultiplexer . ConnectAsync ( configurationOptions ) ;
275279 return connection . GetDatabase ( ) ;
You can’t perform that action at this time.
0 commit comments