In Agora Console, create a project and enable App Certificate to require token authentication; download or clone Agora's open-source token server reference implementation (AgoraDynamicKey on GitHub) in your preferred language.
On your server, implement a token generation endpoint that accepts appId, appCertificate, channelName, and uid; use the RtcTokenBuilder from the SDK to call buildTokenWithUid() with a privilege expiry time in seconds (maximum 24 hours per token).
Return the generated token to your client; the client calls agoraEngine.joinChannel(token, channelName, uid, options) — uid and channelName must exactly match the values used to generate the token.
Handle token expiration on the client by listening for the onTokenPrivilegeWillExpire callback (fires 30 seconds before expiry); fetch a fresh token from your server and call agoraEngine.renewToken(newToken) without leaving the channel.
If the token expires before renewal, the SDK fires onConnectionStateChanged with the reason TOKEN_EXPIRED; the client must leave and rejoin with a new token.
For security, never embed your App Certificate in client-side code; always generate tokens server-side and invalidate compromised tokens by rotating the App Certificate in Agora Console (this invalidates all existing tokens).
Known gotchas
Using App ID without a certificate (test mode) is only for development; production traffic without token authentication is disabled by default once App Certificate is enabled.
The uid must be an unsigned 32-bit integer or 0 (Agora assigns a UID when 0 is passed); using the same uid for two clients in the same channel causes one client to be kicked.
Token generation timestamps are based on server time; significant clock skew between your token server and Agora's infrastructure can cause premature token expiry — sync your server clock with NTP.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp