Wpf 如何将RestClient与Oauth 2.0和客户端+;TLS证书?

Wpf 如何将RestClient与Oauth 2.0和客户端+;TLS证书?,wpf,vb.net,ssl,oauth-2.0,restsharp,Wpf,Vb.net,Ssl,Oauth 2.0,Restsharp,我是OAuth2.0和所有证书内容的新手,所以请饶了我;-) 今天我尝试与银行的RESTAPI接口。它们提供了一个很好的解释,在这里可以找到,但是这些都是为web开发编写的(我认为),所有OAuth的东西对我来说都有些新。我已经创建了一个新的测试应用程序,它应该连接到银行的沙箱环境。然而,我不清楚把证书放在哪里。我有四个档案;客户端证书+密钥和TLS证书+密钥。除此之外,我已经注册了我的申请,并收到了一个ClientID。但是,在使用沙盒环境进行测试时,它们提供了一个ClientID供公共使用(

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

今天我尝试与银行的RESTAPI接口。它们提供了一个很好的解释,在这里可以找到,但是这些都是为web开发编写的(我认为),所有OAuth的东西对我来说都有些新。我已经创建了一个新的测试应用程序,它应该连接到银行的沙箱环境。然而,我不清楚把证书放在哪里。我有四个档案;客户端证书+密钥和TLS证书+密钥。除此之外,我已经注册了我的申请,并收到了一个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)

当我使用此命令时,返回一个错误:
指定的值包含无效的CRLF字符。参数名称:value

我不是OAuth方面的专家,但是没有详细说明,您是否放弃了最愚蠢的理由?比如复制/粘贴具有CRLF字符的代码,等等?也许你可以用一个简单的工具,比如记事本++来快速查看所有的东西,它启用了“显示所有字符”选项。谢谢你的simpel,但是很容易出错。我检查了很多次,一切都正常。gues我缺少一些必须对包进行签名的内容或其他内容……您是否尝试过使用文件名和File.ReadAllText获取您正在加载的数据,然后直接将其粘贴到应用程序中,看看是否有效,并排除文件中可能存在尾随换行符的可能性?是的,不起作用。我发现我需要用SHA256和base64签署请求,但这对我来说有点新鲜,在谷歌上搜索RestClient的例子,我发现可能还没有人这么做,因为它是一个高级别的Oauth