π Status: Production Ready π‘οΈ Service Role: Identity + Entitlement Authority
bus-auth is the central gateway for BUS Core Pro. It operates on the philosophy of "Gate Key, Not Hall Monitor". The service is responsible for:
-
π Identity: Issuing tokens that prove email ownership.
-
ποΈ Entitlements: Verifying subscription status via Stripe and issuing signed entitlement tokens.
-
β³ Persistence: Clients are encouraged to trust token expiry (
exp) for offline grace periods.
-
β‘ Runtime: Cloudflare Workers
-
π₯ Framework: Hono (TypeScript)
-
ποΈ Database: Cloudflare D1
-
β‘ Cache: Cloudflare KV
-
π³ Billing: Stripe (Checkout + Webhooks)
-
βοΈ Signing: Ed25519 Asymmetric Signing
| Method | Path | Purpose |
|---|---|---|
π₯ GET |
/health |
Service health check |
|
| πͺ POST | /auth/magic/start | Trigger a 6-digit magic code email
|
| β
POST | /auth/magic/verify | Exchange code for an Identity Token
|
| π POST | /entitlement | Public eligibility check
|
| π GET | /.well-known/identity-public-key | Verification key for Identity Tokens
|
| π GET | /.well-known/entitlement-public-key | Verification key for Entitlement Tokens
|
Requires a valid Bearer Identity Token
| Method | Path | Purpose |
|---|---|---|
π POST |
/entitlement/token |
Mint a signed Entitlement Token |
|
| π POST | /checkout/session | Create a Stripe Checkout session
|
-
π’ Magic Codes: 6-digit numeric codes with a 15-minute expiry.
-
β±οΈ Token TTL: Identity tokens are valid for 7 days.
-
ποΈ Entitlement Grace: Tokens include a built-in 7-day grace period beyond the
current_period_endto handle intermittent connectivity. -
ποΈ Verification: All tokens are signed using Ed25519.
Ensure the following variables are defined in your environment:
- π§
EMAIL_FROM: The sender address for magic links. - π
CHECKOUT_SUCCESS_URL/CHECKOUT_CANCEL_URL: Stripe redirect paths. - π
IDENTITY_PUBLIC_KEY/ENTITLEMENT_PUBLIC_KEY: The public half of your Ed25519 pairs.
The following secrets must be set via wrangler secret put:
- ποΈ
IDENTITY_PRIVATE_KEY/ENTITLEMENT_PRIVATE_KEY - π³
STRIPE_SECRET_KEY/STRIPE_WEBHOOK_SECRET - βοΈ
RESEND_API_KEY - π
ADMIN_API_KEY