I am integrating DocuSign into my ASP.NET Core application but facing an issue with creating a JWT token using an RSA private key. How can I generate a valid JWT token with the RSA private key?
DocuSign integration in asp.net core
![10th Reply Posted Badge](https://uploads-us-west-2.insided.com/docusign-en/attachment/24651d4f-1ab3-4214-8ead-e45d5eb2e22a_thumb.png)
1. Generate RSA key pair as instructed in the article below.
https://developers.docusign.com/platform/configure-app/
2. Grant consent to your application as explained in the article below
https://www.docusign.com/blog/developers/oauth-jwt-granting-consent
3. You the Quickstart to download a personalised project with code examples.
https://developers.docusign.com/docs/esign-rest-api/quickstart/
Alternatively tou can use the SDK below
https://github.com/docusign/docusign-esign-csharp-client
JWTAuth Class
// <copyright file="JWTAuth.cs" company="DocuSign">
// Copyright (c) DocuSign. All rights reserved.
// </copyright>
namespace DocuSign.CodeExamples.Authentication
{
using System;
using System.Collections.Generic;
using DocuSign.CodeExamples.Common;
using DocuSign.eSign.Client;
using static DocuSign.eSign.Client.Auth.OAuth;
public static class JwtAuth
{
/// <summary>
/// Uses Json Web Token (JWT) Authentication Method to obtain the necessary information needed to make API calls.
/// </summary>
/// <returns>Auth token needed for API calls</returns>
public static OAuthToken AuthenticateWithJwt(string api, string clientId, string impersonatedUserId, string authServer, byte[] privateKeyBytes)
{
var docuSignClient = new DocuSignClient();
var apiType = Enum.Parse<ExamplesApiType>(api);
var scopes = new List<string>
{
"signature",
"impersonation",
};
if (apiType == ExamplesApiType.Rooms)
{
scopes.AddRange(new List<string>
{
"dtr.rooms.read",
"dtr.rooms.write",
"dtr.documents.read",
"dtr.documents.write",
"dtr.profile.read",
"dtr.profile.write",
"dtr.company.read",
"dtr.company.write",
"room_forms",
});
}
if (apiType == ExamplesApiType.Click)
{
scopes.AddRange(new List<string>
{
"click.manage",
"click.send",
});
}
if (apiType == ExamplesApiType.Monitor)
{
scopes.AddRange(new List<string>
{
"signature",
"impersonation",
});
}
if (apiType == ExamplesApiType.Admin)
{
scopes.AddRange(new List<string>
{
"user_read",
"user_write",
"account_read",
"organization_read",
"group_read",
"permission_read",
"identity_provider_read",
"domain_read",
"user_data_redact",
"asset_group_account_read",
"asset_group_account_clone_write",
"asset_group_account_clone_read",
});
}
if (apiType == ExamplesApiType.WebForms)
{
scopes.Add("webforms_read");
scopes.Add("webforms_instance_write");
scopes.Add("webforms_instance_read");
}
return docuSignClient.RequestJWTUserToken(
clientId,
impersonatedUserId,
authServer,
privateKeyBytes,
1,
scopes);
}
}
}
Example:
You can use the JWTAuth Class to generate the token as follows:
OAuthToken accessToken = JwtAuth.AuthenticateWithJwt("ESignature","INTEGRATION_KEY" ,
"USER_ID","account-d.docusign.com", BYTES_FROM_PrivateKeyFile");
- Use account-d.docusign.com for development environment and account.docusign.com for production environment.
- USER_ID is the userId who granted consent in step 2.
- INTEGRATION_KEY can be found (In Docusign eSignature Settings, select Apps and Keys)
Reply
Sign up
Already have an account? Login
You can login or register as either a Docusign customer or developer. If you don’t already have a Docusign customer or developer account, you can create one for free when registering.
Customer Login/Registration Developer Login/RegistrationDocusign Community
You can login or register as either a Docusign customer or developer. If you don’t already have a Docusign customer or developer account, you can create one for free when registering.
Customer Login/Registration Developer Login/RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.