Added authlib support
This commit is contained in:
parent
a7cf6ad5a1
commit
a3eb5ee70c
@ -18,3 +18,7 @@ SUPPORT_MOJANG_FALLBACK=FALSE #[no_mojang_namespace]
|
||||
SUPPORT_MOJANG_TELEMETRY_BLOCKER=TRUE #[enable_mojang_anti_features]
|
||||
SUPPORT_PROFILE_KEY=TRUE #[enable_profile_key]
|
||||
SUPPORT_ONLY_DEFAULT_USERNAME=true #[username_check]
|
||||
SUPPORT_REGISTER=TRUE
|
||||
REGISTER_ENDPOINT="/register"
|
||||
HOMEPAGE_URL=
|
||||
SERVER_NAME="Yggdrasil"
|
||||
@ -3,7 +3,7 @@ const globals = require("globals")
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
ignores: ["node_modules", "logs", "coverage", ".env", "*.log"],
|
||||
ignores: ["node_modules", "data", "logs", "coverage", ".env", "*.log"],
|
||||
},
|
||||
js.configs.recommended,
|
||||
{
|
||||
|
||||
17
routes/index.js
Normal file
17
routes/index.js
Normal file
@ -0,0 +1,17 @@
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const utils = require("../modules/utils")
|
||||
const serverService = require("../services/serverService")
|
||||
|
||||
if (utils.isTrueFromDotEnv("SUPPORT_AUTHLIB_INJECTOR")) {
|
||||
router.get("", (req, res) => {
|
||||
const hostname = req.hostname
|
||||
const metadata = serverService.getServerMetadata(hostname)
|
||||
res.header("X-Authlib-Injector-Date", new Date().toISOString())
|
||||
return res.status(200).json(metadata)
|
||||
})
|
||||
} else {
|
||||
router.get("", (req, res, next) => next())
|
||||
}
|
||||
|
||||
module.exports = router
|
||||
39
services/serverService.js
Normal file
39
services/serverService.js
Normal file
@ -0,0 +1,39 @@
|
||||
const certs = require("../modules/certificatesManager")
|
||||
const utils = require("../modules/utils")
|
||||
const package = require("../package.json")
|
||||
|
||||
function getServerMetadata(hostname) {
|
||||
const keys = certs.getKeys()
|
||||
const publicKeyPEM = keys.playerCertificateKeys.public
|
||||
|
||||
const serverMeta = {
|
||||
meta: {
|
||||
serverName: process.env.SERVER_NAME || "Yggdrasil Server",
|
||||
implementationName: package.name,
|
||||
implementationVersion: package.version,
|
||||
|
||||
"feature.legacy_skin_api": utils.isTrueFromDotEnv("SUPPORT_LEGACY_SKIN_API"),
|
||||
"feature.no_mojang_namespace": utils.isTrueFromDotEnv("SUPPORT_MOJANG_FALLBACK"),
|
||||
"feature.enable_mojang_anti_features": utils.isTrueFromDotEnv("SUPPORT_MOJANG_TELEMETRY_BLOCKER"),
|
||||
"feature.enable_profile_key": utils.isTrueFromDotEnv("SUPPORT_PROFILE_KEY"),
|
||||
"feature.username_check": utils.isTrueFromDotEnv("SUPPORT_ONLY_DEFAULT_USERNAME"),
|
||||
|
||||
links: {
|
||||
homepage: process.env.HOMEPAGE_URL || `http://${hostname}`,
|
||||
}
|
||||
},
|
||||
skinDomains: [
|
||||
hostname,
|
||||
`.${hostname}`
|
||||
],
|
||||
signaturePublickey: publicKeyPEM
|
||||
}
|
||||
if (utils.isTrueFromDotEnv("SUPPORT_REGISTER")) {
|
||||
serverMeta.meta.links.register = process.env.REGISTER_ENDPOINT || `http://${hostname}/register`
|
||||
}
|
||||
return serverMeta
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getServerMetadata
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user