1
votes

Creating an Azure function that uses nuget packages Microsoft.Rest.ClientRuntime.Azure.Authentication for authenticating to DataLake as well as Microsoft.IdentityModel.Clients.ActiveDirectory for authenticating to HDInsight. Getting the following error when I try to install both in the function project:

uninstall-package : Version conflict detected for Microsoft.IdentityModel.Clients.ActiveDirectory. Reference the package directly from the project to resolve this issue. MyProject.Functions (>= 1.0.0) -> Microsoft.Rest.ClientRuntime.Azure.Authentication (>= 2.3.1) -> Microsoft.IdentityModel.Clients.ActiveDirectory (>= 2.28.3) MyProject.Functions (>= 1.0.0) -> Microsoft.Azure.Common.Authentication (>= 1.7.0-preview) -> Microsoft.IdentityModel.Clients.ActiveDirectory (>=2.18.206251556).

It looks like Microsoft.Azure.Common.Authentication 1.7.0-preview has a constraint on referencing Microsoft.IdentityModel.Clients.ActiveDirectory 2.18.206251556 only. Unfortunately this library has not been updated since February 2016 and I'm not sure of another way of authenticating non-interactively with HDInsight besides the steps outlined at https://docs.microsoft.com/en-us/azure/hdinsight/hdinsight-create-non-interactive-authentication-dotnet-applications

2

2 Answers

1
votes

Per my understanding, you could directly use the package Microsoft.IdentityModel.Clients.ActiveDirectory to retrieve the access token instead of using the Microsoft.Azure.Common.Authentication package.

Based on your description, I created my azure function project to test this issue. I installed the packages as follows:

enter image description here

Method for retrieving the token:

private static string GetAuthorizationToken()
{
    string tenantId = "xxx";
    string clientId = "xxx";
    string clientSecrets = "xxx";

    var context = new AuthenticationContext(String.Format("https://login.windows.net/{0}", tenantId));
    AuthenticationResult result = context.AcquireTokenAsync(
                "https://management.azure.com/"
            , new ClientCredential(clientId, clientSecrets)
            ).Result;
    return result.AccessToken;
}

My function:

[FunctionName("Function1")]
public static void Run([TimerTrigger("*/10 * * * * *")]TimerInfo myTimer,TraceWriter log)
{
    TokenCloudCredentials tokenCredential = new TokenCloudCredentials("{subscriptionId}", GetAuthorizationToken());
    HDInsightManagementClient _hdiManagementClient = new HDInsightManagementClient(tokenCredential);
    var results = _hdiManagementClient.Clusters.List();
    foreach (var name in results.Clusters)
    {
        Console.WriteLine("Cluster Name: " + name.Name);
        Console.WriteLine("\t Cluster type: " + name.Properties.ClusterDefinition.ClusterType);
        Console.WriteLine("\t Cluster location: " + name.Location);
        Console.WriteLine("\t Cluster version: " + name.Properties.ClusterVersion);
    }
}
0
votes

After attempting to resolve the dependency a few different ways I took Bruce's suggestion, removed all references to Microsoft.Azure.Common.Authentication and used Microsoft.IdentityModel.Clients.ActiveDirectory to get the token instead.