Support new login payload on Client

This commit is contained in:
Tamás Papp 2025-06-18 20:32:35 +02:00
commit b459a1dbd4
2 changed files with 38 additions and 7 deletions

View file

@ -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
}
})

View file

@ -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