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>
This commit is contained in:
parent
317c886529
commit
65f900169b
11 changed files with 489 additions and 0 deletions
34
scripts/sign-token.ts
Normal file
34
scripts/sign-token.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue