2017-11-09 18 views
1

nugetパッケージを使用するAzure関数を作成すると、Microsoft.Rest.ClientRuntime.Azure.AuthenticationがDataLakeに認証され、Microsoft.IdentityModel.Clients.ActiveDirectoryがHDInsightに認証されます。関数プロジェクトに両方をインストールしようとすると、次のエラーが表示されます。Microsoft.IdentityModel.Clients.ActiveDirectoryのバージョン競合が検出されました

uninstall-package:Microsoft.IdentityModel.Clients.ActiveDirectoryのバージョン競合が検出されました。この 問題を解決するには、プロジェクトからパッケージを直接参照してください。 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プレビュー) - > Microsoft.IdentityModel.Clients.ActiveDirectory(> = 2.18.206251556)

Microsoft.Azure.Common.Authentication 1.7.0-プレビューがMicrosoft.IdentityModel.Clients.ActiveDirectory 2.18.206251556のみを参照するに制約があるように見えます。残念ながら、このライブラリは2016年2月から更新されていません。https://docs.microsoft.com/en-us/azure/hdinsight/hdinsight-create-non-interactive-authentication-dotnet-applications

答えて

1

Microsoft.IdentityModel.Clients.ActiveDirectoryを直接使用して、アクセストークンの代わりにMicrosoft.Azure.Common.Authenticationパッケージを使用してください。

あなたの説明に基づいて、この問題をテストするために私のazure関数プロジェクトを作成しました。次のように私はパッケージをインストール:トークンを取得するための

enter image description here

方法:

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機能:

[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

私の答えがあなたを助けてくれる場合は、このような問題に遭遇する可能性がある他のメンバーのための受け入れ可能な回答として親切にそれをマークしてください。 –

0

を依存aを解決しようとした後、私はブルースの提案を取ったいくつかの異なる方法、レモMicrosoft.Azure.Common.Authenticationへの参照をすべて使用し、代わりにMicrosoft.IdentityModel.Clients.ActiveDirectoryを使用してトークンを取得しました。

関連する問題