Developers · SDKs
TypeScript / Node.js SDK
The @authguard/sdk package targets Node.js and uses jose for JWTs.
Install
It is not on npm yet. From the repository's sdks/typescript folder:
npm ci && npm pack # produces authguard-sdk-0.1.0.tgz
npm install ./authguard-sdk-0.1.0.tgzCreate a request and wait
import { IntentsClient, ApiError } from "@authguard/sdk";
const intents = new IntentsClient({
baseUrl: "https://identity.example.com",
clientId: process.env.AUTHGUARD_CLIENT_ID!,
clientSecret: process.env.AUTHGUARD_CLIENT_SECRET!,
});
const { intent } = await intents.createIntent(
{ operationType: "invoice.pay", subjectEmail: "ana@example.com",
externalReference: "INV-42", expiresInSeconds: 900,
fields: { amount: { amount: "1250.00", currency: "EUR" } } },
{ idempotencyKey: "erp-INV-42-attempt-1" },
);
console.log(intent.comparisonCode); // show it next to the operation
const decided = await intents.waitForDecision(intent.intentId, { timeoutMs: 15 * 60_000 });cancelIntent throws an ApiError with code === "conflict" when the request is already over.
Verify a webhook
import { verifyWebhook, WebhookVerificationError } from "@authguard/sdk";
const event = verifyWebhook(process.env.AUTHGUARD_WEBHOOK_SECRET!, req.headers, req.body); // raw bodyUse the raw body (for example express.raw) and deduplicate on the webhook-id header.
Verify the receipt
verifyIntentDigest(intent.intentJson, intent.intentDigest) and checkReceipt(intent.receipt, { intentId, intentDigest, state, clientId }).
Error codes in this article
Was this page helpful?
Thank you. Your answer stays in this browser; nothing is sent.
Sorry about that. Try:
- searching for the exact text of the message or the error code
- the error code index
- asking your organization's administrator