Azure functions 获取DataFactoryManagementClient的凭据

Azure functions 获取DataFactoryManagementClient的凭据,azure-functions,azure-data-factory,azure-managed-identity,Azure Functions,Azure Data Factory,Azure Managed Identity,我有生成凭据以传递给DataFactoryManagementClient的代码。它使用应用程序注册来获取凭据,就像我在控制台应用程序中启动它一样 public DataFactoryClient(string tenantId, string subscriptionId, string applicationId, string clientSecret) { AuthenticationContext context = new Authentication

我有生成凭据以传递给DataFactoryManagementClient的代码。它使用应用程序注册来获取凭据,就像我在控制台应用程序中启动它一样

    public DataFactoryClient(string tenantId, string subscriptionId, string applicationId, string clientSecret)
    {
        AuthenticationContext context = new AuthenticationContext("https://login.windows.net/" + tenantId);
        ClientCredential clientCredential = new ClientCredential(applicationId, clientSecret);
        AuthenticationResult result = context.AcquireTokenAsync(
            "https://management.azure.com/", clientCredential).Result;
        ServiceClientCredentials credentials = new TokenCredentials(result.AccessToken);
        client = new DataFactoryManagementClient(credentials)
        {
            SubscriptionId = subscriptionId
        };
    }
我将代码移动到Azure功能,现在我想摆脱应用程序注册,只使用自动分配的托管身份(我已启用该功能),但我不知道如何。。。DataFactoryManagementClient需要一个ServiceClientCredentials对象,但我有一个ManagedEntityCredential对象


有什么方法可以做到这一点吗?

如果您想将azure函数的系统分配标识与
DataFactoryManagementClient一起使用,您可以使用,当您将代码发布到azure函数时,它将自动使用您函数的系统分配标识

注意:使用代码时,请先为函数应用程序创建连接字符串,要使用系统分配的标识,其值应为
RunAs=app

示例(我在本地测试它以获得ADF,它自动使用VS登录帐户进行身份验证,在azure函数中,它使用系统分配的标识):


您好,如果我的答复有帮助,请接受,谢谢。
using Microsoft.Azure.Management.DataFactory;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Rest;

namespace ConsoleApp11
{
    class Program
    {
        static void Main(string[] args)
        {
            AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
            string accessToken = azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/").Result;
            string subscriptionId = "xxxxxxxx";
            ServiceClientCredentials credentials = new TokenCredentials(accessToken);
            var client = new DataFactoryManagementClient(credentials)
            {
                SubscriptionId = subscriptionId
            };
            var a = client.Factories.Get("group-name","joyfactory");
            System.Console.WriteLine(a);
        }
    }
}