Search code examples
docusignapi

Docusign migration from Legacy to OAuth 2.0 Authentication


I have been researching back and forth also talking to Docusign support but nobody can help me. We area still using the legacy authentication.

We need help how to switch to the new OAuth authentication. We are using Visual Studio 2015 Community, .NetFramework 4.5 and Docusign.dll SDK Version 4.0.4. I understand that our system is too old and have not catch up to the new versions. Take Note: We are not using Console program, not using a Project but we are using a Web Based Application c#. I just installed the new Visual Studio 2022, installed the Docusign SDK version 4.5.2 from the Nuget package manager, and upgraded to .NET framework 4.5.2. Again just a reminder, we are not using Visual Studio Core. We are not using Console program or any project. We are in a website development where a user pushes a button, that creates a pdf file manually, and sends the pdf file to Docusign for our customers to sign and date.

This is the Legacy Authentication that we have:

            if (!Configuration.Default.DefaultHeader.ContainsKey("X-DocuSign-Authentication"))
            {
                string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
                Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
            }

I tried to download the JWT-console program from Docusign and it works. But when I transferred just using the initial code below, we have some errors:

    OAuthToken accessToken = null;
    try
    {
        accessToken = JWTAuth.AuthenticateWithJWT("ESignature", ConfigurationManager.AppSettings["ClientId"], ConfigurationManager.AppSettings["ImpersonatedUserId"],
                                                    ConfigurationManager.AppSettings["AuthServer"], DSHelper.ReadFileContent(ConfigurationManager.AppSettings["PrivateKeyFile"]));

    }

1st error:

enter image description here

and a bunch of errors:

enter image description here

Please help how can we migrate the Legacy Authentication to our webpage using Visual Studio.

Thank you

I already called and emailed tech support, until now no answers.


Solution

  • Finally got an answer from a Docusign Tech support and he was able to help me replacing my code to the new one below. We will remain to use VS 2015 and Docusign Ver. 4.0.4 below. We can't make upgrades yet but we will in the near future.

            string basePath = "";
            if (bDebug)
            {
                basePath = "https://demo.docusign.net/restapi";
            }
            else
            {
                basePath = "https://www.docusign.net/restapi";
            }
    
            var apiClient = new ApiClient(basePath);
            string privateKey = "-----BEGIN RSA PRIVATE KEY-----XXXXX-----END RSA PRIVATE KEY-----\r\n";
            OAuth.OAuthToken authToken = apiClient.RequestJWTUserToken("integrator key goes here", "user id goes here", "account-d.docusign.com", Encoding.ASCII.GetBytes(privateKey), 600, new List<string> { "signature", "impersonation" });
            var token = authToken.access_token;            
    
            Configuration.Default.AddDefaultHeader("Authentication", token);
            Configuration.Default.ApiClient = apiClient;