Docs

Service-auth cookbook

Concrete service-auth recipes for app calls, payer assertions, XRPC receivers, ticket holds and replay protection.

Closed beta@atmosphere-money/app-nodeSDK beta: 0.0.0-beta.3ATM API beta: 2026-0671 published lexicons

Compatible with the closed-beta ATM app APIs and versioned ATM event headers. Check atm-api-version on every webhook or XRPC receiver event.

Which token to use

ATM uses short-lived service-auth in two directions. Your app proves its own DID when it calls ATM. Your app may also include a user assertion when it acts for a buyer or organizer who is already signed in to your app.

App calls ATMApp service-auth: iss is your app DID, lxm is the exact ATM method, and aud is your broker’s #atmosphere_money_broker service.
Buyer present in your appInclude payerDid with payerAssertionJwt in createCheckout, or buyerDid with buyerAssertionJwt in a ticket request.
Organizer configures ticketsInclude organizerAssertionJwt when your app creates or changes ticket types for an organizer.
ATM calls your XRPC receiverATM sends service-auth to your app; your app verifies ATM as the caller.
HTTP webhookRaw-body HMAC signature verification, not service-auth.

App service-auth

App service-auth protects app attribution, environment access, notification routing, module permissions and app-visible payments. Never trust an app DID supplied only as a URL parameter. Your app account's PDS signs each token through com.atproto.server.getServiceAuth and sets the issuer, key ID and a unique jti.

ts
import { AtpAgent } from "@atproto/api";

// Your app account's authenticated agent (an OAuth session or app password).
declare const appAgent: AtpAgent;

// Mint a NEW token for every call, including retries.
export async function mintMyAppServiceAuthJwt(
  { lxm, aud }: { lxm: string; aud: string },
): Promise<string> {
  const exp = Math.floor(Date.now() / 1000) + 60; // ATM allows at most 300 seconds
  const { data } = await appAgent.com.atproto.server.getServiceAuth({ aud, lxm, exp });
  return data.token;
}
FieldTypeRequiredDescription
issdidyesYour registered app DID.
auddid#serviceyesYour assigned broker DID plus #atmosphere_money_broker. Bare DIDs and other service fragments are rejected.
lxmnsidyesThe exact XRPC method being called.
expintegeryes60 seconds after issue is recommended; ATM rejects more than 300.
jtistringyesUnique per token. ATM rejects a token it has already seen.

Payer assertion

A payer assertion is a low-friction proof that your app saw the signed-in buyer for this purchase. The buyer's PDS signs it through their session with your app. It is not an OAuth grant and never lets ATM write to the buyer's repo.

ts
import { AtpAgent } from "@atproto/api";
import type { AtmCreateCheckoutInput } from "@atmosphere-money/app-node";

export async function withPayerAssertion(
  buyerAgent: AtpAgent, // the signed-in buyer's session with your app
  buyerDid: string,
  request: AtmCreateCheckoutInput,
): Promise<AtmCreateCheckoutInput> {
  const { data } = await buyerAgent.com.atproto.server.getServiceAuth({
    aud: "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb#atmosphere_money_broker",
    lxm: "money.atmosphere.payment.assertPayer",
    exp: Math.floor(Date.now() / 1000) + 60,
  });
  // Add the pair BEFORE capture. It is then frozen with the original request.
  return { ...request, payerDid: buyerDid, payerAssertionJwt: data.token };
}

Organizer assertion

Ticketing apps may need to prove that an organizer authorized a ticket event, ticket type, sale window, per-order limit or capacity change inside the app. Those changes mutate shared organizer-owned ATM ticket config, so scope the assertion to the exact ticket method being called.

ts
import { AtpAgent } from "@atproto/api";

