skip to Main Content

I am trying to integrate DocuSign in my web application (.net framework 4.8). I’m using DocuSign eSign dll version 6.5.0.

I am trying to get an access token using JWT auth grant. I created an App and Integration Key in the DocuSign developer portal, and have granted consent.

However, when I attempt to get an Access token, it throws an ApiException with message:
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"))
        {
            
        }
    }

*** Update: ***

Installed eSign dll version 6.2.0 to match the same version as the Quick Start Console version which I confirmed works.

Also, changed the DocuSignClient instnatiation to pass a config with dev 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: "
    }

*** Update 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
    }

3

Answers


  1. Chosen as BEST ANSWER

    I figured out the issue. Not sure what version of TLS the eSign dll uses, but explicitly setting the SecurityProtocol to use Tls12 fixed my issue.

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    
    var authToken = docuSignClient.RequestJWTUserToken(
                                    clientID,
                                    impersonatedUserID,
                                    url,
                                    privateKeyBytes,
                                    1,
                                    scopes); 
    

  2. Save the RSA private key into a text file called private.key

    Then do this :

    byte[] privateKeyBytes = File.ReadAllBytes("private.key");
    var authToken = docuSignClient.RequestJWTUserToken(
                                clientID,
                                impersonatedUserID,
                                "account-d.docusign.com",
                                privateKeyBytes,
                                1,
                                scopes);
                                
    
    Login or Signup to reply.
  3. Looking at the src code it appears that the sdk oauth server default is now production.

    Fix is to explicitly create a "configuration" object with the demo oauth url for your DocuSignClient constructor

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search