gpt4 book ai didi

wpf - 如何将 RestClient 与 Oauth 2.0 和客户端 + TLS 证书一起使用?

转载 作者:行者123 更新时间:2023-12-04 22:35:48 25 4
gpt4 key购买 nike

我是 OAuth2.0 和所有证书内容的新手所以请饶了我 ;-)

今天,我正在尝试与银行的 REST API 进行交互。他们提供了很好的解释,可在此处找到 https://developer.ing.com/openbanking/get-started然而,这些都是为网络开发而写的(我认为),所有的 OAuth 东西对我来说都是新的。我创建了一个新的测试应用程序,它应该连接到银行的沙盒环境。但是我不清楚将证书放在哪里。我有四个文件;客户端证书+ key 和TLS证书+ key 。除此之外,我已经注册了我的应用程序并收到了一个 ClientID。但是,在使用沙盒环境进行测试时,他们会提供一个 ClientID 供公众使用(与证书相同)

这是我目前得到的代码:

'Example: https://developer.ing.com/openbanking/get-started
'OAuth2.0 explained: https://developer.ing.com/api-marketplace/marketplace/2d00fd5f-88cd-4416-bbca-f309ebb03bfe/documentation#introduction

'Create New RestClient
Dim ClientIDSandBox As String = "e77d776b-90af-4684-bebc-521e5b2614dd"
Dim client As New RestClient("https://api.sandbox.ing.com/")

'Some code i found here: https://forums.xamarin.com/discussion/139799/call-to-tls-1-2-server-with-restsharp-works-in-console-app-not-in-xamarin-forms
ServicePointManager.Expect100Continue = True
ServicePointManager.DefaultConnectionLimit = 9999
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
client.Proxy = New WebProxy

'Create new certificate collection containing the Client and TLS certificate
Dim certColl As New X509CertificateCollection
certColl.Add(New X509Certificate("../../ING/Sandbox/example_client_tls.cer")) 'A TLS connection certificate used for setting up a mutual TLS connection
certColl.Add(New X509Certificate("../../ING/Sandbox/example_client_signing.cer")) 'A HTTP Signature certificate used for signing the token request in accordance with the Signature Header RFC
client.ClientCertificates = certColl

'Create new request
Dim request As New RestRequest("/oauth2/token", DataFormat.None)

'Add custom headers to request
request.AddHeader("Content-Type", "application/x-www-form-urlencoded")
request.AddHeader("Date", Now.ToUniversalTime().ToString("r"))
request.AddHeader("Digest", "SHA-256=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
request.AddHeader("Authorization", $"Signature keyId={ClientIDSandBox}, algorithm=""rsa-sha256"", headers=""(request-target) Date digest"", signature=""{File.ReadAllText("../../ING/Sandbox/example_client_signing.cer")}""")
request.AddParameter("grant_type=client_credentials&scope=greetings%3view", ParameterType.RequestBody)

'POST the request and retrieve the server response
Dim response As IRestResponse = client.Post(request)

'Printout the response
Debug.Print(response.ErrorMessage)
Debug.Print(response.StatusCode.ToString)
Debug.Print(response.Content)

当我使用它时,我得到一个错误返回:Specified value contains invalid CRLF characters。参数名称:值

最佳答案

试试这个替换

request.AddParameter("grant_type=client_credentials&scope=greetings%3view", ParameterType.RequestBody)

request.AddBody("grant_type=client_credentials&scope=greetings%3view", "application/x-www-form-urlencoded")

关于wpf - 如何将 RestClient 与 Oauth 2.0 和客户端 + TLS 证书一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57220165/

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