Verifying Tokens in Your Server
Authon is a frontend-only SDK. This guide explains how to verify Authon-issued tokens on your own server and issue your own session.
Overview
When a user logs in via the Authon popup, an Authon JWT is issued. If you have your own backend API, you need a "bridge" pattern: send the Authon token to your backend, verify it, then issue your own session/JWT.
2. Frontend receives Authon JWT authon.getToken()
3. Frontend sends token to your backend POST /api/auth/authon
4. Backend verifies token via Authon API GET /v1/auth/token/verify
5. Verified → issue your own service JWT
1. Frontend: Get the token
After Authon login, use getToken() to get the JWT and send it to your backend.
import { Authon } from '@authon/js';
const authon = new Authon('pk_live_...');
authon.on('signedIn', async (user) => {
const authonToken = authon.getToken();
// Send token to your backend
const res = await fetch('/api/auth/authon', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: authonToken }),
});
const { serviceToken } = await res.json();
// Use serviceToken for your API calls
});
await authon.openSignIn();2. Backend: Verify token + issue session
Call Authon's token verification API from your backend to validate the token. If valid, create (or find) the user and issue your own service JWT.
Token Verification API
/v1/auth/token/verifyVerifies an Authon JWT and returns user information. No API key required.
Request
curl https://api.authon.dev/v1/auth/token/verify \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."Response
{
"valid": true,
"payload": {
"sub": "user-uuid",
"projectId": "project-uuid",
"type": "access",
"iat": 1711584000,
"exp": 1711584900
},
"user": {
"id": "user-uuid",
"email": "user@example.com",
"displayName": "Alan Kim",
"avatarUrl": null,
"emailVerified": true
}
}Always verify tokens server-side. Client-side token validation is insecure. Never issue service JWTs based on email alone — always verify the Authon token first.
getToken() Details
authon.getToken() returns the JWT issued by Authon. The token is signed with HS256 and expires after 15 minutes. The SDK automatically refreshes it when expired.
| Field | Value |
|---|---|
| Format | JWT (HS256) |
| Expiry | 15 minutes |
| Auto-refresh | Yes (handled by SDK) |
| Payload.sub | User UUID |
| Payload.projectId | Project UUID |