Developer documentation
How your mini app receives the WAAFI user token and how your backend verifies it.
Integration flow
- 1
The user opens your mini app from the WAAFI app. WAAFI creates a signed token for this user and your app.
- 2
WAAFI opens your URL in its webview with the token in the token query parameter: https://your-app.example/?token=<jwt>.
- 3
Your page reads the token, removes it from the address bar at once, and sends it to your backend over HTTPS.
- 4
Your backend verifies the token (below) and creates its own session for the user.
The token arrives in the URL, so treat it like a password: remove it from the address bar right away with history.replaceState, never log it, and never put it in links, analytics or the Referer header (add <meta name="referrer" content="no-referrer">).
Reading the token in your page
Read token from the query string when the page loads, clean the URL, and POST the token to your backend. If there is no token, the page was not opened from WAAFI: show your normal sign-in.
<!-- In <head>: never send the URL (with the token) as Referer -->
<meta name="referrer" content="no-referrer">
<script>
// WAAFI opens your page as https://your-app.example/?token=<jwt>
(async function signInWithWaafi() {
const url = new URL(window.location.href);
const token = url.searchParams.get('token');
if (!token) {
// Not opened from WAAFI: show your normal sign-in instead.
return;
}
// 1. Remove the token from the address bar and history at once.
url.searchParams.delete('token');
history.replaceState(history.state, '', url.pathname + url.search + url.hash);
// 2. Send it to your backend over HTTPS; the backend verifies it.
// Never log it or put it in links or analytics.
await fetch('/api/waafi/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token }),
});
})();
</script>Token claims
The token is a JWT signed with RS256. The header carries the kid of the signing key. It is valid for 6 hours.
| Claim | Meaning |
|---|---|
| kid | Header: id of the signing key. Use it to pick the key from the JWKS. |
| iss | Issuer — the WAAFI mini app token service. |
| aud | Audience — your app slug. |
| sub | Pairwise user id: stable for the same user in your app, different in every other app. Use it as your user key. |
| iat | Issued at (Unix seconds). |
| exp | Expiry (Unix seconds), 6 hours after iat. |
| jti | Unique token id. Store it until the token expires and reject a jti you have already seen (replay). |
| data | Only the user fields your app was approved for: firstName, middleName, lastName, phone, email, deviceId, countryCode. |
{
"iss": "https://miniapps-api.waafi.com/miniapp",
"aud": "baano-health",
"sub": "3f9a0c5e1b7d4a2e8c6f0b1d2e3a4c5b",
"iat": 1767225600,
"exp": 1767247200,
"jti": "9b2f6c1e-7a1d-4c3e-9f0a-2b4d6e8f0a1c",
"data": { "phone": "252615000000", "firstName": "Amina" }
}Public keys (JWKS)
Fetch the public keys for your app from the JWKS endpoint. Responses can be cached for up to 5 minutes.
- Production
https://miniapps-api.waafi.com/.well-known/miniapp/{slug}/jwks.json
Your exact URL is shown in the portal under your app → Keys & testing.
Checks your backend must do
- Signature: select the key whose kid matches the token header, and verify with RS256 only.
- iss equals the WAAFI issuer.
- aud equals your app slug.
- exp is in the future (allow at most a small clock skew, e.g. 30 s).
- jti has not been used before (keep used ids until they expire).
Key rotation
- When a key is rotated, the new key becomes ACTIVE and signs all new tokens immediately.
- The old key moves to ROTATING and stays in the JWKS for an overlap period (72 hours by default), so tokens already issued still verify.
- Never pin a single key: always select by kid. If you see an unknown kid, refetch the JWKS (at most once a minute).
- A revoked key is removed from the JWKS at once and is never used for signing.
Verification examples
Replace the slug with your own.
// npm install jose
import { createRemoteJWKSet, jwtVerify } from 'jose';
const SLUG = 'baano-health'; // your app slug (= aud)
const ISSUER = 'https://miniapps-api.waafi.com/miniapp';
// Cached and refetched automatically when an unknown kid appears.
const JWKS = createRemoteJWKSet(
new URL(`https://miniapps-api.waafi.com/.well-known/miniapp/${SLUG}/jwks.json`)
);
export async function verifyWaafiToken(token) {
const { payload } = await jwtVerify(token, JWKS, {
algorithms: ['RS256'], // signature, selected by the kid header
issuer: ISSUER, // iss
audience: SLUG, // aud
clockTolerance: 30, // exp with 30 s skew
requiredClaims: ['exp', 'sub', 'jti'],
});
// Reject a jti you have already seen (keep used ids until payload.exp).
return { userId: payload.sub, data: payload.data ?? {} };
}Testing
Before your app is published, only the phone numbers you add as test numbers can open it in WAAFI. Add them in the portal under Keys & testing, open the app in WAAFI, and watch integration health for issued and denied tokens.