diff --git a/sample/Sample.cs b/sample/Sample.cs index 5940e1f..007c0b6 100644 --- a/sample/Sample.cs +++ b/sample/Sample.cs @@ -49,13 +49,13 @@ case "3": // User-Assigned managed identity Write("Redis cache host name: "); cacheHostName = ReadLine()?.Trim(); - Write("Managed identity Client ID: "); - var managedIdentityClientId = ReadLine()?.Trim(); + Write("Managed identity Client ID or resource ID: "); + var managedIdentityId = ReadLine()?.Trim(); Write("Managed identity Principal (object) ID ('Username' from the 'Data Access Configuration' blade on the Azure Cache for Redis resource): "); principalId = ReadLine()?.Trim(); WriteLine("Connecting with a user-assigned managed identity..."); - configurationOptions = await ConfigurationOptions.Parse($"{cacheHostName}:6380").ConfigureForAzureWithUserAssignedManagedIdentityAsync(managedIdentityClientId!, principalId!); + configurationOptions = await ConfigurationOptions.Parse($"{cacheHostName}:6380").ConfigureForAzureWithUserAssignedManagedIdentityAsync(managedIdentityId!, principalId!); configurationOptions.AbortOnConnectFail = true; // Fail fast for the purposes of this sample. In production code, this should remain false to retry connections on startup LogTokenEvents(configurationOptions); diff --git a/src/AzureCacheForRedis.cs b/src/AzureCacheForRedis.cs index 8523882..064ec3c 100644 --- a/src/AzureCacheForRedis.cs +++ b/src/AzureCacheForRedis.cs @@ -41,7 +41,7 @@ public static async Task ConfigureForAzureWithSystemAssign /// Throws on failure by default (configurable in the method). /// /// The configuration to update. - /// Client ID of the user-assigned managed identity. + /// Client ID or resource ID of the user-assigned managed identity. /// Principal (object) ID of the user-assigned managed identity. /// When the token source is not supported or identified incorrectly. /// Unable to contact the identity service to acquire a token. diff --git a/src/CacheIdentityClient.cs b/src/CacheIdentityClient.cs index 41f5255..1b7b171 100644 --- a/src/CacheIdentityClient.cs +++ b/src/CacheIdentityClient.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using Microsoft.Identity.Client; +using Microsoft.Identity.Client.AppConfig; using System; using System.Threading.Tasks; @@ -27,13 +28,11 @@ internal class CacheIdentityClient : ICacheIdentityClient private readonly Func> _getToken; internal static ICacheIdentityClient CreateForSystemAssignedManagedIdentity() - => new CacheIdentityClient(ManagedIdentityApplicationBuilder.Create() - .WithExperimentalFeatures() + => new CacheIdentityClient(ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.SystemAssigned) .Build()); - internal static ICacheIdentityClient CreateForUserAssignedManagedIdentity(string clientId) - => new CacheIdentityClient(ManagedIdentityApplicationBuilder.Create(clientId) - .WithExperimentalFeatures() + internal static ICacheIdentityClient CreateForUserAssignedManagedIdentity(string id) + => new CacheIdentityClient(ManagedIdentityApplicationBuilder.Create(Guid.TryParse(id, out _) ? ManagedIdentityId.WithUserAssignedClientId(id) : ManagedIdentityId.WithUserAssignedResourceId(id)) .Build()); internal static ICacheIdentityClient CreateForServicePrincipal(string clientId, string tenantId, string secret) diff --git a/src/Microsoft.Azure.StackExchangeRedis.csproj b/src/Microsoft.Azure.StackExchangeRedis.csproj index 5ff6145..aa2fa95 100644 --- a/src/Microsoft.Azure.StackExchangeRedis.csproj +++ b/src/Microsoft.Azure.StackExchangeRedis.csproj @@ -13,11 +13,11 @@ - + - + diff --git a/tests/Microsoft.Azure.StackExchangeRedis.Tests.csproj b/tests/Microsoft.Azure.StackExchangeRedis.Tests.csproj index a5853c0..48d58c3 100644 --- a/tests/Microsoft.Azure.StackExchangeRedis.Tests.csproj +++ b/tests/Microsoft.Azure.StackExchangeRedis.Tests.csproj @@ -9,10 +9,10 @@ - - - - + + + +