Server API and webhooks
Your product's server can look up people who have signed in to your product, and hear when something changes about them: a new name, email or phone, identity verification, or a sign-out.
Server API
Your server gets a token with your product's client id and client secret, then calls
/private/cts-product/….
Webhooks
Tekscopes POSTs signed JSON events to your https address. You check the signature and answer 2xx.
Getting access
- Ask Tekscopes to switch on Server API access for your product and choose the scopes
(
tekscopes.users.read,tekscopes.kyc.read). - For webhooks, send your https address and the events you want. You get a signing secret
(
whsec_…) once. - Use the same client id and secret your product already signs people in with. Browser-only products have no secret and can't use the server API.
Base address for the environment selected at the top: https://sso-api-dev.tekscopes.com.
Everything on this page runs in your browser. Your secrets are sent only to that address, and are never saved.
1. Get a token
POST /oauth2/token with grant_type=client_credentials. Ask for the scopes you need;
none are granted otherwise. Cache the token until it expires.
2. Look up a person
Only people who have signed in to your product (and haven't removed its access) are found. Anyone else answers
25, so you can't tell whether they have a Tekscopes account. Fields your product's sign-in scopes don't
cover are left out.
3. Webhooks
Each event is a POST to your address with Content-Type: application/json.
| Header | Value |
|---|---|
Tekscopes-Webhook-Id | The event id. The same on every retry: use it to ignore repeats. |
Tekscopes-Webhook-Delivery | This delivery's id. |
Tekscopes-Webhook-Timestamp | Unix seconds. |
Tekscopes-Signature | t=<unix>,v1=<hex>. Two v1 values during a secret rotation. |
Body: { "id", "type", "createdAt", "data" }
| type | data | When |
|---|---|---|
user.updated | {userId, changed: ["name","email","phone"]} | A name, email or phone changed. Read the new values with the server API. |
user.kyc_updated | {userId, level, previousLevel, checks} | Identity verification changed. level is your product's own level (you name them, e.g. "basic"); null until identity verification launches. |
session.revoked | {userId, sessions: "all" | "browser" | "device", reason, sid?, deviceId?} | The person signed out, signed out everywhere, removed your product's access (reason: "access_removed"), or Tekscopes locked the account. Drop your sessions for them. |
user.deleted | {userId} | Coming later. |
ping | {webhookId, clientId, message} | A test sent by Tekscopes. |
Answering and retries
- Answer any 2xx within 5 seconds, and do slow work afterwards. Redirects aren't followed.
- Retries after 1 min, 5 min, 30 min, 2 h, 6 h and 12 h. After that the delivery is marked failed; Tekscopes can send it again.
- A webhook is switched off after 50 failures in a row, or after 3 days of failing.
- Order isn't guaranteed. Use
createdAt, and read the current state with the server API when it matters.
Signature checker
Paste a delivery your server received to see whether its signature is valid, or make a signed example to send to your own server. This runs in your browser only; nothing is sent anywhere.
Code samples
# Token curl -s https://sso-api-dev.tekscopes.com/oauth2/token \ -u "$CLIENT_ID:$CLIENT_SECRET" \ -d grant_type=client_credentials \ -d scope=tekscopes.users.read # A person by id (the sub in your ID tokens) curl -s https://sso-api-dev.tekscopes.com/private/cts-product/read/user/$USER_ID \ -H "Authorization: Bearer $TOKEN" # By phone: encode the + as %2B curl -s "https://sso-api-dev.tekscopes.com/private/cts-product/read/user-by-phone?phone=%2B2348031234567" \ -H "Authorization: Bearer $TOKEN"
import crypto from "node:crypto";
const BASE = "https://sso-api-dev.tekscopes.com";
// Token (cache it until expires_in runs out)
const res = await fetch(`${BASE}/oauth2/token`, {
method: "POST",
headers: {
Authorization: "Basic " + Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString("base64"),
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({ grant_type: "client_credentials", scope: "tekscopes.users.read" }),
});
const { access_token } = await res.json();
// A person
const person = await fetch(`${BASE}/private/cts-product/read/user/${userId}`, {
headers: { Authorization: `Bearer ${access_token}` },
}).then(r => r.json());
// Webhook signature: pass the RAW body (e.g. express.raw({ type: "application/json" }))
function verify(rawBody, header, secret) {
const parts = header.split(",").map(p => p.split("="));
const t = parts.find(([k]) => k === "t")?.[1];
const sigs = parts.filter(([k]) => k === "v1").map(([, v]) => v);
if (!t || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
return sigs.some(s => s.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)));
}
import hashlib, hmac, time
import requests
BASE = "https://sso-api-dev.tekscopes.com"
# Token
r = requests.post(f"{BASE}/oauth2/token", auth=(CLIENT_ID, CLIENT_SECRET),
data={"grant_type": "client_credentials", "scope": "tekscopes.users.read"})
token = r.json()["access_token"]
# A person
person = requests.get(f"{BASE}/private/cts-product/read/user/{user_id}",
headers={"Authorization": f"Bearer {token}"}).json()
# Webhook signature: raw_body is the request body as bytes, before any JSON parsing
def verify(raw_body: bytes, header: str, secret: str) -> bool:
parts = [p.split("=", 1) for p in header.split(",") if "=" in p]
t = next((v for k, v in parts if k == "t"), None)
sigs = [v for k, v in parts if k == "v1"]
if t is None or abs(time.time() - int(t)) > 300:
return False
expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(s, expected) for s in sigs)
<?php
$base = "https://sso-api-dev.tekscopes.com";
// Token
$ch = curl_init("$base/oauth2/token");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_USERPWD => "$clientId:$clientSecret",
CURLOPT_POSTFIELDS => http_build_query(["grant_type" => "client_credentials", "scope" => "tekscopes.users.read"]),
CURLOPT_RETURNTRANSFER => true,
]);
$token = json_decode(curl_exec($ch), true)["access_token"];
// Webhook signature: $rawBody = file_get_contents("php://input");
function verify(string $rawBody, string $header, string $secret): bool {
$t = null; $sigs = [];
foreach (explode(",", $header) as $part) {
$kv = explode("=", $part, 2);
if (count($kv) !== 2) continue;
if ($kv[0] === "t") $t = $kv[1]; elseif ($kv[0] === "v1") $sigs[] = $kv[1];
}
if ($t === null || abs(time() - (int) $t) > 300) return false;
$expected = hash_hmac("sha256", $t . "." . $rawBody, $secret);
foreach ($sigs as $s) if (hash_equals($expected, $s)) return true;
return false;
}
import java.security.MessageDigest
import java.time.Instant
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import kotlin.math.abs
// Token: POST {BASE}/oauth2/token with HTTP Basic (client id, secret) and
// grant_type=client_credentials&scope=tekscopes.users.read; Spring: spring-security-oauth2-client
// with authorization-grant-type: client_credentials does this for you.
// Webhook signature: rawBody is the request body exactly as received
fun verify(rawBody: ByteArray, header: String, secret: String): Boolean {
val parts = header.split(",").filter { "=" in it }.map { it.substringBefore("=") to it.substringAfter("=") }
val t = parts.firstOrNull { it.first == "t" }?.second?.toLongOrNull() ?: return false
if (abs(Instant.now().epochSecond - t) > 300) return false
val mac = Mac.getInstance("HmacSHA256").apply { init(SecretKeySpec(secret.toByteArray(), "HmacSHA256")) }
mac.update("$t.".toByteArray())
val expected = mac.doFinal(rawBody).joinToString("") { "%02x".format(it) }.toByteArray()
return parts.filter { it.first == "v1" }.any { MessageDigest.isEqual(it.second.toByteArray(), expected) }
}
Response codes
Token endpoint (OAuth errors)
| error | Meaning |
|---|---|
invalid_client | Wrong client id or secret, or the secret is disabled. |
unauthorized_client | Server API access isn't switched on for this product. |
invalid_scope | A scope your product wasn't given. |
Server API
| responseCode | Meaning |
|---|