【问题标题】:Azure linked services with data factory custom activity具有数据工厂自定义活动的 Azure 链接服务
【发布时间】:2018-05-12 19:00:45
【问题描述】:

无法使用 Azure 数据工厂 (ADF) 创建链接服务, 我对 ADF 级别的链接服务具有读/写权限。

using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.DataFactory;
using Microsoft.Azure.Management.DataFactory.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

LinkedServiceResource storageLinkedService = new 
LinkedServiceResource(
new AzureStorageLinkedService
{
ConnectionString = new 
SecureString("DefaultEndpointsProtocol=https;AccountName=" + 
storageAccount + ";AccountKey=" + storageKey)
}
);
client.LinkedServices.CreateOrUpdate(resourceGroup, 
dataFactoryName, storageLinkedServiceName, storageLinkedService);

顺便说一句,我同时使用了客户端凭据和用户凭据

ClientCredential cc = new ClientCredential(applicationId, 
authenticationKey);
var cc = new UserPasswordCredential(userName, password);

使用客户端凭据的错误响应:

Microsoft.Azure.Management.DataFactory.Models.ErrorResponseException: 
Operation returned an invalid status code 'Forbidden'
at Microsoft.Azure.Management.DataFactory.LinkedServicesOperations.
<CreateOrUpdateWithHttpMessagesAsync>d__6.MoveNext() --- End of stack 
trace from previous location where exception was thrown ---

使用用户凭证的错误响应:

System.Net.Http.HttpRequestException:  Response status code does not 
indicate success: 401 (Unauthorized). ---> 
Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: 
{"error":"invalid_client","error_description":"AADSTS70002: The 
request body must contain the following parameter: 'client_secret or 
client_assertion'.\r\nTrace ID: 2264d637-8786-4a40-96d4-
5d27b0670300\r\nCorrelation ID: fec688c8-bb92-49c2-86d3-
1e091181fe10\r\nTimestamp: 2017-11-29 05:30:23Z","error_codes":
[70002],"timestamp":"2017-11-29 05:30:23Z","trace_id":"2264d637-8786-
4a40-96d4-5d27b0670300","correlation_id":"fec688c8-bb92-49c2-86d3-
1e091181fe10"}: Unknown error
--- End of inner exception stack trace ---

【问题讨论】:

  • 你的问题到底是什么?
  • 无法在 Azure 数据工厂中使用 .net 自定义活动创建链接服务

标签: c# azure azure-data-factory


【解决方案1】:

根据您的例外情况,您似乎使用来自 Web 客户端的资源所有者流程。机密客户端(例如 Web 应用客户端)无法使用直接用户凭据。

您需要将其作为公共客户端(本机客户端应用)调用,而不是作为机密客户端(网络应用/API)调用。有关如何使用 ADAL 的更多信息,请参阅此document,尤其是约束和限制部分

没有网站/机密客户 这不是 ADAL 限制,而是 AAD 设置。您只能从本机客户端使用这些流。机密客户端(例如网站)不能使用直接用户凭据。

要访问订阅中的资源,您需要assign role to the registried App.

请尝试使用以下方法获取 TokenCredentials,以下是创建墨迹服务的演示代码。它在我这边正常工作。我们也可以参考这个document。

 private static async Task<string> GetToken(string tenantId, string clientId, string secretKey)
        {
            var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
            ClientCredential clientCredential = new ClientCredential(clientId, secretKey);
            var tokenResponse = await context.AcquireTokenAsync("https://management.azure.com/", clientCredential); 
            var accessToken = tokenResponse.AccessToken;
            return accessToken;
        }



        var token = GetToken(_tenantId, _clientId, _screctKey).Result;
        TokenCredentials credentials = new TokenCredentials(token);
        DataFactoryManagementClient client = new 
        DataFactoryManagementClient(credentials) { SubscriptionId = subscriptionId };
        DataFactoryManagementClient client = new DataFactoryManagementClient(credentials) { SubscriptionId = subscriptionId };
        LinkedServiceResource storageLinkedService = new LinkedServiceResource(new AzureStorageLinkedService{
                     ConnectionString = new SecureString("DefaultEndpointsProtocol=https;AccountName=" + storageAccount + ";AccountKey=" + storageKey)});

       var result =client.LinkedServices.CreateOrUpdateWithHttpMessagesAsync(resourceGroup, factoryName, storageLinkedServiceName, storageLinkedService).Result;

【讨论】:

    猜你喜欢
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 2019-05-09
    • 2018-10-02
    相关资源
    最近更新 更多