export async function organizerAssertionFor(
  organizerAgent: AtpAgent, // the signed-in organizer's session with your app
  lxm: string, // for example "tickets.atmosphere.createTicketEvent"
): Promise<string> {
  const { data } = await organizerAgent.com.atproto.server.getServiceAuth({
    // The same #atmosphere_money_broker audience as every ATM call; lxm scopes it.
    aud: "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb#atmosphere_money_broker",
    lxm,
    exp: Math.floor(Date.now() / 1000) + 60,
  });
  return data.token;
}

ATM receiver callback

AT Protocol apps receive notifications through the canonical XRPC receiver by default. Verify ATM's service-auth, claim the delivery and queue reconciliation; the worker reads canonical status before granting anything.

Your assigned test broker signs each receiver call. Pass its DID as expectedIssuerDid: it's the test broker DID in your test configuration, the same value you give createAtmCheckoutAttempts as brokerDid. Without it, the helper expects ATM's production broker and rejects your test notifications.

ts
import { constructAtmXrpcReceiverEvent } from "@atmosphere-money/app-node";

// Your JWT verifier (for example @atproto/xrpc-server). The helper then enforces
// iss = your assigned broker DID, your #AtmEventReceiver audience and the exact method.
declare const verifyServiceAuthJwt: Parameters<
  typeof constructAtmXrpcReceiverEvent
>[0]["verifyServiceAuthJwt"];

export async function receiveAtmEvent(request: Request) {
  const event = await constructAtmXrpcReceiverEvent({
    appDid: "did:plc:aaaaaaaaaaaaaaaaaaaaaaaa",
    // The test broker DID from your test configuration: the same brokerDid you
    // give createAtmCheckoutAttempts. Without it, the SDK expects ATM's production broker.
    expectedIssuerDid: "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb",
    rawBody: await request.text(),
    headers: {
      authorization: request.headers.get("authorization"),
      deliveryId: request.headers.get("atm-delivery-id"),
    },
    verifyServiceAuthJwt,
  });
  if (event.environment !== "test" || event.apiVersion !== "2026-07")
    return Response.json({ error: "UnexpectedEventBinding" }, { status: 422 });

  const claim = await claimWebhookDelivery(event.id);
  if (claim.status === "completed") {
    return Response.json({ ok: true, duplicate: true });
  }
  if (claim.status === "busy") {
    return Response.json(
      { error: "AtmEventDeliveryBusy" },
      { status: 503, headers: { "retry-after": "1" } },
    );
  }
  try {
    await enqueueReconciliation(event); // the worker reads canonical status
    await completeWebhookDelivery(event.id, claim.claimId);
    return Response.json({ ok: true });
  } catch (error) {
    await releaseWebhookDelivery(event.id, claim.claimId);
    throw error;
  }
}

Replay protection

  • Use short expiries for every service-auth JWT, and a new token for every request.
  • On your receiver, store jti values for the replay window before performing side effects.
  • Reject a token if iss, aud, lxm, exp, kid, signature or jti is wrong.
  • Never reuse a payer assertion across attempts or refresh one inside a retry.
  • Deduplicate app events by delivery ID (the envelope id and Atm-Delivery-Id header).

Common failures

Native checkout methods report every authentication failure as AuthenticationRequired. Other ATM XRPC methods return the specific service-auth codes below.

CodeHTTPRetryCauseDeveloper action
AuthenticationRequired401yescreateCheckout or getCheckoutStatus received a missing, expired, replayed or mis-scoped token.Mint a fresh token for the exact method and audience, then retry the same request.
BadAudience401noThe JWT aud is not your broker’s #atmosphere_money_broker service.Mint a new token with the exact documented audience.
BadScope401noThe JWT lxm does not match the XRPC method being called.Use the exact method NSID in lxm.
ExpiredToken401yesThe JWT has expired or is too old.Mint a fresh token per request and check your server clock.
ReplayDetected401yesThe jti has already been used.Mint a fresh token per request; never cache tokens across retries.
PayerAssertionInvalid400noThe payer assertion’s issuer, audience, method, expiry or signature failed.Ask the signed-in buyer to try again, as a new attempt with a new assertion.