private ICacheIdentityClient GetIdentityClient()

in src/AzureCacheOptionsProviderWithToken.cs [59:83]


    private ICacheIdentityClient GetIdentityClient(AzureCacheOptions azureCacheOptions)
    {
        if (azureCacheOptions.TokenCredential is not null) // DefaultAzureCredential (or other TokenCredential)
        {
            return CacheIdentityClient.CreateForTokenCredential(azureCacheOptions.TokenCredential, azureCacheOptions.Scope);
        }
        else if (azureCacheOptions.ServicePrincipalTenantId is not null || azureCacheOptions.ServicePrincipalSecret is not null || azureCacheOptions.ServicePrincipalCertificate is not null) // Service Principal
        {
            if (azureCacheOptions.ClientId is null || azureCacheOptions.ServicePrincipalTenantId is null)
            {
                throw new ArgumentException($"To use a service principal, {nameof(azureCacheOptions.ClientId)} and {nameof(azureCacheOptions.ServicePrincipalTenantId)} must be specified");
            }

            if (azureCacheOptions.ServicePrincipalSecret is null && azureCacheOptions.ServicePrincipalCertificate is null)
            {
                throw new ArgumentException($"To use a service principal, {nameof(azureCacheOptions.ServicePrincipalSecret)} or {nameof(azureCacheOptions.ServicePrincipalCertificate)} must be specified");
            }

            return CacheIdentityClient.CreateForServicePrincipal(azureCacheOptions);
        }
        else // Managed identity
        {
            return CacheIdentityClient.CreateForManagedIdentity(azureCacheOptions);
        }
    }