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
| Parameter | Type | Description |
|---|---|---|
externalUsername | string | Your user ID Required |
clientIp | string | The end user's IP address, as for a login request (a port is dropped; loopback and non-IP values are ignored) Optional |
userAgent | string | The 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();<?php
require_once 'vendor/autoload.php';
use Touchque\Touchque;
use Touchque\Config;
$config = new Config(
'tq_abc123',
'YOUR_API_SECRET'
);
$tq = new Touchque($config);
// Generate a new secret for the user (expires in 5 minutes)
$result = $tq->auth->generateSecret('user@yourcompany.com');
// result = ['secret' => 'A1B2...', 'expiresAt' => '2026...', 'externalUsername' => '...']
// ⚠️ Secret is only returned in this response!
echo "Secret: " . $result['secret'];package main
import (
"fmt"
"log"
"github.com/Touchque/touchque-go/v6/touchque"
)
func main() {
tq, err := touchque.New(touchque.DefaultConfig("tq_abc123", "YOUR_API_SECRET"))
if err != nil {
log.Fatal(err)
}
// Generate a new secret for the user (expires in 5 minutes)
result, err := tq.Auth.GenerateSecret("user@yourcompany.com")
if err != nil {
log.Fatal(err)
}
// result = &touchque.GenerateSecretResponse{Secret: "A1B2...", ExpiresAt: "2026...", QRCodeDataURL: "data:image/png;base64,...", ...}
// ⚠️ Secret is only returned in this response!
fmt.Println("Secret:", result.Secret)
}from touchque import Touchque, Config
tq = Touchque(Config(
api_key="tq_abc123",
api_secret="YOUR_API_SECRET"
))
# Generate a new secret for the user (expires in 5 minutes)
result = tq.auth.generate_secret("user@yourcompany.com")
# result = {'secret': 'A1B2...', 'expiresAt': '2026...', 'externalUsername': '...'}
# ⚠️ Secret is only returned in this response!
print("Secret:", result["secret"])using Touchque;
var tq = new TouchqueClient(new TouchqueOptions { ApiKey = "tq_abc123", ApiSecret = "YOUR_API_SECRET" });
// Generate a new secret for the user (expires in 5 minutes)
var result = await tq.Auth.GenerateSecretAsync("user@yourcompany.com");
// ⚠️ Secret is only returned in this response!
Console.WriteLine($"Secret: {result.Secret}");import com.touchque.TouchqueClient;
import com.touchque.TouchqueOptions;
var tq = new TouchqueClient(new TouchqueOptions().apiKey("tq_abc123").apiSecret("YOUR_API_SECRET"));
// Generate a new secret for the user (expires in 5 minutes)
JsonNode result = tq.auth().generateSecret("user@yourcompany.com");
// ⚠️ Secret is only returned in this response!
System.out.println("Secret: " + result.path("secret").asText());require "touchque"
tq = Touchque::Client.new(api_key: "tq_abc123", api_secret: "YOUR_API_SECRET")
# Generate a new secret for the user (expires in 5 minutes)
result = tq.auth.generate_secret("user@yourcompany.com")
# ⚠️ Secret is only returned in this response!
puts "Secret: #{result["secret"]}"# 1) Generate signature
BODY='{"externalUsername": "user@yourcompany.com"}'
BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 | awk '{print $2}')
TS=$(date +%s000)
NONCE=$(openssl rand -hex 16)
MSG="POST:/auth/generate-secret:$TS:$NONCE:$BODY_HASH"
SIG=$(echo -n "$MSG" | openssl dgst -sha256 -hmac "YOUR_API_SECRET" | awk '{print $2}')
# 2) Send request
curl -X POST https://api.touchque.com/auth/generate-secret \
-H "x-api-key: tq_abc123" \
-H "x-signature: $SIG" \
-H "x-timestamp: $TS" \
-H "x-nonce: $NONCE" \
-H "Content-Type: application/json" \
-d "$BODY"Response 200
{
"secret": "A1B2C3D4E5F6A7B8C9D0E1F2",
"qrCodeDataUrl": "data:image/png;base64,…",
"externalUsername": "user@yourcompany.com",
"expiresAt": "2026-11-02T12:05:00.000Z",
"ttlMs": 300000,
"recoveryCodes": ["…", "…"]
}