auth variable. This is how you control who can read and write what.
Anonymous access
The simplest way to connect. No credentials, no tokens. The client connects and starts reading and writing immediately. In security rules,auth will be null for anonymous clients. You can allow anonymous access where appropriate:
Lark tokens
Lark tokens are JWTs (JSON Web Tokens) signed with your project’s secret key using HS256. You generate them on your backend server and pass them to the client.Generating a token
On your server, create a JWT with at least auid field:
The auth object in security rules
Once authenticated, the auth object in security rules contains the token’s payload:
auth.uid— The user’s unique ID from theuidfield in the token.auth.token— The full token payload, including any custom claims.
Custom claims
Include any extra data in your token to make it available in security rules. Common use cases: roles, permissions, team membership, subscription tier.Token flow
Here’s the full authentication flow:- The user logs in to your app through whatever auth system you use (email/password, OAuth, SSO).
- Your backend server verifies the user’s identity.
- Your backend generates a signed Lark JWT containing the user’s
uidand any custom claims. - Your backend sends the token to the client.
- The client passes the token to Lark on connect (or via
signIn). - Lark validates the JWT signature against your project’s secret key.
- If valid, the
authobject is populated for all security rule evaluations on this connection.
Lark doesn’t manage user accounts or passwords. It trusts whatever identity your backend puts in the JWT. This gives you full flexibility — use any auth provider, any user store, any login flow you want.
Secret key management
Your project’s secret key is available in the Lark dashboard under Project Settings > Secret Key. A few important rules:- Keep it on your server. Never include the secret key in client-side code, mobile apps, or anywhere a user could extract it.
- Use environment variables. Store it as
LARK_SECRET_KEYor similar, not hardcoded in source files. - Regenerate if compromised. You can regenerate your secret key from the dashboard at any time. This immediately invalidates all existing tokens — connected clients will need to re-authenticate with tokens signed by the new key.

