DocuSign C# SDK 无 API 响应

huangapple go评论67阅读模式
英文:

DocuSign C# SDK No API Response

问题

尝试使用JWT授权设置ASP.NET Core Web应用程序以使用DocuSign SDK。当尝试调用任何Envelope API时,它从不返回数据并且被挂起。

var _apiClient = new DocuSignClient("https://demo.docusign.net/restapi");

var privateKeyBytes = GetPrivateKeyBytes();
var authToken = _apiClient.RequestJWTUserToken("integration_key", "user_id", "account-d.docusign.com", privateKeyBytes: privateKeyBytes, 1, new List<string> { "impersonation", "signature" });

// authToken对象正确返回access_token,调用_apiClient.GetUserInfo(authToken.access_token)也将返回有效的对象。

var envelopesAPI = new EnvelopesApi(_apiClient);
// 永远无法通过这一行,一直加载。
Envelope env = envelopesAPI.GetEnvelope("api_account_id", "envelope_id");

我已经检查了我的DocuSign API仪表板,可以看到这些请求已经完成(状态码200),但仍然无法收到对象并且无法继续执行该行,也没有抛出错误。我尝试让它运行一段时间,看是否最终会抛出错误,但似乎没有抛出错误。

成功的请求

如果使用代码生成的access_token通过Postman发送请求,我还会得到成功的JSON响应。

任何帮助都将不胜感激,谢谢。

英文:

Trying to setup a ASP.NET Core web application with DocuSign SDK using JWT Authorization. When trying to call any Envelope API it never returns data and gets hung up.

var _apiClient = new DocuSignClient(&quot;https://demo.docusign.net/restapi&quot;);

var privateKeyBytes = GetPrivateKeyBytes();
var authToken = _apiClient.RequestJWTUserToken(&quot;integration_key&quot;, &quot;user_id&quot;, &quot;account-d.docusign.com&quot;, privateKeyBytes: privateKeyBytes, 1, new List&lt;string&gt; { &quot;impersonation&quot;, &quot;signature&quot; });

// authToken object returns correctly with access_token, calling _apiClient.GetUserInfo(authToken.access_token) will return a valid object as well.

var envelopesAPI = new EnvelopesApi(_apiClient);
// never gets past this line, constantly loads.
Envelope env = envelopesAPI.GetEnvelope(&quot;api_account_id&quot;, &quot;envelope_id&quot;);

I've checked my DocuSign API Dashboard and can see these requests are being completed (200) but still not receiving an object and unable to get past that line, no error is being thrown either I've tried letting it run for a bit to see if it would eventually throw one but I didn't seem to get one.

Successful request

I also get a successful JSON response if sending the request through postman using access_token generated by code.

Any help is appreciated, thanks.

答案1

得分: 0

要使用JWT,您需要确保您已经获得了授权同意。如果您传递给它的信息不正确,获取访问令牌的调用将失败。例如,您在其中使用的"user_id"必须是系统中与您在授权时用于登录的帐户相对应的用户的有效GUID(而非帐户)。

如果您获得了有效的访问令牌,那么您需要添加以下代码:

string access_token = authToken.access_token;
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
英文:

To use JWT, you need to make sure that you have consent. The call to get an access token will fail if the information you pass to it is incorrect. For example, the "user_id" that you have in there must be a valid GUID of a user (not account!) in the system that corresponds to the account you used to log in when you gave consent.

If you do get a valid access token, then you have to add this code:

string access_token = authToken.access_token;
apiClient.Configuration.DefaultHeader.Add(&quot;Authorization&quot;, &quot;Bearer &quot; + accessToken);

答案2

得分: 0

我已修复。我需要添加授权标头。

_apiClient.Configuration.DefaultHeader["Authorization"] = "Bearer " + access_token;
英文:

I fixed it. I needed to add in the Authorization Header.

_apiClient.Configuration.DefaultHeader[&quot;Authorization&quot;] = &quot;Bearer &quot; + access_token;

huangapple
  • 本文由 发表于 2023年3月10日 01:48:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75688288.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定