SDK Authentication

The SDK manages API tokens for you. Provide credentials once during initialization; the SDK requests and attaches the bearer token to all calls. It also refreshes the token when needed.

Configure

import { IdCanopy } from "idcanopy-sdk";

const canopy = new IdCanopy({
  apiKey: process.env.IDCANOPY_API_KEY!,
  customerId: process.env.IDCANOPY_CUSTOMER_ID!,
  environment: "sandbox" // or "production"
});

// Optional: prefetch on startup
await canopy.auth.getToken();

Manual control (optional)

// Provide an existing token if you manage it externally
canopy.auth.setToken({ accessToken: "…", expiresIn: 3600 });

// Read current token
const tok = canopy.auth.getCurrent();

Under the hood, the SDK calls the same /auth endpoint documented in API Authentication and caches the token until it expires.