How to vverify livekit token on my backend server?
# ask-ai
n
How to vverify livekit token on my backend server?
t
Thanks for reaching out, Hari. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you verify a LiveKit token on your backend server, here’s a simple step-by-step guide you can follow: 1. Extract API Key and Secret: Make sure you use the same
LIVEKIT_API_KEY
and
LIVEKIT_API_SECRET
that were originally used to generate the token. 2. Decode and Validate the JWT: ◦ First, verify the token's signature using your API secret. ◦ Check that the token hasn’t expired by looking at the
exp
claim. ◦ Ensure the token isn’t being used before its not-before time, which you can find in the
nbf
claim. ◦ Confirm that the issuer (
iss
) matches your API key. 1. Extract Claims: Once the token is successfully verified, you can decode the permissions inside it—like room access, publishing rights—and get the participant’s identity from the token payload. To make things easier, here are some examples in different programming languages: • *Ruby:*`require 'livekit-server-sdk' verifier = LiveKit::TokenVerifier.new(api_key: 'your_api_key', api_secret: 'your_api_secret') claims = verifier.verify(token) #
claims
will include identity, video grants, metadata, and more.` • *Rust:*`use livekit_api::AccessToken; let verifier = TokenVerifier::with_api_key("your_api_key", "your_api_secret"); let claims = verifier.verify(&token).unwrap(); // Access details like
claims.sub
(identity),
claims.video
, etc.` • *Python:*`from livekit.api.access_token import TokenVerifier verifier = TokenVerifier(api_key="your_api_key", api_secret="your_api_secret") claims = verifier.verify(token) # You can extract identity, permissions, metadata, and more from claims` • *JavaScript/Node.js:*`import jwt from 'jsonwebtoken'; try { const decoded = jwt.verify(token, process.env.LIVEKIT_API_SECRET, { issuer: process.env.LIVEKIT_API_KEY, }); // Token is valid! You can now use the decoded claims. } catch (err) { // If the token is invalid, handle errors related to signature, expiration, or issuer here. }` If you have any questions or need a hand with the implementation, please don’t hesitate to ask—I’m here to help! Sources: Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | LiveKit Server Platform | livekit/livekit_composite | DeepWiki | spec/livekit/token_verifier_spec.rb | livekit-api/src/access_token.rs | livekit-api/livekit/api/access_token.py