Skip to main content

Overview

This tutorial shows you how to authenticate to the Issuing API using Node.js by generating signed JSON Web Tokens (JWTs).

In This Recipe

  1. Install Dependencies
  2. Create signJWT function
  3. Usage - GET Request
  4. Usage - POST Request

Prerequisites

  • Node.js 16 or higher
  • Your Issuing API credentials (Access Key and RSA key pair)

Step 1: Install Dependencies

Install the required npm packages:

Step 2: Create signJWT Function

Create a utility function to handle JWT signing with SHA256 body hashing:

Important Notes:

  • Request body is hashed with SHA256 before signing
  • 30 second expiration for security
  • Private key format: PEM-encoded RSA private key
  • Empty body: Use empty string "" for GET requests

Step 3: Usage - GET Request

Make a simple GET request to test connectivity:

Step 4: Usage - POST Request

Make a POST request with a request body:

Using with Axios

If you prefer using Axios instead of fetch:

TypeScript Version

For TypeScript projects:

Common Pitfalls

Body Hashing is Critical! The signJWT function automatically hashes the request body with SHA256 before including it in the JWT claims. Make sure you pass the exact same request body to both signJWT() and your HTTP request.
Token Expiration: JWT tokens expire after 30 seconds. Generate a fresh token for each API request to avoid authentication errors.
JSON Stringify Consistency: When sending JSON bodies, use JSON.stringify() consistently. The exact string representation must match between signing and sending.

Next Steps