Current scope of the extension
This extension currently supports:
- DocuSign eSignature REST API. Other DocuSign APIs may be added later; check back soon.
- C# code examples. Other languages may be added later; check back soon.
- All SKUs of Visual Studio Code on Windows or Mac.
- OAuth for authentication into DocuSign.
Prerequisites to building a DocuSign integration
Installing this extension
To install the DocuSign Visual Studio Code Extension, simply double-click it; it will be installed automatically by launching Visual Studio Code. For more information, see Using extensions in Visual Studio Code in the Visual Studio Code documentation.
Configuring an existing project to use DocuSign
Open a command palette inside VS Code by going to View->Command Palette...
In the command palette, type DocuSign to find the extensions' command
Select the DocuSign: Configure Project command.
Note: This only works for C# projects. You will get the error message, "The workplace does not contain any C# projects" if you don't have any C# projects loaded.
In the Select OAuth authentication type for your application dialog box, select the authentication type you wish to use for the DocuSign eSignature API: either Authorization Code Grant or JSON Web Token (JWT). Note that if you use Authorization Code Grant, your app will need to include a link where users enter their credentials to authenticate to DocuSign. If you choose JWT, you can impersonate a single user to make all API calls, but you'll need the user ID that you wish to impersonate.
If you choose Authorization Code Grant, you'll need the integration key, redirect URI and secret key (also known as a client secret) to configure the authentication to DocuSign. See Building an eSignature Integration in the DocuSign Developer Center to learn more about how to set up a new DocuSign integration and to configure these settings.
If you choose JWT, use the next dialog box to add the two out of three configuration elements - integration key and DocuSign user ID - required to use JWT authentication. The RSA private key (part of the RSA key pair) has to be manually updated in the configuration file that will show up as soon as you're done. See JSON Web Token (JWT) Grant in the Developer Center to find out how to set up JWT authentication.
The DocuSign Visual Studio Code Extension configures your project, adds the necessary NuGet packages, and modifies your configuration file (appsettings.json) to include all the necessary configuration data to make DocuSign API calls.
Note: It is not recommended to deploy an application to your production environment with any secret, sensitive, or personal information in the configuration files. Instead, we recommend you use a secure vault, environment variables, or some other secure mechanism to ensure the privacy of your data.
At this point your project includes all the necessary files to integrate DocuSign functionality in your application. You will still need to modify your code to call the DocuSign code as follows:
If you chose Authorization Code Grant authentication, and ASP.NET Core Web Application, you will need to make the following code changes:
In startup.cs, in the ConfigureServices() method, you will need to add a call to:
DocuSign.eSignature.DocuSignWebAppExtensions.ConfigureDS(services, this.Configuration);
In startup.cs, in the Configure() method, you will need to add a call to:
DocuSign.eSignature.DocuSignWebAppExtensions.ConfigureDS(app);
In the controller class where you wish to invoke DocuSign functionality, add this private method:
protected bool CheckToken(int bufferMin = 60)
{
return HttpContext.User.Identity.IsAuthenticated
&& (DateTime.Now.Subtract(TimeSpan.FromMinutes(bufferMin)) <
RequestItemsService.User.ExpireIn.Value);
}
In the controller, add this code inside the method where you want to invoke DocuSign functionality:
string accessToken = RequestItemsService.User.AccessToken;
string basePath = RequestItemsService.Session.BasePath + "/restapi";
string accountId = RequestItemsService.Session.AccountId;
Once you have the accessToken, accountId, and basePath values, you can make calls to any of the code examples that you have added.
If you choose Authorization Code Grant and the ASP.NET Web Application (.NET Framework), you will need to make the following code changes:
Update your web.config file to include the following line:
<add key ="AppUrl" value ="{YourAppURL}"/>
making sure to replace {YourAppURL} with the URL where your app is running.
In FilterConfig.cs, in the RegisterGlobalFilters() method, add the following line:
filters.Add(new LocalsFilter(DSConfiguration.Instance, RequestItemsService.Instance));
In DSOwinStartup.cs, add the following line above the namespace declaration:
[assembly: OwinStartupAttribute(typeof(<YourNamespace>.DocuSign.eSignature.DSOwinStartup))]
making sure to replace <yourNamespace> with the namespace of your project.
In the controller class where you wish to invoke DocuSign functionality, add this code:
if (RequestItemsService.Instance.User == null)
return new DSChallengeResult();
string accessToken = RequestItemsService.Instance.User.AccessToken;
string basePath = RequestItemsService.Instance.Session.BasePath + "/restapi";
string accountId = RequestItemsService.Instance.Session.AccountId;
Once you have the accessToken, accountId, and basePath values, you can make calls to any of the code examples that you have added.
If you chose JWT Grant authentication, you need to add the following code to the location in your project where you wish to invoke DocuSign functionality:
var auth = DocuSign.eSignature.JWTAuth.AuthenticateWithJWT();
The auth object is a tuple that contains the accessToken, the accountId, and the basePath (in that order) that are required to make calls to any of the code examples that you have added.
Adding code examples to your project
Open a command palette inside VS Code by going to View->Command Palette...
In the command palette, type DocuSign to find the extensions' command.
Select the DocuSign: Add Code Examples command.
From the Select code example for your project screen, pick all the code examples you wish to add to your projects and click OK.
| |