mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

Cannot connect using Microsoft | "The user could not be authenticated or user interaction is required."

Open wAIfu-DEV opened this issue 6 months ago • 4 comments

  • [x] The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.28.0
  • server/LAN: vanilla/spigot/paper 1.20.4
  • node: 20.9.0

Detailed description of a problem

I am trying to login using Microsoft in order to display the skin of the alt account that I own. offline mode works perfectly, however microsoft login seems impossible.

For context on the exact setup I am using, I have my main account (another one) connected using the minecraft launcher, and running on the same PC would be the bot using an alt account.

This isn't a breaking bug considering I can still use the offline mode, but it prevents me from seeing the bot using a specific skin (mind you if you have a solution for that specific problem I'm taking)

What did you try yet?

I tried:

  • auth: "microsoft" and username being the actual account username, with and without password
  • auth: "microsoft" and username being the mail address of the account, with and without password

Your current code

const bot = mineflayer.createBot({
    host: "host.server.com",
    port: portNum,
    username: "[email protected]", // or username: "UserName"
    password: "xxxxxxxx" // or undef
    version: "1.20.4",
    auth: "microsoft",
    profilesFolder: "./cache",
})

Error Messages

In the case of using username / email + no password I get:

[msa] First time signing in. Please authenticate now:
To sign in, use a web browser to open the page https://www.microsoft.com/link and use the code XXXXXX or visit http://microsoft.com/link?otc=XXXXXX
Error: Failed to acquire authorization code from device token (invalid_grant) - The user could not be authenticated or user interaction is required. The user must sign in again and if needed grant the client application access to the requested scope.
    at C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\TokenManagers\LiveTokenManager.js:137:23
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async LiveTokenManager.authDeviceCode (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\TokenManagers\LiveTokenManager.js:131:23)
    at async MicrosoftAuthFlow.getMsaToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:103:19)
    at async retry.msa.forceRefresh (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:167:24)
    at async retry (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:22:20)
    at async MicrosoftAuthFlow.getXboxToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:166:12)
    at async retry.xbl.forceRefresh (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:195:22)
    at async retry (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:22:20)
    at async MicrosoftAuthFlow.getMinecraftJavaToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:194:7)
Error: Failed to acquire authorization code from device token (invalid_grant) - The provided value for the input parameter 'device_code' has already been used.
    at C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\TokenManagers\LiveTokenManager.js:137:23
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async LiveTokenManager.authDeviceCode (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\TokenManagers\LiveTokenManager.js:131:23)
    at async MicrosoftAuthFlow.getMsaToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:103:19)
    at async retry.msa.forceRefresh (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:167:24)
    at async retry (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:22:20)
    at async MicrosoftAuthFlow.getXboxToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:166:12)
    at async retry.xbl.forceRefresh (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:195:22)
    at async retry (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:22:20)
    at async MicrosoftAuthFlow.getMinecraftJavaToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:194:7)

This happens even though I get redirected to a page saying "All done! You're now signed in to Minecraft for Nintendo Switch. You can now safely close this window.", I tried with both Brave and Chrome and both failed.

When using the email / username + password I get:

Sign in failed, try removing the password field

XboxReplayError: Invalid credentials.
    at Object.unauthorized (C:\Users\x\Desktop\mineflayerTest\node_modules\@xboxreplay\errors\dist\index.js:25:74)
    at C:\Users\x\Desktop\mineflayerTest\node_modules\@xboxreplay\xboxlive-auth\dist\core\live\index.js:71:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async XboxTokenManager.doReplayAuth (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\TokenManagers\XboxTokenManager.js:123:31)
    at async MicrosoftAuthFlow.getXboxToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:160:20)
    at async retry.xbl.forceRefresh (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:195:22)
    at async retry (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:26:14)
    at async MicrosoftAuthFlow.getMinecraftJavaToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:194:7)
    at async Object.authenticate (C:\Users\x\Desktop\mineflayerTest\node_modules\minecraft-protocol\src\client\microsoftAuth.js:22:58) {
  __XboxReplay__: true,
  details: { statusCode: 401, reason: 'UNAUTHORIZED' }
}
XboxReplayError: Invalid credentials.
    at Object.unauthorized (C:\Users\x\Desktop\mineflayerTest\node_modules\@xboxreplay\errors\dist\index.js:25:74)
    at C:\Users\x\Desktop\mineflayerTest\node_modules\@xboxreplay\xboxlive-auth\dist\core\live\index.js:71:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async XboxTokenManager.doReplayAuth (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\TokenManagers\XboxTokenManager.js:123:31)
    at async MicrosoftAuthFlow.getXboxToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:160:20)
    at async retry.xbl.forceRefresh (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:195:22)
    at async retry (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:26:14)
    at async MicrosoftAuthFlow.getMinecraftJavaToken (C:\Users\x\Desktop\mineflayerTest\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:194:7)
    at async Object.authenticate (C:\Users\x\Desktop\mineflayerTest\node_modules\minecraft-protocol\src\client\microsoftAuth.js:22:58) {
  __XboxReplay__: true,
  details: { statusCode: 401, reason: 'UNAUTHORIZED' }
}

wAIfu-DEV avatar May 18 '25 20:05 wAIfu-DEV

This error means the Microsoft/Xbox login you're using for your Mineflayer bot has invalid credentials. Here's how to fix it:

🔧 Fix Steps: Double-check your credentials Make sure you're using the correct email and password. Microsoft accounts might also have:

2FA (two-factor authentication) enabled

Security updates or locked access due to suspicious activity

Don't pass the password directly If you're using the new Microsoft auth flow, you shouldn't include the password field in your bot code. Instead, use auth: 'microsoft' and let it open a browser to log in (first time only).

Example:

js Copy Edit const bot = mineflayer.createBot({ host: 'server.ip', port: 25565, auth: 'microsoft', // no username or password }); Clear cached auth files Sometimes cached login tokens break things. Try deleting the .minecraft or .prismarine folders in your project or user folder, or re-authenticate manually.

Make sure it's a Microsoft account Mojang accounts no longer work — it must be migrated to Microsoft.

johnpauladattu2 avatar May 21 '25 12:05 johnpauladattu2

Most likely a 2fa problem

johnpauladattu2 avatar May 21 '25 12:05 johnpauladattu2

Alright, so I added 2FA to my account and now it works without an issue, quite confusing. The default behavior for new microsoft accounts is to have 2FA turned off so others might be affected. Will keep this open in case anything can be done about it on the side of this project.

wAIfu-DEV avatar May 21 '25 17:05 wAIfu-DEV

And when I mean works without an issue, I mean the auth flow where you have to go to http://microsoft.com/link?otc=XXXXXX haven't yet tested with plain creds

wAIfu-DEV avatar May 21 '25 17:05 wAIfu-DEV