.NET Framework 4.8集成DocuSign JWT认证获取AccessToken报错
.NET Framework 4.8 Web应用集成DocuSign JWT授权获取Token问题
我正尝试在.NET Framework 4.8的Web应用中集成DocuSign,使用DocuSign eSign dll版本6.5.0。通过JWT授权方式获取Access Token,已在DocuSign开发者门户创建应用和集成密钥,并完成授权操作。
但获取Access Token时抛出ApiException异常,提示信息:
Error while requesting server, received a non successful HTTP code with response Body:
对应代码实现:
getAuthInfo(out string clientID, out string rsaPrivateKey, out string impersonatedUserID); var docuSignClient = new DocuSignClient(); var scopes = new List<string>{"signature","impersonation"}; var privateKeyBytes = Encoding.ASCII.GetBytes(rsaPrivateKey); try { var authToken = docuSignClient.RequestJWTUserToken( clientID, impersonatedUserID, "account-d.docusign.com", privateKeyBytes, 1, scopes); return authToken; } catch (ApiException apiExp) { // Consent for impersonation must be obtained to use JWT Grant if (apiExp.Message.Contains("consent_required")) { } }
更新内容1
安装了eSign dll版本6.2.0(与已验证可用的快速启动控制台版本一致),同时修改DocuSignClient的实例化方式,传入开发环境URL配置:
getAuthInfo(out string clientID, out string rsaPrivateKey, out string impersonatedUserID); var config = new DocuSign.eSign.Client.Configuration("https://demo.docusign.net/restapi"); var docuSignClient = new DocuSignClient(config); var scopes = new List<string>{"signature","impersonation"}; var privateKeyBytes = Encoding.ASCII.GetBytes(rsaPrivateKey); try { var authToken = docuSignClient.RequestJWTUserToken( clientID, impersonatedUserID, "account-d.docusign.com", privateKeyBytes, 1, scopes); return authToken; } catch (ApiException apiExp) { // Exception Message: "Error while requesting server, received a non successful HTTP code with response Body: " }
更新内容2
string directoryPath = Server.MapPath("~/App_Data/"); string fileName = "private.key"; var filePath = Path.Combine(directoryPath, fileName); var privateKeyBytes = File.ReadAllBytes(filePath); try { var accessToken = JWTAuth.AuthenticateWithJWT("ESignature", ConfigurationManager.AppSettings["ClientId"], ConfigurationManager.AppSettings["ImpersonatedUserID"], ConfigurationManager.AppSettings["AuthServer"], privateKeyBytes); } catch (DocuSign.eSign.Client.ApiException apiExp) { // Exception: Error code 500 }
此时抛出ApiException异常,错误码为500。
内容的提问来源于stack exchange,提问作者Pavel
相关产品推荐
相关产品推荐

