← All posts
BLOG · · Sebastien Le Touze

Anonymous sessions, one HTTP call, nine languages

Verify a visitor is human without learning who they are. Walk-through plus the same call in PHP, Python, Ruby, Node, Go, C#, Java, Unity, Godot, and Unreal.

6 MIN READ 8 SECTIONS TUTORIAL

LoginSeal's anon:ephemeral scope lets you confirm a visitor is a real human without ever asking for their name, email, or any persistent identifier. The token your backend gets back carries the claims you asked for (typically is_human, and optionally an age band like age_over_18) and nothing else. No sub, no email, no profile. Every issuance mints a fresh UUID; LoginSeal does not store a row linking the visitor to your app.

This post walks through the simplest end-to-end shape: one POST to mint an anonymous session, one bearer-token call to verify a claim, done. The same call appears below in nine languages.

When to reach for this

  • A forum that wants to gate posting behind "you are a real human" without forcing sign-up.
  • A vote-once survey where you need each respondent to be distinct, but you must not be able to identify them later.
  • An age gate for one piece of content where a persistent identity would be overkill and a compliance risk.
  • A free-tier rate limit that cannot rely on IP alone but where a real account is too much friction.

If you want a stable anonymous identity (the same opaque sub each time this visitor comes back), use anon:stable instead. The shape is identical; only the persistence semantics differ.

What you need before you start

  1. A registered OAuth client on LoginSeal with anon:ephemeral in its anon_scopes_allowed list. The dev console covers this under Your apps → Anonymous scopes.
  2. The client ID and client secret for that app. Treat the secret like any other API credential: server-side only, never in front-end JavaScript or compiled into a Unity build.
  3. Your backend able to make outbound HTTPS calls to https://loginseal.com.

The call

The same HTTP request in nine languages. Every variant POSTs JSON to /api/v1/anonymous-sessions, asks for the is_human claim, and prints the returned token. The request body is the same in every case; what differs is the HTTP client idiom.

$res = (new GuzzleHttp\Client())->post('https://loginseal.com/api/v1/anonymous-sessions', [
    'json' => [
        'client_id' => $clientId,
        'client_secret' => $clientSecret,
        'scope' => 'anon:ephemeral is_human',
    ],
]);
$body = json_decode((string) $res->getBody(), true);
// Persist $body['anonym_id'] and $body['anonym_token'] for the current visitor session.
import requests
res = requests.post('https://loginseal.com/api/v1/anonymous-sessions', json={
    'client_id': client_id,
    'client_secret': client_secret,
    'scope': 'anon:ephemeral is_human',
})
body = res.json()
# Persist body['anonym_id'] and body['anonym_token'] for the current visitor session.
require 'net/http'
require 'json'
uri = URI('https://loginseal.com/api/v1/anonymous-sessions')
res = Net::HTTP.post(uri, {
    client_id: client_id,
    client_secret: client_secret,
    scope: 'anon:ephemeral is_human',
}.to_json, 'Content-Type' => 'application/json')
body = JSON.parse(res.body)
# Persist body['anonym_id'] and body['anonym_token'] for the current visitor session.
const res = await fetch('https://loginseal.com/api/v1/anonymous-sessions', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        client_id: clientId,
        client_secret: clientSecret,
        scope: 'anon:ephemeral is_human',
    }),
});
const body = await res.json();
// Persist body.anonym_id and body.anonym_token for the current visitor session.
payload, _ := json.Marshal(map[string]string{
    "client_id":     clientId,
    "client_secret": clientSecret,
    "scope":         "anon:ephemeral is_human",
})
res, _ := http.Post(
    "https://loginseal.com/api/v1/anonymous-sessions",
    "application/json",
    bytes.NewBuffer(payload),
)
var body map[string]any
json.NewDecoder(res.Body).Decode(&body)
// Persist body["anonym_id"] and body["anonym_token"] for the current visitor session.
using var http = new HttpClient();
var payload = JsonContent.Create(new {
    client_id = clientId,
    client_secret = clientSecret,
    scope = "anon:ephemeral is_human",
});
var res = await http.PostAsync("https://loginseal.com/api/v1/anonymous-sessions", payload);
var body = await res.Content.ReadFromJsonAsync<Dictionary<string, string>>();
// Persist body["anonym_id"] and body["anonym_token"] for the current visitor session.
var body = """
{"client_id":"%s","client_secret":"%s","scope":"anon:ephemeral is_human"}
""".formatted(clientId, clientSecret);
var req = HttpRequest.newBuilder(URI.create("https://loginseal.com/api/v1/anonymous-sessions"))
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(body))
    .build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
