From b459a1dbd43af44ce20fbf61ed98331a77dd6987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Papp?= Date: Wed, 18 Jun 2025 20:32:35 +0200 Subject: [PATCH] Support new login payload on Client --- src/client.js | 38 +++++++++++++++++++++++++++++++------- src/client/auth.js | 7 +++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/client.js b/src/client.js index 472a777..7c05b39 100644 --- a/src/client.js +++ b/src/client.js @@ -141,19 +141,43 @@ class Client extends Connection { this.status = ClientStatus.Authenticating this.createClientChain(null, this.options.offline) - const chain = [ - this.clientIdentityChain, // JWT we generated for auth - ...this.accessToken // Mojang + Xbox JWT from auth - ] + const useNewLogin = true // TODO: mcdata feature + let encodedLoginPayload - const encodedChain = JSON.stringify({ chain }) + if (useNewLogin) { + const authType = this.options.offline + ? auth.AuthenticationType.SelfSigned + : auth.AuthenticationType.Full - debug('Auth chain', chain) + // TODO: implement the new login payload (Token field) + // Send the legacy token chain for now + const chain = [ + this.clientIdentityChain, + ...this.accessToken + ] + + encodedLoginPayload = JSON.stringify({ + AuthenticationType: authType, + Token: '', + Certificate: JSON.stringify({ chain }), // Deprecated legacy certificate chain + }) + + debug('Login payload', encodedLoginPayload) + } else { + const chain = [ + this.clientIdentityChain, // JWT we generated for auth + ...this.accessToken // Mojang + Xbox JWT from auth + ] + + encodedLoginPayload = JSON.stringify({ chain }) + + debug('Auth chain', chain) + } this.write('login', { protocol_version: this.options.protocolVersion, tokens: { - identity: encodedChain, + identity: encodedLoginPayload, client: this.clientUserChain } }) diff --git a/src/client/auth.js b/src/client/auth.js index 7a07d83..3703379 100644 --- a/src/client/auth.js +++ b/src/client/auth.js @@ -5,6 +5,12 @@ const debug = require('debug')('minecraft-protocol') const { uuidFrom } = require('../datatypes/util') const { RealmAPI } = require('prismarine-realms') +const AuthenticationType = { + Full: 0, // The player's own token + Guest: 1, // Split screen sessions, the player is using the host's token + SelfSigned: 2, // Not authenticated +} + function validateOptions (options) { if (!options.profilesFolder) { options.profilesFolder = path.join(minecraftFolderPath, 'nmp-cache') @@ -113,6 +119,7 @@ function postAuthenticate (client, profile, chains) { } module.exports = { + AuthenticationType, createOfflineSession, authenticate, realmAuthenticate