gpt4 book ai didi

c# - 检测到 Microsoft.IdentityModel.Clients.ActiveDirectory 的版本冲突

转载 作者:行者123 更新时间:2023-12-03 03:02:55 30 4
gpt4 key购买 nike

创建一个 Azure 函数,该函数使用 nuget 包 Microsoft.Rest.ClientRuntime.Azure.Authentication 向 DataLake 进行身份验证,并使用 Microsoft.IdentityModel.Clients.ActiveDirectory 向 HDInsight 进行身份验证。当我尝试在函数项目中安装两者时出现以下错误:

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).

看起来 Microsoft.Azure.Common.Authentication 1.7.0-preview 仅限于引用 Microsoft.IdentityModel.Clients.ActiveDirectory 2.18.206251556。不幸的是,该库自 2016 年 2 月以来一直没有更新,除了 https://learn.microsoft.com/en-us/azure/hdinsight/hdinsight-create-non-interactive-authentication-dotnet-applications 中概述的步骤之外,我不确定是否还有其他与 HDInsight 进行非交互式身份验证的方法。

最佳答案

据我了解,您可以直接使用包 Microsoft.IdentityModel.Clients.ActiveDirectory检索访问 token ,而不是使用 Microsoft.Azure.Common.Authentication 包。

根据您的描述,我创建了我的azure函数项目来测试这个问题。我按如下方式安装了软件包:

enter image description here

获取 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;
}

我的功能:

[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);
}
}

关于c# - 检测到 Microsoft.IdentityModel.Clients.ActiveDirectory 的版本冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47192919/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com