Verify the token
This goes in the handler that receives the form. Read the secret from your
environment — it is a server credential and must never reach the browser — and
the token from the goust-response field the widget wrote.
Every sample below sends the same request; pick the one you already work in.
# $GOUST_SECRET is your site secret. $TOKEN is the value of the
# "goust-response" field the widget wrote into your form.
# For a signed-in user, add "account":"<your own id for them>" to the body.
curl -s -X POST https://challenge.goust.io/siteverify \
-H 'content-type: application/json' \
-d "{\"secret\":\"$GOUST_SECRET\",\"response\":\"$TOKEN\"}"
# => {"success":true}
# => {"success":false,"errors":["invalid_secret"]}// Node, or anything with fetch. Never run this in a browser:
// the secret is a server credential and a page that held it would leak it.
const answer = await fetch("https://challenge.goust.io/siteverify", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
secret: process.env.GOUST_SECRET,
response: form.get("goust-response"),
// account: user.id, // optional: your own id for a signed-in user
}),
});
// 200 for a refusal as well as a grant — "no" is an answer, not an error.
const verdict = await answer.json();
if ( !verdict.success ) {
// verdict.errors names what was wrong, e.g. "expired_response"; it is
// empty when Goust denied the visitor, by its score or by a policy.
// Reject the submission.
return reject(verdict.errors);
}
// The token is genuine, unspent, and Goust granted its visitor.
accept();import os
import requests
# Never run this in a browser-facing context: the secret is a server credential.
answer = requests.post(
"https://challenge.goust.io/siteverify",
json={
"secret": os.environ["GOUST_SECRET"],
"response": form["goust-response"],
# "account": user.id, # optional: your own id for a signed-in user
},
timeout=10,
)
# 200 for a refusal as well as a grant — "no" is an answer, not an error.
verdict = answer.json()
if not verdict["success"]:
# verdict["errors"] names what was wrong, e.g. "expired_response"; it is
# empty when Goust denied the visitor, by its score or by a policy.
# Reject the submission.
return reject(verdict["errors"])
# The token is genuine, unspent, and Goust granted its visitor.
accept()// The secret is a server credential; keep it out of anything client-facing.
body, _ := json.Marshal(map[string]string{
"secret": os.Getenv("GOUST_SECRET"),
"response": r.FormValue("goust-response"),
// "account": user.ID, // optional: your own id for a signed-in user
})
answer, err := http.Post("https://challenge.goust.io/siteverify", "application/json", bytes.NewReader(body))
if err != nil {
return err
}
defer answer.Body.Close()
// 200 for a refusal as well as a grant — "no" is an answer, not an error.
var verdict struct {
Success bool `json:"success"`
Errors []string `json:"errors"`
}
if err := json.NewDecoder(answer.Body).Decode(&verdict); err != nil {
return err
}
if !verdict.Success {
// verdict.Errors names what was wrong, e.g. "expired_response"; it is
// empty when Goust denied the visitor, by its score or by a policy.
// Reject the submission.
return reject(verdict.Errors)
}
// The token is genuine, unspent, and Goust granted its visitor.
accept()// reqwest + serde_json. The secret is a server credential.
#[derive(serde::Deserialize)]
struct Verdict {
success: bool,
#[serde(default)]
errors: Vec<String>,
}
let verdict: Verdict = client
.post("https://challenge.goust.io/siteverify")
.json(&serde_json::json!({
"secret": std::env::var("GOUST_SECRET")?,
"response": form.get("goust-response"),
// "account": user.id, // optional: your own id for a signed-in user
}))
.send()
.await?
// 200 for a refusal as well as a grant — "no" is an answer, not an error.
.json()
.await?;
if !verdict.success {
// verdict.errors names what was wrong, e.g. "expired_response"; it is
// empty when Goust denied the visitor, by its score or by a policy.
// Reject the submission.
return reject(verdict.errors);
}
// The token is genuine, unspent, and Goust granted its visitor.
accept();<?php
// The secret is a server credential; never emit it into a page.
$answer = file_get_contents("https://challenge.goust.io/siteverify", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "content-type: application/json\r\n",
"content" => json_encode([
"secret" => getenv("GOUST_SECRET"),
"response" => $_POST["goust-response"],
// "account" => $user->id, // optional: your own id for a signed-in user
]),
"ignore_errors" => true,
],
]));
// 200 for a refusal as well as a grant — "no" is an answer, not an error.
$verdict = json_decode($answer, true);
if (!$verdict["success"]) {
// $verdict["errors"] names what was wrong, e.g. "expired_response"; it is
// empty when Goust denied the visitor, by its score or by a policy.
// Reject the submission.
return reject($verdict["errors"]);
}
// The token is genuine, unspent, and Goust granted its visitor.
accept();The request
Section titled “The request”A JSON body with two fields, and a third you may add:
| Field | Value |
|---|---|
secret |
Your site secret, from the dashboard. |
response |
The token, from the goust-response form field. |
account |
Optional. Your own id for the account the visitor is signed in to: an opaque string of 1 to 128 characters. |
Send account when the form belongs to a signed-in user. Goust then keeps a
reputation for that account on your site, and on plans with risk details the
answer carries it. The id is yours and
stays opaque: use an internal id rather than an email address. Goust stores a
keyed hash of it, scoped to your site, and never the value. Leave the field
out for a visitor who is not signed in.
Branch on success in the answer rather than on the status: /siteverify
answers 200 for a refusal as well as a grant. Reading the answer
has both shapes.
Verifying twice
Section titled “Verifying twice”A token is single-use. Once a verification succeeds, verifying the same token again refuses, which is what stops a captured token being replayed against your form.