Skip to main content
New Voice
Dec 22, 2024 6:16 PM UTC
Question

fix error AUTHORIZATION_INVALID_TOKEN

import axios from "axios";

import docusign from "docusign-esign";

import fs from "fs";

import path from "path";

 

const getAccessToken = async () => {

  const apiClient = new docusign.ApiClient();

  apiClient.setOAuthBasePath("account-d.docusign.com");

 

  const privateKey = fs.readFileSync(

    path.join(process.cwd(), process.env.NEXT_PUBLIC_SIGNUP_CLIENT_SECRET || "")

  );

  const response = await apiClient.requestJWTUserToken(

    process.env.NEXT_PUBLIC_SIGNUP_CLIENT_ID,

    process.env.NEXT_PUBLIC_SIGNUP_USER_ID,

    ["signature"],

    privateKey,

    3600

  );

 

  return response.body.access_token;

};

where i can find these issues? 
tried to use this, but have error AUTHORIZATION_INVALID_TOKEN

 

2 replies

Hengfeng Ge
Hero
Hero
Dec 23, 2024 10:37 AM UTC

the scopes should be impersonation signature for JWT.

 

FreeLink/甫连信息

🌍 Docusign Partner | Partner Profile

🏆 Docusign 2024 APAC Reseller Growth Partner of the Year

🌟 The only Docusign Partner globally certified as both a Certified eSignature Administrator and eSignature Technical Consultant.

📊 Docusign Community Leaderboard Top 5 contributor.

🚀 Expertise in Docusign integrations with on-premises systems for leading enterprises across various industries.

Translate
Welcome to the DocuSign Community! Your feedback is highly valued. If you find my response helpful, please give it a "Like" and consider marking it as the "Best Answer" to assist others with similar issues.
Docusign Employee
Dec 24, 2024 6:56 AM UTC

Regarding the AUTHORIZATION_INVALID_TOKEN error, it occurs when the invalid access token (expired or malformed) is used to call the eSignature REST API. Please refer to the below link for more information about this error: https://developers.docusign.com/docs/esign-rest-api/esign101/error-codes/troubleshooting-common-errors/#authorization-invalid-token

I've reviewed the code but I wonder whether you import the RSA private key in the below line of the code as it seems you import the client secret.

 const privateKey = fs.readFileSync(
 path.join(process.cwd(), process.env.NEXT_PUBLIC_SIGNUP_CLIENT_SECRET || "")
 );

If you don't import the RSA private key, please generate it on Docusign Portal > Admin > Apps and Keys > Actions > Edit > Generate RSA and then import it using the above code.

Translate