Authentication

Get OAuth 2.0 tokens with your API and SDK client credentials, in sandbox and production: the token call, its 5-minute lifetime, SDK scopes, and keeping secrets off the browser.

For: developers

OAuth 2.0 client credentials. Your server sends its client ID and secret to the token endpoint and gets back a short-lived access token; when it expires, the server asks for a new one. OAuth 2.0 client credentials. Your server exchanges a client ID and secret for a short-lived access token. YOUR SERVER client_id client_secret /token access token short-lived OAuth 2.0 client credentials. Your server sends its client ID and secret to the token endpoint and gets back a short-lived access token; when it expires, the server asks for a new one. OAuth 2.0 client credentials. Your server exchanges a client ID and secret for a short-lived access token. YOUR SERVER client_id client_secret /token access token short-lived

Astrada uses OAuth 2.0 client credentials. Each client is a client_id and client_secret pair that your server exchanges for a short-lived access token.

Sandbox: signing up at astrada.co/sandbox gives you one client ID and secret, shown once on the sign-up page. That client holds every sandbox scope, so the one client works for both the API and the SDK.

Production: Astrada gives you two separate sets of client credentials during onboarding, through 1Password, each scoped for a specific purpose:

Credential SetPurposeUsed By
API CredentialsBackend API operations (subaccounts, webhooks, transactions, cards)Your server
SDK CredentialsEnrollment in the browser with SDK v2 (and the earlier SDKs)Your server + the SDK in the browser

API Credentials

API credentials authorize your backend server to call Astrada's REST API. Use these for all server-to-server operations: managing subaccounts, registering webhooks, retrieving transactions, and more. In production they carry the scopes Astrada sets up for your account. The backend SDKs take these credentials and get and renew the token for you.

Obtaining an Access Token

Exchange your client_id and client_secret for a Bearer token using the OAuth 2.0 client credentials flow, on the host for your environment:

EnvironmentHost
Sandboxhttps://api.sandbox.astrada.co
Productionhttps://api.astrada.co
curl -X POST \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET" \
  -d "grant_type=client_credentials" \
  "$HOST/auth/realms/{ACCOUNT_ID}/protocol/openid-connect/token"

Set HOST to the host above, and replace {ACCOUNT_ID} with your Astrada account ID: shown at sandbox sign-up, and provided during onboarding for production.

Response:

{
  "access_token": "eyJhbGciOiJSUzI1NiIs...",
  "expires_in": 300,
  "token_type": "Bearer"
}

Using the Token

Include the access token as a Bearer token in the Authorization header of all API requests, on the same host:

curl -X GET "$HOST/transactions" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Token Lifecycle

  • Tokens expire after 5 minutes (expires_in: 300).
  • Request a new token when the current one expires. There is no refresh token flow.
  • For your own API calls, cache the token on your backend and reuse it until it expires, rather than requesting one per call. The route that gives tokens to an SDK works differently: see Providing the Token to the SDK.
  • Tokens are stateless JWTs validated on each request.

SDK Credentials

In production, SDK credentials authorize SDK v2 (and the earlier Card Enrollment SDK and Unified Enrollment SDK v1) to perform enrollment operations in the browser. These are a separate client_id / client_secret pair whose scopes cover only the calls the SDK makes. Besides enrolling and verifying cards, every SDK reads the subaccount and asks how a card can enroll, and the Unified Enrollment SDK (v1 and v2) also links banks and sends bulk enrollment requests. In sandbox, your one client already holds these scopes. Unified Enrollment SDK v2 makes these calls with the SDK token:

CallScopeWhen
GET /subaccounts/{subaccountId}subaccounts:readOpening a session
POST /enrollment-methodsenrollment-methods:writeEvery card number
GET /bin-lookupcards:readEvery card number; optional, the SDK routes the card without it
POST /card-subscriptions, GET /card-subscriptions/{subscriptionId}card-subscriptions:write, card-subscriptions:readThe card form; the read when the card is already enrolled
POST /card-verifications/3ds and its steps, GET /card-verifications/3ds/{verificationId}card-verifications:write, card-verifications:read3DS verification
POST /bank-links, GET /bank-links/{bankLinkId}, GET /bank-accountsbanking:write, banking:readBank linking
POST /bank-accounts/{bankAccountId}/refreshbanking:writeReconnecting a bank account
POST /network-bulk-enrollments, GET /network-bulk-enrollments/open, POST /network-bulk-confirmationsnetwork-bulk-enrollments:write or network-bulk-feeds:writeBulk enrollment requests on admin pages
POST /subaccounts/{subaccountId}/team-linkcard-subscriptions:writeInvite your team, when enrollment links are on for your account

The SDK token belongs to your account, not to one subaccount: within your account it can create, read and deactivate card subscriptions on any subaccount, and, when your SDK client holds the banking scopes, list every bank link and bank account and start a bank link on any subaccount. Check on your server that the user may use the subaccountId you open the SDK with. To have Astrada hold a session to one subaccount, use enrollment links.

How SDK Authentication Works

The client credentials should never be exposed in browser code. Instead:

  1. Your backendAstradaExchanges the SDK client_id and client_secret for an access token, at the same token endpoint as above.
  2. Your backendYour frontendReturns the access token to the frontend.
  3. The SDKAstradaGets the token from your getAccessToken callback and uses it to authenticate the enrollment requests.

Providing the Token to the SDK

Pass an async function as getAccessToken when you open the SDK. It calls your backend, which mints the token with the SDK credentials and returns it as plain text, with no Bearer in front; the function resolves to that string. With Unified Enrollment SDK v2:

UnifiedEnrollmentSdk.open({
  subaccountId: "67bc3887-4e25-49cf-bea7-326d808acb5f",
  companyName: "Your Company",
  getAccessToken: async () => {
    const response = await fetch("/your-backend/astrada-sdk-token");
    if (!response.ok) throw new Error("the token route answered " + response.status);
    return response.text();
  },
  persona: "admin", // "cardholder" on employee pages
  onSuccess: (result) => console.log(result.summary),
});

SDK v2 calls getAccessToken:

  • Before its first request to Astrada.
  • Before a later request, once the token it holds has expired.
  • Once more when Astrada answers a request with 401. A second 401 is not retried.

The SDK passes no arguments to getAccessToken, so your token route cannot tell the ask after a 401 from the other two. Have the route mint a new token each time it is called; the SDK already reuses the token it holds until that token expires. A route that returns a cached token hands back the token Astrada just refused, and the one retry fails the same way.

The function must resolve within 5 seconds, or within the getAccessTokenTimeoutMs you set. If it takes longer, the request that needed the token fails. When that happens the first time a tab opens the SDK, the screen reads "We couldn't get started", with a "Try again" button.

SDK v2 screen "We couldn't get started": Something went wrong getting this page ready. Try again, and if it keeps happening, contact Lumen Freight. A Try again button.

What the person sees when getAccessToken does not answer in time on the first open. The same screen serves all five start codes.

SDK v2: Quick Start runs this call in sandbox on your own page, and Options lists what open() takes. For how the legacy Card Enrollment SDK and SDK v1 take the token, see Installation and Unified Enrollment SDK v1.

Keeping Credentials Safe

Never expose any client_id or client_secret in frontend/browser code. Exchange them for tokens on your backend; only the resulting access token goes to the browser (for the SDK) or into API calls.

  • Least privilege: in production, use SDK credentials for enrollment operations and API credentials for backend operations. Do not use API credentials where SDK credentials suffice.
  • Credential storage: store credentials securely in your backend environment (for example, environment variables or a secrets manager). Never commit credentials to source control.

Next Steps


Did this page help you?