Consume approval
Uses an approved request exactly once, atomically. Call it right before performing the protected action; a replayed token or a retried form post then gets 409 already_used. The SDK guards (requireTouchque, the relay routers, tq.complete) call it for you.
POST/login/{id}/consume
| Status | Meaning |
|---|---|
200 | Consumed: user, type, details, assurance, approvalProof |
409 | already_used · rejected · expired · not_approved |
404 | Not one of your requests |
Request
const { Touchque } = require('@touchque/node');
const tq = new Touchque({
apiKey: 'tq_abc123',
apiSecret: 'YOUR_API_SECRET'
});
// Use the approval exactly once: a second call throws code 'already_used' (409).
// login.consume is in @touchque/node 5.2.0; tq.complete(requestId, { user, action })
// consumes and checks in one call.
const approval = await tq.login.consume('request_id_here');
if (approval.externalUsername !== user || approval.type !== 'LOGIN') {
throw new Error('This approval is for another user or action');
}<?php
require_once 'vendor/autoload.php';
use Touchque\Touchque;
use Touchque\Config;
$tq = new Touchque(new Config('tq_abc123', 'YOUR_API_SECRET'));
// Use the approval exactly once: a second call throws code 'already_used' (409)
$approval = $tq->login->consume('request_id_here');
if ($approval['externalUsername'] !== $user || $approval['type'] !== 'LOGIN') {
throw new RuntimeException('This approval is for another user or action');
}package main
import (
"fmt"
"log"
"github.com/Touchque/touchque-go/v5/touchque"
)
func main() {
tq, err := touchque.New(touchque.DefaultConfig("tq_abc123", "YOUR_API_SECRET"))
if err != nil {
log.Fatal(err)
}
// Use the approval exactly once: a second call returns an *APIError with Code "already_used" (409)
approval, err := tq.Login.Consume("request_id_here")
if err != nil {
log.Fatal(err)
}
fmt.Println("Approved:", approval.ExternalUsername, approval.Type)
}from touchque import Touchque, Config
tq = Touchque(Config(api_key="tq_abc123", api_secret="YOUR_API_SECRET"))
# Use the approval exactly once: a second call raises code "already_used" (409)
approval = tq.login.consume("request_id_here")
if approval["externalUsername"] != user or approval["type"] != "LOGIN":
raise RuntimeError("This approval is for another user or action")var tq = new TouchqueClient(new TouchqueOptions { ApiKey = "tq_abc123", ApiSecret = "YOUR_API_SECRET" });
// Use the approval exactly once: a second call throws code "already_used" (409)
var approval = await tq.Login.ConsumeAsync("request_id_here");
if (approval.ExternalUsername != user || approval.Type != "LOGIN")
throw new InvalidOperationException("This approval is for another user or action");var tq = new TouchqueClient(new TouchqueOptions().apiKey("tq_abc123").apiSecret("YOUR_API_SECRET"));
// Use the approval exactly once: a second call throws code "already_used" (409)
JsonNode approval = tq.login().consume("request_id_here");
if (!approval.path("externalUsername").asText().equals(user) || !"LOGIN".equals(approval.path("type").asText())) {
throw new IllegalStateException("This approval is for another user or action");
}tq = Touchque::Client.new(api_key: "tq_abc123", api_secret: "YOUR_API_SECRET")
# Use the approval exactly once: a second call raises code "already_used" (409)
approval = tq.login.consume("request_id_here")
raise "This approval is for another user or action" if approval["externalUsername"] != user || approval["type"] != "LOGIN"curl -X POST https://api.touchque.com/login/<requestId>/consume \
-H "x-api-key: tq_abc123" -H "x-timestamp: $TS" -H "x-nonce: $NONCE" -H "x-signature: $SIG"Response 200
{
"consumed": true,
"requestId": "…",
"externalUsername": "user@yourcompany.com",
"type": "WITHDRAW",
"confirmedVia": "DEVICE",
"assurance": { "phishingResistant": false, "method": "push" },
"approvalProof": { "version": "v2", "…": "…" }
}