JWT Authentication
How JSON Web Tokens are implemented in Zyeta
Zyeta uses JSON Web Tokens (JWT) as the primary authentication mechanism, providing a stateless, secure way to verify user identity across API requests.
What are JWTs?
JSON Web Tokens are an open standard (RFC 7519) for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed.
In Zyeta, JWTs are used to:
- Authenticate users after login
- Maintain session state without server-side storage
- Pass user identity information securely between services
JWT Structure
JWTs consist of three parts separated by dots:
Header
Contains the token type and signing algorithm:
Payload
Contains the claims or user data:
Signature
Ensures the token hasn’t been tampered with:
Implementation in Zyeta
Token Generation
When a user logs in successfully, the system generates a JWT:
The token contains:
- User ID (
id
) - Expiration time (
exp
) - No sensitive information like passwords
Token Validation
Every protected endpoint uses the JWTBearer
dependency for validation:
This middleware:
- Extracts the token from the Authorization header
- Verifies the token signature using the secret key
- Checks if the token has expired
- Returns the decoded payload containing user information
Using JWT in Requests
Client applications must include the JWT in the Authorization header:
JWT and RBAC Integration
JWTs work in conjunction with the Role-Based Access Control (RBAC) system:
- The JWT establishes user identity
- The RBAC middleware uses this identity to determine:
- The user’s role in the requested organization
- Permissions associated with that role
- Whether the user can perform the requested action
JWT Configuration
Zyeta’s JWT implementation can be configured through environment variables:
WebSocket Authentication
For WebSocket connections, JWTs are passed as query parameters:
The server validates these tokens using the same mechanism:
Security Considerations
Zyeta’s JWT implementation follows these security best practices:
- Secret Key Protection: The JWT secret is securely stored and never exposed
- Short Expiration Times: Tokens expire quickly to limit the damage of token theft
- No Sensitive Data: Tokens never contain sensitive user information
- HTTPS Only: JWTs are only transmitted over encrypted connections
- Signature Validation: All tokens are cryptographically verified
Troubleshooting
Next Steps
- Authentication Overview: Learn about the complete authentication system
- Invitation Flow: How users join organizations via invitations
- Role-Based Access Control: Understanding permission management
Was this page helpful?