Generate secret

Generate a secret to register your user in the 2FA system. Display it to the user — they enter it in the Touchque mobile app to link their device.

POST/auth/generate-secret
Body parameters
ParameterTypeDescription
externalUsernamestringYour user ID Required
clientIpstringThe end user's IP address, as for a login request (a port is dropped; loopback and non-IP values are ignored) Optional
userAgentstringThe end user's browser User-Agent (cut at 512 characters) Optional
Secret is returned only in this response. Validity: 5 minutes.
Setup context. With clientIp and userAgent, Touchque records where the QR was asked for and the phone shows it before linking: city and country, browser and device, time, and a warning when it is far from the phone. Someone tricked into scanning another person's QR then sees that person's place and device. It is kept on our side, never in the QR. The SDKs' relays and guards send the browser's values for you; POST /auth/secret/reset takes the same two fields.
Request
const { Touchque } = require('@touchque/node');

const tq = new Touchque({
  apiKey: 'tq_abc123',
  apiSecret: 'YOUR_API_SECRET'
});

async function setupUser() {
  // Generate a new secret for the user (expires in 5 minutes)
  const result = await tq.auth.generateSecret({
    externalUsername: 'user@yourcompany.com'
  });
  
  // result = { secret: "A1B2...", expiresAt: "2026-05-18...", ttlMs: 300000, externalUsername: "..." }
  // ⚠️ Secret is only returned in this response!
  console.log('Secret:', result.secret);
}

setupUser();
Response 200
{
  "secret": "A1B2C3D4E5F6A7B8C9D0E1F2",
  "qrCodeDataUrl": "data:image/png;base64,…",
  "externalUsername": "user@yourcompany.com",
  "expiresAt": "2026-11-02T12:05:00.000Z",
  "ttlMs": 300000,
  "recoveryCodes": ["…", "…"]
}