Skip to main content
Question

JWT Authentication returning error while matching code examples

  • 30 May 2024
  • 4 replies
  • 184 views

I’ve downloaded the DocuSign NuGet package, and also the code examples provided by DocuSign through the quick start for comparing.

I have matched my code to the code examples downloaded within my own project. Confirmed my UserId/ImpersonationId, IntegrationKey/ClientId match from what the code examples use to what my login “Apps & Keys” have.

After attempting to call the “AuthenticateWithJwt(string api, string clientId, string impersonatedUserId, string authServer, bytee] privateKeyBytes)” I get an ApiException of “Error while requesting server, received a non successful HTTP code with response Body: ”

I’ve followed through the documentation on https://developers.docusign.com/platform/auth/jwt/jwt-get-token/
 

When using POSTMAN I’m able to get an access token. However, so far I’ve been unsuccessful in getting the DocuSign NuGet package code to work. I’ve tried searching around the forums for any reference to the error response I’m getting with no success.

Any help in pointing me in the right direction would be much appreciated.

What about RSA keypair, did you create one? do you have the private key file copy/pasted exactly the same into your C# project?


The example project from DocuSign has this:

accessToken = JwtAuth.AuthenticateWithJwt("ESignature", ConfigurationManager.AppSettings["ClientId"], ConfigurationManager.AppSettings["ImpersonatedUserId"],
ConfigurationManager.AppSettings["AuthServer"], DsHelper.ReadFileContent(ConfigurationManager.AppSettings["PrivateKeyFile"]));

The read file definition:

internal static byte[] ReadFileContent(string path)
{
return File.ReadAllBytes(path);
}


with the config file of entry of:

<add key="PrivateKeyFile" value="../../../private.key"/>

Within my project

byte[] l_PrivateKeyBytes = DocuSignV2.GetPrivateKeyBytes();
public static byte[] GetPrivateKeyBytes()
{
return System.IO.File.ReadAllBytes(ConfigurationManager.AppSettings["DocuSignPrivateKeyFile"]);
}

I use “l_PrivateKeyBytes” as the variable passed on “AuthenticateWithJwt”

The contents of this file is just the RSA Private Key provided within the Apps & Keys > Edit > Generate RSA

-----BEGIN RSA PRIVATE KEY-----
M…....l
-----END RSA PRIVATE KEY-----


Hello Daman,

You can check the walkthrough to set up authentication with JWT Below:
https://developers.docusign.com/docs/esign-rest-api/sdks/csharp/auth/

In case you still experience issues, you may need to capture error logs and open a ticket for the support team for further investigation.

 

Thanks,


Issue was solved. This issue ended up being a security protocol setting.

TLS 1.2+ was needed to be set.


Reply