hytale-says/scripts/sign-token.ts
devilreef 65f900169b feat: add Hono API with JWT authentication
- Implement REST API using Hono framework with token-based auth
- Add JWT middleware for scope-based access control
- Create version endpoints: launcher, downloader, patches, server
- Add account lookup endpoints (by UUID or username)
- Fetch server software with signed URLs and full version data
- Add token signing utility script for testing
- Support configurable account UUID for game session creation
- Integrate API server with existing module system

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-17 00:24:27 +06:00

34 lines
794 B
TypeScript

import jwt from 'jsonwebtoken'
import process from 'node:process'
const args = process.argv.slice(2)
let scopes = 'admin'
let expirationHours = 24
for (let i = 0; i < args.length; i++) {
if (args[i] === '--scope' && args[i + 1]) {
scopes = args[i + 1]
i++
}
else if (args[i] === '--exp' && args[i + 1]) {
const expStr = args[i + 1]
const match = expStr.match(/^(\d+)h?$/)
if (match) {
expirationHours = parseInt(match[1], 10)
}
i++
}
}
const jwtSecret = process.env.JWT_SECRET || 'your-secret-key'
const payload = {
scope: scopes,
sub: 'test-client',
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + (expirationHours * 3600),
}
const token = jwt.sign(payload, jwtSecret, { algorithm: 'HS256' })
console.log(token)