v2.2.2 | Cloudflare Worker that handles OAuth authentication for the XIV Dye Tools ecosystem.
This Worker provides multi-provider OAuth authentication for the XIV Dye Tools web application. It supports both Discord and XIVAuth as authentication providers, with D1 database for user management and account merging.
๐ PKCE-Secured OAuth - Proof Key for Code Exchange for secure authorization ๐ซ JWT Issuance - JSON Web Tokens with HS256 signing ๐ Token Refresh - 24-hour grace period for expired token refresh ๐ CORS Support - Localhost allowed for development, configurable for production โก Edge Deployment - Global low-latency via Cloudflare Workers ๐ฎ XIVAuth Support - Login with FFXIV character (via XIVAuth.net) ๐๏ธ D1 Database - User management and account merging ๐ Account Merging - Link Discord and XIVAuth accounts automatically ๐ก๏ธ Security Hardened - Validated redirect URIs, API call timeouts, structured logging
| Endpoint | Method | Description |
|---|---|---|
/auth/discord |
GET | Start Discord OAuth flow (requires PKCE params) |
/auth/callback |
GET | Discord redirect handler |
/auth/callback |
POST | SPA token exchange (code + code_verifier) |
| Endpoint | Method | Description |
|---|---|---|
/auth/xivauth |
GET | Start XIVAuth OAuth flow (requires PKCE params) |
/auth/xivauth/callback |
GET | XIVAuth redirect handler |
/auth/xivauth/callback |
POST | SPA token exchange (code + code_verifier) |
| Endpoint | Method | Description |
|---|---|---|
/auth/refresh |
POST | Refresh JWT (24h grace period) |
/auth/me |
GET | Get user info from JWT (Bearer token) |
/auth/revoke |
POST | Logout (client-side token clear) |
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Frontend โ โ OAuth Worker โ โ Discord โ
โโโโโโโโฌโโโโโโโโ โโโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโ
โ โ โ
โ 1. Generate PKCE โ โ
โ code_verifier โ โ
โ code_challenge โ โ
โ โ โ
โ 2. GET /auth/discord โโโโโโโโโโโโโโโโโโโบโ
โ + code_challenge โ
โ โ โ
โ โโโโโโโ 3. Redirect โโค
โ โ with auth code โ
โ โ โ
โ 4. Exchange code โ โ
โ + code_verifier โ โ
โ โ โ
โโโโโโ 5. JWT โโโโโโโโโค โ
โ โ โ
- Node.js 18+
- Cloudflare account with Workers enabled
- Discord application with OAuth2 configured
-
Install dependencies:
npm install
-
Set up secrets:
wrangler secret put DISCORD_CLIENT_SECRET wrangler secret put XIVAUTH_CLIENT_SECRET # Optional for public client mode wrangler secret put JWT_SECRET # Generate with: openssl rand -hex 32
-
Set up D1 database:
wrangler d1 create xivdyetools-users # Update wrangler.toml with generated database ID wrangler d1 execute xivdyetools-users --file=./schema/users.sql --remote -
Start local development server:
npm run dev
| Command | Description |
|---|---|
npm run dev |
Start local dev server (localhost:8788) |
npm run deploy |
Deploy to Cloudflare |
npm run type-check |
TypeScript validation |
| Variable | Description |
|---|---|
ENVIRONMENT |
"production" or "development" |
DISCORD_CLIENT_ID |
Discord application client ID |
XIVAUTH_CLIENT_ID |
XIVAuth application client ID |
FRONTEND_URL |
Allowed CORS origin and redirect target |
WORKER_URL |
This worker's URL (for JWT issuer claim) |
JWT_EXPIRY |
Token lifetime in seconds (default: 3600) |
| Binding | Description |
|---|---|
DB |
D1 database for user management |
| Secret | Description |
|---|---|
DISCORD_CLIENT_SECRET |
Discord OAuth client secret |
XIVAUTH_CLIENT_SECRET |
XIVAuth OAuth client secret (optional for public client) |
JWT_SECRET |
Shared secret for HS256 JWT signing |
Issued tokens include:
{
"sub": "internal_user_uuid",
"username": "username",
"global_name": "Display Name",
"avatar": "avatar_hash",
"auth_provider": "discord|xivauth",
"discord_id": "discord_snowflake",
"xivauth_id": "xivauth_uuid",
"primary_character": {
"name": "Character Name",
"server": "Server Name",
"verified": true
},
"iss": "worker_url",
"iat": 1234567890,
"exp": 1234571490,
"jti": "unique_token_id"
}Note:
primary_characteris only included for XIVAuth users.
src/
โโโ index.ts # Hono app, middleware, route mounting
โโโ types.ts # TypeScript interfaces
โโโ handlers/
โ โโโ authorize.ts # GET /auth/discord - Initiates Discord OAuth
โ โโโ callback.ts # Discord token exchange, JWT issuance
โ โโโ xivauth.ts # XIVAuth OAuth endpoints
โ โโโ refresh.ts # Token refresh, user info, revoke
โโโ services/
โโโ jwt-service.ts # JWT creation/verification (Web Crypto API)
โโโ user-service.ts # D1 user management and account merging
schema/
โโโ users.sql # D1 database schema
- xivdyetools-web-app - Web app that uses this OAuth
- xivdyetools-presets-api - API that verifies these JWTs
MIT ยฉ 2025 Flash Galatine
See LICENSE for full details.
This is a fan-made tool and is not affiliated with or endorsed by Square Enix Co., Ltd. FINAL FANTASY is a registered trademark of Square Enix Holdings Co., Ltd.
Flash Galatine | Balmung (Crystal)
๐ฎ FFXIV: Lodestone Character ๐ Blog: Project Galatine ๐ป GitHub: @FlashGalatine ๐ฆ X / Twitter: @AsheJunius ๐บ Twitch: flashgalatine ๐ BlueSky: projectgalatine.com โค๏ธ Patreon: ProjectGalatine โ Ko-Fi: flashgalatine ๐ฌ Discord: Join Server
- Issues: GitHub Issues
- Discord: Join Server
Made with โค๏ธ for the FFXIV community