# Quickstart · Ageseal docs

Canonical URL: https://ageseal.eu/docs/quickstart

> Add the Ageseal script, call Ageseal.check, send the token to your server, verify it and handle visitors without a wallet.

Status: Planned.

Four steps, about an afternoon: a script tag, one call in the browser, one check on your server, and a fallback.

> **Planned.** You can complete these steps in test mode with a test key from an invited dashboard account. Live keys are refused until production issuers are added. Join the waitlist for an invitation. The code may still change before the first release.

## Before you start

- A site in the Ageseal dashboard with a verified domain. See [Testing and going live](https://ageseal.eu/docs/testing).
- A publishable key (`pk_test_9fK2`), a secret key (`sk_test_Hn4x`, only needed for single use redemption) and your site id (`site_7Kq2`).
- A server that can make an outbound HTTPS request to fetch public keys.

## 1. Add the script

`checkout.html`:

```html
<script src="https://cdn.ageseal.eu/v1/ageseal.js" defer></script>
```

If you use a Content Security Policy or want to pin a version, see [Browser SDK](https://ageseal.eu/docs/sdk#content-security-policy).

## 2. Call Ageseal.check

Call it from a click or tap. The browser opens its own wallet picker, and the visitor approves one question.

`checkout.html`:

```html
<button id="buy">Continue</button>
<script>
  document.getElementById("buy").addEventListener("click", async () => {
    const r = await Ageseal.check({ key: "pk_test_9fK2", over: 18 });

    if (r.result === "pass") {
      // 3. Send the token to your server
      const res = await fetch("/age-ok", { method: "POST", body: r.token });
      if (res.ok) location.href = "/checkout";
    } else if (r.result === "fail") {
      alert("This purchase is only for people over 18.");
    } else {
      showFallback(r.reason); // 5. no wallet, cancelled ...
    }
  });
</script>
```

## 3. Send the token to your server

The example above posts the token to `/age-ok`. Use any route and format you like. The token is a short string, so a request body or a header both work.

## 4. Verify the token on your server

Check the signature with the Ageseal public keys, then check the claims. Never skip this: the result in the browser can be changed by the visitor. Each example caches the public keys for you.

**Node** (`age-ok.js`)

```js
import { createRemoteJWKSet, jwtVerify } from "jose"; // npm install jose

const jwks = createRemoteJWKSet(new URL("https://api.ageseal.eu/.well-known/jwks.json"));

export async function isOver18(token) {
  try {
    const { payload } = await jwtVerify(token, jwks, {
      issuer: "https://api.ageseal.eu",
      audience: process.env.AGESEAL_SITE_ID, // "site_7Kq2"
      algorithms: ["ES256"],
    });
    return payload.result === true && payload.over >= 18 && payload.mode === "live";
  } catch {
    return false; // bad signature, wrong site, expired ...
  }
}

// POST /age-ok
export async function POST(request) {
  const token = await request.text();
  if (!(await isOver18(token))) return new Response("Not verified", { status: 403 });
  // Remember it on your side, for example in your session, then let the visitor in.
  return new Response("OK");
}
```

**Go** (`ageseal.go`)

```go
package ageseal

// go get github.com/MicahParks/keyfunc/v3 github.com/golang-jwt/jwt/v5
import (
	"os"

	"github.com/MicahParks/keyfunc/v3"
	"github.com/golang-jwt/jwt/v5"
)

var jwks, _ = keyfunc.NewDefault([]string{"https://api.ageseal.eu/.well-known/jwks.json"})

func IsOver18(token string) bool {
	t, err := jwt.Parse(token, jwks.Keyfunc,
		jwt.WithValidMethods([]string{"ES256"}),
		jwt.WithIssuer("https://api.ageseal.eu"),
		jwt.WithAudience(os.Getenv("AGESEAL_SITE_ID")), // "site_7Kq2"
		jwt.WithExpirationRequired(),
	)
	if err != nil {
		return false
	}
	c, ok := t.Claims.(jwt.MapClaims)
	if !ok {
		return false
	}
	over, _ := c["over"].(float64)
	return c["result"] == true && over >= 18 && c["mode"] == "live"
}
```

**PHP** (`ageseal.php`)

```php
<?php
// composer require firebase/php-jwt
use Firebase\JWT\JWK;
use Firebase\JWT\JWT;

function isOver18(string $token): bool {
    // Cache this for a few minutes, for example in APCu or a file.
    $jwks = json_decode(file_get_contents('https://api.ageseal.eu/.well-known/jwks.json'), true);
    try {
        $c = JWT::decode($token, JWK::parseKeySet($jwks, 'ES256'));
    } catch (Throwable $e) {
        return false; // bad signature, expired ...
    }
    return $c->iss === 'https://api.ageseal.eu'
        && $c->aud === getenv('AGESEAL_SITE_ID') // 'site_7Kq2'
        && $c->result === true
        && $c->over >= 18
        && $c->mode === 'live';
}
```

**Python** (`ageseal.py`)

```python
import os
import jwt  # pip install "pyjwt[crypto]"

jwks = jwt.PyJWKClient("https://api.ageseal.eu/.well-known/jwks.json")

def is_over_18(token: str) -> bool:
    try:
        key = jwks.get_signing_key_from_jwt(token)
        c = jwt.decode(
            token,
            key.key,
            algorithms=["ES256"],
            issuer="https://api.ageseal.eu",
            audience=os.environ["AGESEAL_SITE_ID"],  # "site_7Kq2"
            options={"require": ["exp", "iat", "iss", "aud"]},
        )
    except jwt.PyJWTError:
        return False  # bad signature, wrong site, expired ...
    return c["result"] is True and c["over"] >= 18 and c["mode"] == "live"
```

The checks are the same in every language: the signature, `iss`, `aud` (your site id), `exp`, `result` is true, `over` is at least 18, and `mode` is `live` in production. Details, key rotation and single use redemption are on [Verify tokens](https://ageseal.eu/docs/verify).

These examples accept live tokens only. Tokens from a test key have their own `iss` and `aud`, so the examples refuse them. To try the flow with a test key, see [Test tokens](https://ageseal.eu/docs/verify#test-tokens).

## 5. Handle the fallback

When `result` is `unavailable`, the visitor could not answer from a wallet. Send them to another check you trust. The gate never blocks them for that reason alone.

`fallback.js`:

```js
function showFallback(reason) {
  // reason is for your logs. It never contains personal data.
  location.href = "/age-check/other";
}
```

More patterns, and what happens when a spend cap is reached, are on [Fallback](https://ageseal.eu/docs/fallback).

## Next steps

- [Testing and going live](https://ageseal.eu/docs/testing) for test keys and the go live checklist.
- [Browser SDK](https://ageseal.eu/docs/sdk) for every option, result and reason.
- [HTTP API](https://ageseal.eu/docs/api) if you build your own client.

Docs: [Overview](https://ageseal.eu/docs), [Quickstart](https://ageseal.eu/docs/quickstart), [Browser SDK](https://ageseal.eu/docs/sdk), [Verify tokens](https://ageseal.eu/docs/verify), [HTTP API](https://ageseal.eu/docs/api), [Fallback](https://ageseal.eu/docs/fallback), [Testing and going live](https://ageseal.eu/docs/testing), [Privacy and security](https://ageseal.eu/docs/privacy-security).
