Voxelum / minecraft-launcher-core-node

Provide packages to install Minecraft, launch Minecraft and more to build launcher with NodeJs/Electron!
https://docs.xmcl.app/en/core/
MIT License
174 stars 25 forks source link

Launch game authorized #243

Closed SomeBody16 closed 1 year ago

SomeBody16 commented 1 year ago

I'm using minecraft-auth for authorization (MicrosoftAccount)

My code:

console.log(config.data.account)
await launch({
  gamePath: config.modpackDir(modpack.name),
  javaPath: 'javaw',
  version: `${modpack.mcVersion}-forge-${modpack.forgeVersion}`,
  extraExecOption: {
    detached: true,
  },
  accessToken: config.data.account.accessToken,
  server: modpack.server,
})

console.log result:

MicrosoftAccount {
  properties: {},
  accessToken: 'VALID_ACCESS_TOKEN',
  type: 'microsoft',
  alternativeValidation: true,
  authCode: 'AUTH_CODE',
  refreshToken: 'VALID_REFTESH_TOKEN',
  ownership: true,
  username: 'My username',
  uuid: 'My uuid',
  profile: {
    id: 'my id',
    name: 'My username',
    skins: [ [Object] ],
    capes: [ [Object], [Object] ]
  }
}

And games start without problems Buuuut In game my username is Steve and I can't join any premium server

Sooo How to start the game with accessToken from AzureApp to be properly authorized?

ci010 commented 1 year ago

You need to assign gameProfile to the LaunchOptions

await launch({
  gameProfile: config.data.account.profile,
  gamePath: config.modpackDir(modpack.name),
  javaPath: 'javaw',
  version: `${modpack.mcVersion}-forge-${modpack.forgeVersion}`,
  extraExecOption: {
    detached: true,
  },
  accessToken: config.data.account.accessToken,
  server: modpack.server,
})
SomeBody16 commented 1 year ago

That worked! Thank you!