Register /uds-auth/qr-start and fix crypto imports for QR login.

This commit is contained in:
oliver 2026-09-08 01:54:42 +08:00
parent 3aca99ca93
commit c9ca785155

View file

@ -8,6 +8,7 @@ import { readFile, writeFile } from 'node:fs/promises'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { createRequire } from 'node:module'
import { createHash, randomBytes } from 'node:crypto'
const __dirname = dirname(fileURLToPath(import.meta.url))
const require = createRequire(import.meta.url)
@ -144,8 +145,8 @@ async function loadQRCodeLib() {
function createQrChallenge(config = _currentConfig || {}) {
const loginSystemCode = String(config.loginSystemCode || CONFIG_DEFAULTS.loginSystemCode)
const originSystemCode = String(config.originSystemCode || '')
const qrCodeKey = crypto.randomBytes(16).toString('hex')
const qrCodeValue = crypto.randomBytes(16).toString('hex')
const qrCodeKey = randomBytes(16).toString('hex')
const qrCodeValue = randomBytes(16).toString('hex')
const qrCodeStr = `TwoDIMAuth:${qrCodeKey}:${qrCodeValue}`
return { qrCodeStr, qrCodeKey, qrCodeValue, loginSystemCode, originSystemCode }
}
@ -511,6 +512,11 @@ async function handleAllRoutes(req, res) {
return await handleQRCode(req, res)
}
// QR 挑战(扫码登录入口)
if (pathname === '/uds-auth/qr-start' && (method === 'GET' || method === 'POST')) {
return await handleQrStart(req, res)
}
// QR 代理
if (pathname === '/uds-auth/qr-proxy' && method === 'POST') {
return await handleQRProxy(req, res)