Installation
Package Information
- Version: 0.1.1
- License: MIT OR Apache-2.0
- Repository: github:moq-dev/moq
- Dependencies:
jose,zod,@hexagon/base64
Overview
MoQ relays typically require JWT authentication tokens with specific claims. This package makes it easy to generate and validate tokens in JavaScript/TypeScript.Generating Tokens
Basic Usage
With Expiration
"1h"- 1 hour"30m"- 30 minutes"24h"- 24 hours"7d"- 7 days
With Custom Claims
Generating Keys
Using the Key API
Importing Existing Keys
Validating Tokens
Token Claims
Standard Claims
Role-based Access
Using with MoQ Lite
Publishing
Subscribing
CLI Tool
The package includes a CLI tool for generating tokens:CLI Usage
Algorithm Support
The library uses ES256 (ECDSA with P-256 and SHA-256) for signing tokens. This is a widely supported algorithm with good security properties.Security Best Practices
Protect Private Keys
Use Short Expiration Times
Validate Tokens Server-Side
Use HTTPS
Always transmit tokens over HTTPS to prevent interception:Complete Example
Here’s a complete example generating keys, creating tokens, and connecting:Next Steps
@moq/lite
Use tokens with the MoQ protocol
@moq/publish
Publish streams with authentication
@moq/watch
Watch streams with authentication
JWT.io
Learn more about JWT tokens