๐ ๏ธ Twilio Rust Video Token & Stripe Checkout Server
This is a lightweight, production-ready Rust-based Actix Web server that:
- ๐ Generates Twilio Video JWT tokens for secure room access.
- ๐ณ Optionally integrates with Stripe Checkout for paid video sessions.
- ๐ฑ Uses
.envfor configuration and supports feature flags for flexible builds.
๐ Features
- โ
Twilio Video token endpoint (
/api/generate-token) - โ
Optional Stripe checkout endpoint (
/api/create-checkout-session) - ๐งฉ Modular structure (Twilio & Stripe code separated)
- ๐ JWTs with video grants & expiration
- โ๏ธ Configurable via
.env - ๐ฆ Single-binary friendly (no Redis required)
- ๐ Ready to deploy behind Nginx, Caddy, etc.
- ๐ Uses rusttls instead of openssl, as such it is easy to cross-compile
- โ๏ธ generate the Debian x86_64 binaries e.g. macos)
๐ฆ Requirements
- Rust 2021+
- Twilio account (API SID, secret)
- Optional: Stripe account (secret key)
๐ง Setup
-
Clone this repo
-
Create
.envfile:SERVER_PORT=8888 USE_STRIPE=false GOVERNOR_BURST=5 GOVERNOR_PER_SECOND=2 # 60*60s = 3,600s => 1h TOKEN_EXPIRY=3600 # Twilio configuration TWILIO_ACCOUNT_SID=ACxxx... TWILIO_API_KEY_SID=SKxxx... TWILIO_API_KEY_SECRET=your_secret # Stripe (optional) USE_STRIPE=true STRIPE_SECRET_KEY=sk_test_xxx STRIPE_CURRENCY=EUR STRIPE_AMOUNT=1000 STRIPE_PRODUCT_NAME=Private Video Session STRIPE_SUCCESS_URL=https://yourdomain.com/success STRIPE_CANCEL_URL=https://yourdomain.com/cancel
โถ๏ธ Run the Server
- Without Stripe support:
- With Stripe support:
optional pass the .env file e.g..env.production
๐ธ With Stripe support
cargo run --features stripe optional pass the .env file e.g. .env.production
๐ API
GET /api/generate-token
Generates a Twilio JWT token for the given identity and room.
Query Parameters: โข identity โ The user name โข roomName โ Room to join
Example: GET /api/generate-token?identity=alice&roomName=room1
Optional Stripe support
POST /api/create-checkout-session (requires Stripe + USE_STRIPE=true)
Creates a Stripe Checkout session.
JSON Body:
{
"identity": "alice",
"room_name": "room1"
}
Returns:
{ "url": "https://checkout.stripe.com/session/..." }
๐งช Testing
You can test endpoints using Postman or curl:
curl "http://localhost:6666/api/generate-token?identity=test&roomName=myroom"
๐ก๏ธ Security
โข Tokens expire after 1 hour default, but configurable in seconds in .env TOKEN_EXPIRY โข Rate-limiting can be added via actix-governor
๐ Project Structure
tiny_twilio_stripe/
โโโ src/
โ โโโ main.rs # Actix server entry point
โ โโโ twilio/
โ โ โโโ mod.rs
โ โ โโโ twilio_token.rs
โ โโโ stripe/
โ โโโ mod.rs
โ โโโ stripe_checkout.rs
โโโ .env
โโโ Cargo.toml
โโโ README.md