简体   繁体   English

BizTalk 2016:如何使用带有API令牌的HTTP发送适配器

[英]BizTalk 2016: How to use HTTP Send adapter with API token

I need to make calls to a rest API service via BizTalk Send adapter. 我需要通过BizTalk Send适配器调用其他API服务。 The API simply uses a token in the header for authentication/authorization. API只是在标头中使用标记进行身份验证/授权。 I have tested this in a C# console app using httpclient and it works fine: 我已经使用httpclient在C#控制台应用程序中对此进行了测试,它运行正常:

string apiUrl = "https://api.site.com/endpoint/<method>?";
        string dateFormat = "dateFormat = 2017-05-01T00:00:00";

        using (var client = new HttpClient())
        {

            client.DefaultRequestHeaders.Add("token", "<token>");
            client.DefaultRequestHeaders.Add("Accept", "application/json");

            string finalurl = apiUrl + dateFormat;
            HttpResponseMessage resp = await client.GetAsync(finalurl);
            if (resp.IsSuccessStatusCode)
            {
                string result = await resp.Content.ReadAsStringAsync();
                var rootresult = JsonConvert.DeserializeObject<jobList>(result);
                return rootresult;

            }
            else
            {
                return null;
            }
        }

however I want to use BizTalk to make the call and handle the response. 但是我想使用BizTalk来进行调用并处理响应。

I have tried using the wcf-http adapter, selecting 'Transport' for security (it is an https site so security is required(?)) with no credential type specified and placed the header with the token in the 'messages' tab of the adapter configuration. 我尝试过使用wcf-http适配器,选择“传输”作为安全性(它是一个https站点,因此需要安全性(?)),没有指定凭据类型,并将带有令牌的标头放在“消息”选项卡中适配器配置。 This fails though with the exception: System.IO.IOException: Authentication failed because the remote party has closed the transport stream. 但是这会失败,但出现异常:System.IO.IOException:身份验证失败,因为远程方已关闭传输流。

I have tried googling for this specific scenario and cannot find a solution. 我已经尝试使用谷歌搜索这个特定的场景,无法找到解决方案。 I did find this article with suggestions for OAUth handling but I'm surprised that even with BizTalk 2016 I still have to create a custom assembly for something so simple. 我确实发现这篇文章有关于OAUth处理的建议但是我很惊讶即使使用BizTalk 2016我仍然需要为这么简单的事情创建一个自定义程序集。

Does anyone know how this might be done in the wcf-http send adapter? 有谁知道如何在wcf-http发送适配器中完成这项工作?

Yes, you have to write a custom Endpoint Behaviour and add it to the send port. 是的,您必须编写自定义端点行为并将其添加到发送端口。 In fact with the WCF-WebHttp adapter even Basic Auth doesn't work so I'm currently writing an Endpoint Behaviour to address this. 事实上,使用WCF-WebHttp适配器,即使Basic Auth不起作用,所以我正在编写一个端点行为来解决这个问题。

One of the issues with OAuth, is that there isn't one standard that everyone follows, so far I've had to write 2 different OAuth behaviours as they have implemented things differently. OAuth的一个问题是,每个人都没有遵循的标准,到目前为止,我必须编写2种不同的OAuth行为,因为它们实现的方式不同。 One using a secret and time stamp hashed to has to get a token, and the other using Basic Auth to get a token. 使用密钥和时间戳的人必须获得令牌,而另一个使用Basic Auth获取令牌。 Also one of them you could get multiple tokens using the same creds, whereas the other would expire the old token straight away. 其中一个你可以使用相同的信用卡获得多个令牌,而另一个将直接使旧令牌过期。

Another thing I've had to write a custom behaviour for is which version of TLS the end points expects as by default BizTalk 2013 R2 tries TLS 1.0, and then will fail if the web site does not allow it. 我必须编写自定义行为的另一件事是端点期望的TLS版本,默认情况下BizTalk 2013 R2会尝试TLS 1.0,如果网站不允许,则会失败。

You can feedback to Microsoft that you wish to have this feature by voting on Add support for OAuth 2.0 / OpenID Connect authentication 您可以通过投票添加对OAuth 2.0 / OpenID Connect身份验证的支持,向Microsoft提供您希望拥有此功能的反馈

Maybe someone will open source their solution. 也许有人会开源他们的解决方案。 See Announcement: BizTalk Server embrace open source! 请参阅公告: BizTalk Server包含开源!

Figured it out. 弄清楚了。 I should have used the 'Certificate' for client credential type. 我应该使用'证书'作为客户端凭据类型。

I just had to: 我只需要:

  1. Add token in the Outbound HTTP Headers box in the Messages tab and select 'Transport' security and 'Certificate' for Transport client credential type. 在“消息”选项卡的“出站HTTP标头”框中添加令牌,然后为“传输”客户端凭据类型选择“传输”安全性和“证书”。
  2. Downloaded the certificate from the API's website via the browser (manually) and installed it on the local servers certificate store. 通过浏览器(手动)从API网站下载证书,并将其安装在本地服务器证书存储区中。
  3. I then selected that certificate and thumbprint in the corresponding fields in the adapter via the 'browse' buttons (had to scroll through the available certificates and select the API/website certificate I was trying to connect to). 然后,我通过“浏览”按钮在适配器的相应字段中选择了证书和指纹(必须滚动可用的证书并选择我尝试连接的API /网站证书)。

I discovered this on accident when I had Fiddler running and set the adapter proxy setting to the local Fiddler address ( http://localhost:8888 ). 当我运行Fiddler并将适配器代理设置设置为本地Fiddler地址( http:// localhost:8888 )时,我偶然发现了这一点。 I realized that since Fiddler negotiates the TLS connection/certificate (I enabled tls1.2 in fiddler) to the remote server, messages were able to get through but not directly between the adapter and the remote API server (when Fiddler WASN'T running). 我意识到,由于Fiddler协商TLS连接/证书(我在fiddler中启用tls1.2)到远程服务器,消息能够通过而不是直接在适配器和远程API服务器之间(当Fiddler没有运行时) 。

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

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