Installation

Load the legacy Card Enrollment SDK, launch it with openForm, add its TypeScript types, and have your backend fetch the SDK access token.

For: developers

📘

Legacy Card Enrollment SDK

This page is for pages already on the legacy Card Enrollment SDK. A new integration starts on the Unified Enrollment SDK v2: SDK v2: Quick Start.

Integration

To integrate the legacy Card Enrollment SDK into your web application, follow these steps:

1. Loading the JS file

Begin by loading the JavaScript file provided by us. You can find it at the following URL:

<script
  type="text/javascript"
  src="https://sdk.astrada.co/v1/cardEnrollmentSdk.js"
  data-id="card-enrollment-sdk"
></script>

2. Launching the SDK

Once you have added the script to your website, it will register a global variable named CardEnrollmentSdk. This variable provides the following methods:

  • CardEnrollmentSdk.openForm(config): launches the Card Enrollment SDK, used for enrolling cards, and initiates the verification process of the card.
  • CardEnrollmentSdk.closeForm(): closes the Card Enrollment SDK.
  • CardEnrollmentSdk.setStyle(style): applies your brand theme to the SDK (see Visual Customization).

Call openForm from a script inside <body>, or once the page has loaded: the SDK attaches to document.body, so a call that runs in <head> opens nothing and logs a TypeError.

See Configuration to learn about the different configurations supported when calling the openForm method, and Events & Callbacks for what it reports back.

TypeScript types

Astrada publishes official TypeScript types for the SDK, @astrada.co/card-enrollment-sdk. The package contains type declarations only, with no runtime code, so install it as a dev dependency; it adds nothing to your bundle, and the SDK still loads from the hosted script above. Importing it also declares the CardEnrollmentSdk global, so you don't hand-write a .d.ts:

npm install --save-dev @astrada.co/card-enrollment-sdk@^1
import type {
  CardEnrollmentSdkConfig,
  EnrollmentSuccess, // the onSuccess payload
  OnErrorPayload,    // the onError payload
  SdkStyle,          // the setStyle argument
} from "@astrada.co/card-enrollment-sdk";

The types are generated from the SDK source and checked against it in CI, so they match what the runtime sends.

Authentication

The Card Enrollment SDK uses a separate set of credentials from the main API. During onboarding, you'll receive dedicated SDK credentials (client_id + client_secret) scoped specifically for card enrollment operations.

The getAccessToken passed to the openForm must be an asynchronous function responsible for returning an Access Token (JWT). Your backend should use the SDK credentials to obtain this token from Astrada's OAuth endpoint, then return it to the frontend. This function must resolve within the configured timeout, 5 seconds by default. If your token exchange is slower, raise the limit with the getAccessTokenTimeoutMs option (in milliseconds). Otherwise, it will timeout and return an error, resulting in a failed enrollment.

The Access Token is fetched at two different points in time:

  1. When the SDK is launched.
  2. When the Access Token being used expires.
📘

See the Authentication Guide for full details on credential types, the token exchange flow, and security best practices.

🚧

Never use any client_id or client_secret directly in browser code. Your backend must exchange the SDK credentials for a token and pass only the resulting JWT to the frontend via getAccessToken.

Troubleshooting

Having issues integrating with the SDK? See our Troubleshooting Guide.


Did this page help you?