/code-examples-csharp

Docusign C# code examples and launcher

Primary LanguageC#MIT LicenseMIT

C# Launcher Code Examples

PLEASE! Share your feedback in a two-question survey.

This GitHub repo includes code examples for the Web Forms API, Maestro API, Docusign Admin API, Click API, eSignature REST API, Monitor API, and Rooms API.

Introduction

This repo is a C# .NET Core MVC application that demonstrates:

  • Authentication with Docusign via Authorization Code Grant. When the token expires, the user is asked to re-authenticate. The refresh token is not used.

  • Authentication with Docusign via JSON Web Token (JWT) Grant. When the token expires, it updates automatically.

eSignature API

For more information about the scopes used for obtaining authorization to use the eSignature API, see Required scopes.

For a list of code examples that use the eSignature API, see the How-to guides overview on the Docusign Developer Center.

Rooms API

Note: To use the Rooms API, you must also create your Rooms developer account. Examples 4 and 6 require that you have the Docusign Forms feature enabled in your Rooms for Real Estate account. For more information about the scopes used for obtaining authorization to use the Rooms API, see Required scopes.

For a list of code examples that use the Rooms API, see the How-to guides overview on the Docusign Developer Center.

Click API

For more information about the scopes used for obtaining authorization to use the Click API, see Required scopes

For a list of code examples that use the Click API, see the How-to guides overview on the Docusign Developer Center.

Monitor API

Note: To use the Monitor API, you must also enable Docusign Monitor for your organization.

For information about the scopes used for obtaining authorization to use the Monitor API, see the scopes section.

For a list of code examples that use the Monitor API, see the How-to guides overview on the DocuSign Developer Center.

Admin API

Note: To use the Admin API, you must create an organization in your Docusign developer account. Also, to run the Docusign CLM code example, CLM must be enabled for your organization.

For information about the scopes used for obtaining authorization to use the Admin API, see the scopes section.

For a list of code examples that use the Admin API, see the How-to guides overview on the Docusign Developer Center.

Web Forms API

The Web Forms API is available in all developer accounts, but only in certain production account plans. Contact Docusign Support or your account manager to find out whether the Web Forms API is available for your production account plan.

For more information about the scopes used for obtaining authorization to use the Rooms API, see Required scopes.

For a list of code examples that use the Web Forms API, see the How-to guides overview on the Docusign Developer Center.

Installation

Prerequisites

Note: If you downloaded this code using Quickstart from the Docusign Developer Center, skip items 1 and 2 as they were automatically performed for you.

  1. A free Docusign developer account; create one if you don't already have one.

  2. A Docusign app and integration key that is configured to use either Authorization Code Grant or JWT Grant authentication.

    This video demonstrates how to obtain an integration key.

    To use Authorization Code Grant, you will need an integration key and a secret key. See Installation steps for details.

    To use JWT Grant, you will need an integration key, an RSA key pair, and the User ID GUID of the impersonated user. See Installation steps for JWT Grant authentication for details.

    For both authentication flows:

    If you use this launcher on your own workstation, the integration key must include a redirect URI of https://localhost:44333/ds/callback

    If you host this launcher on a remote web server, set your redirect URI as

    {base_url}/ds/callback

    where {base_url} is the URL for the web app.

  3. Microsoft .NET 8.0 or later.

  4. Visual Studio 2022 with ASP.NET package

Installation steps

Note: If you downloaded this code using Quickstart from the Docusign Developer Center, skip step 4 as it was automatically performed for you.

  1. Extract the Quickstart ZIP file or download or clone the code-examples-csharp repository.
  2. In File Explorer, open your Quickstart folder or your code-examples-csharp folder.
  3. Open the project with Visual Studio by double-clicking the launcher-csharp.sln file.
  4. To configure the launcher for Authorization Code Grant authentication, create a copy of the file launcher-csharp/appsettings.example.json and save the copy as launcher-csharp/appsettings.json.
    1. Add your integration key. On the Apps and Keys page, under Apps and Integration Keys, choose the app to use, then select Actions > Edit. Under General Info, copy the Integration Key GUID and save it in appsettings.json as your ClientId.
    2. Generate a secret key, if you don’t already have one. Under Authentication, select + ADD SECRET KEY. Copy the secret key and save it in appsettings.json as your ClientSecret.
    3. Add the launcher’s redirect URI. Under Additional settings, select + ADD URI, and set a redirect URI of https://localhost:44333/ds/callback. Select SAVE.
    4. Set a name and email address for the signer. In appsettings.json, save an email address as SignerEmail and a name as SignerName.
  5. Run the launcher with Visual Studio: Select the green Play IIS Express button.

Installation steps for JWT Grant authentication

Note: If you downloaded this code using Quickstart from the Docusign Developer Center, skip step 4 as it was automatically performed for you. Also, in order to select JSON Web Token authentication in the launcher, in launcher-csharp/appsettings.json, change the quickstart setting to "false".

  1. Extract the Quickstart ZIP file or download or clone the code-examples-csharp repository.
  2. In File Explorer, open your Quickstart folder or your code-examples-powershell folder.
  3. Open the launcher-csharp.sln solution file using Visual Studio.
  4. To configure the launcher for JWT Grant authentication, create a copy of the file launcher-csharp/appsettings.example.json and save the copy as launcher-csharp/appsettings.json.
    1. Add your User ID. On the Apps and Keys page, under My Account Information, copy the User ID GUID and save it in appsettings.json as your ImpersonatedUserId.
    2. Add your integration key. On the Apps and Keys page, under Apps and Integration Keys, choose the app to use, then select Actions > Edit. Under General Info, copy the Integration Key GUID and save it in appsettings.json as your ClientId.
    3. Generate an RSA key pair, if you don’t already have one. Under Authentication, select + GENERATE RSA. Copy the private key, and save it in a new file launcher-csharp/private.key.
    4. Add the launcher’s redirect URI. Under Additional settings, select + ADD URI, and set a redirect URI of https://localhost:44333/ds/callback. Select SAVE.
    5. Set a name and email address for the signer. In appsettings.json, save an email address as SignerEmail and a name as SignerName. Note: Protect your personal information. Please make sure that appsettings.json will not be stored in your source code repository.
  5. Run the launcher with Visual Studio: Select the green Play IIS Express button.
  6. On the black navigation bar, select Login.
  7. From the picklist, select JWT (JSON Web Token) > Authenticate with Docusign.
  8. When prompted, log in to your Docusign developer account. If this is your first time using the app, select ACCEPT at the consent window.
  9. Select your desired code example.

Authorization Code Grant embedded signing example:

  1. Double click the Quick_ACG.csproj file in the Quick_ACG folder of your Quickstart project.
  2. Select the green Play IIS Express button.

JWT grant remote signing project

  1. Double click the JWT-Console.csproj file in the JWT-Console folder of your Quickstart project.
  2. Select the green Play JWT Console button.

Payments code example

To use the payments code example, create a test payment gateway on the Payments page in your developer account. See Configure a payment gateway for details.

Once you've created a payment gateway, save the Gateway Account ID GUID to appsettings.json.

License and additional information

License

This repository uses the MIT License. See LICENSE for details.

Pull Requests

Pull requests are welcomed. Pull requests will only be considered if their content uses the MIT License.