// Parse res.body() with your JSON library of choice and persist anonym_id + anonym_token.
using UnityEngine.Networking;
var payload = JsonUtility.ToJson(new AnonRequest {
    client_id = clientId,
    client_secret = clientSecret,
    scope = "anon:ephemeral is_human",
});
using var req = new UnityWebRequest("https://loginseal.com/api/v1/anonymous-sessions", "POST");
req.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(payload));
req.downloadHandler = new DownloadHandlerBuffer();
req.SetRequestHeader("Content-Type", "application/json");
yield return req.SendWebRequest();
// Parse req.downloadHandler.text and persist on the player session.
var payload = JSON.stringify({
    "client_id": client_id,
    "client_secret": client_secret,
    "scope": "anon:ephemeral is_human",
})
var http = HTTPRequest.new()
add_child(http)
http.request(
    "https://loginseal.com/api/v1/anonymous-sessions",
    PackedStringArray(["Content-Type: application/json"]),
    HTTPClient.METHOD_POST,
    payload,
)
# Connect http.request_completed and persist anonym_id + anonym_token in the result.
TSharedRef<IHttpRequest> Req = FHttpModule::Get().CreateRequest();
Req->SetURL(TEXT("https://loginseal.com/api/v1/anonymous-sessions"));
Req->SetVerb(TEXT("POST"));
Req->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
Req->SetContentAsString(FString::Printf(
    TEXT("{\"client_id\":\"%s\",\"client_secret\":\"%s\",\"scope\":\"anon:ephemeral is_human\"}"),
    *ClientId, *ClientSecret));
Req->OnProcessRequestComplete().BindLambda([](FHttpRequestPtr, FHttpResponsePtr Resp, bool bOK) {
    // Parse Resp->GetContentAsString() and persist on the player session.
});
Req->ProcessRequest();

The user's choice of language sticks across pages: pick Go here, jump to the Webhooks tutorial, and the Webhooks tabs will open on Go too.

Reading the response

The endpoint returns a small JSON object:

{
    "anonym_id": "9b6e6a2c-c5a3-4d12-9a4b-7c3a8b1d2e4f",
    "anonym_token": "eyJhbGciOiJSUzI1NiI...",
    "expires_in": 600,
    "claims": ["is_human"]
}
  • anonym_id is a fresh UUID per call. It is not linked to a LoginSeal user on our side. Two calls for the same visitor return two different UUIDs.
  • anonym_token is a short-lived JWT (10 minutes) that your backend can verify against our public keys at /.well-known/jwks.json. The token carries only the claims you asked for plus a sub matching anonym_id.
  • claims is the resolved list. If the visitor refused a claim on the consent screen, it will be missing here. Your code should treat any required claim as optional and degrade gracefully when absent.

Where to put the token

For a web app, put anonym_token in an HTTP-only, SameSite=Lax cookie scoped to your domain. Refresh it before it expires by calling the endpoint again with the same client credentials.

For a game client, store it in volatile memory only. Treat it as a per-session bearer; do not write it to disk. If the player closes the game, you mint a new one on relaunch. This is the deliberate trade-off of anon:ephemeral: nothing persists beyond the current session, so there is nothing to leak.

What is not in the response

No email, no display name, no avatar, no sub you can correlate across requests, no IP, no fingerprint. If a piece of code in your stack starts to need one of those, you have outgrown anonymous scopes — switch the integration to anon:stable (same call, the response gains a stable pairwise sub) or to a normal signed-in OAuth flow.

Common mistakes

  1. Treating anonym_id as a user identifier across calls. It is not. Two calls = two UUIDs.
  2. Storing the secret in front-end code. The client secret stays on the server. The visitor never sees it.
  3. Sending the call from the browser to bypass the secret. You cannot. Browser-issued tokens have to flow through your backend, which is the whole point of the bearer model.
  4. Forgetting the 10-minute expiry. Build refresh into your hot path before users hit a stale token.

Where to go from here

  • Webhooks: how LoginSeal notifies you when a stable anonymous visitor revokes consent.
  • Per-user developer data: the only LoginSeal feature that lets a third-party app store information about a stable anonymous visitor, on our infrastructure, in a way the visitor can audit.
  • The cascade evaluator: when an age_over_18 claim costs nothing and when it triggers a fresh verification under per-session-mandate jurisdictions like Italy and France.
← Previous
The case against blanket cookie consent
Next →
Built in Europe, on purpose
🇪🇺Operated in the European Union
🛡️Designed for GDPR
🧪In beta: anything not marked Next works today