繁体   English   中英

Azure链接服务与数据工厂自定义活动

[英]Azure linked services with data factory custom activity

我无法使用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 ---

根据您的例外,看来您使用的是Web客户端的资源所有者流。 机密客户端(例如Web App客户端) 不能使用直接用户凭据。

您将需要作为公共客户端(本机客户端应用程序)而不是作为机密客户端(Web应用程序/ API)来调用它。 请参考本文档,以获取有关如何使用ADAL的更多信息,尤其是“ 约束与限制”部分

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

要访问您的订阅中的资源,您需要为注册的应用分配角色。

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

 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;

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM