Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mineflayer error: Cant Authenticate with Microsoft #10049

Open
link-discord opened this issue Apr 7, 2024 · 5 comments
Open

Mineflayer error: Cant Authenticate with Microsoft #10049

link-discord opened this issue Apr 7, 2024 · 5 comments
Labels
bug Something isn't working needs repro Needs an example to reproduce node.js Compatibility with Node.js APIs stale

Comments

@link-discord
Copy link

link-discord commented Apr 7, 2024

What version of Bun is running?

1.1.2+c8d072c2a

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

Run this code with the mineflayer package installed and you get an error when you set the auth parameter to 'microsoft' like in the code below.

const { createBot } = require('mineflayer')

const bot = createBot({
    username: 'Bot',
    host: 'localhost',
    auth: 'microsoft',
    version: '1.19.4',
    port: 25565
})

The code doesn't work because somewhere down the line the code depends on the nodejs crypto module to run this function:

crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' })

The function doesn't return the correct type though.

What is the expected behavior?

The code is supposed to prompt me for a microsoft login and when that is done, the bot should join the microsoft server I setup on my pc that is open on port 25565

What do you see instead?

PS C:\Users\Link\Downloads\mc> bun run index.js
 7 |         return {
 8 |             kty: 'oct',
 9 |             k: base64url(key),
10 |         };
11 |     }
12 |     if (!isCryptoKey(key)) {
                            ^
TypeError: Key must be one of type CryptoKey or Uint8Array. Received an instance of KeyObject
      at C:\Users\Link\Downloads\mc\node_modules\jose\dist\browser\runtime\key_to_jwk.js:12:24
      at keyToJWK (C:\Users\Link\Downloads\mc\node_modules\jose\dist\browser\runtime\key_to_jwk.js:5:25)
      at exportJWK (C:\Users\Link\Downloads\mc\node_modules\jose\dist\browser\key\export.js:10:33)
      at new XboxTokenManager (C:\Users\Link\Downloads\mc\node_modules\prismarine-auth\src\TokenManagers\XboxTokenManager.js:25:5)
      at initTokenManagers (C:\Users\Link\Downloads\mc\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:72:20)
      at new MicrosoftAuthFlow (C:\Users\Link\Downloads\mc\node_modules\prismarine-auth\src\MicrosoftAuthFlow.js:35:10)
      at C:\Users\Link\Downloads\mc\node_modules\minecraft-protocol\src\client\microsoftAuth.js:21:47
      at authenticate (C:\Users\Link\Downloads\mc\node_modules\minecraft-protocol\src\client\microsoftAuth.js:18:30)
      at createClient (C:\Users\Link\Downloads\mc\node_modules\minecraft-protocol\src\createClient.js:52:25)
      at createBot (C:\Users\Link\Downloads\mc\node_modules\mineflayer\lib\loader.js:98:35)

Additional information

Mineflayer is a library that can be used to make bots for the game Minecraft. A link to Mineflayers repo can be found here: https://github.com/PrismarineJS/mineflayer

@link-discord link-discord added the bug Something isn't working label Apr 7, 2024
@link-discord
Copy link
Author

Sorry I noticed the generateKeyPairSync function does actually exist now, but it doesn't change the issue.

@Electroid Electroid added node.js Compatibility with Node.js APIs needs repro Needs an example to reproduce labels Apr 8, 2024
@GustavoWidman
Copy link

This is due to an incompatibility with the library "jose" and bun's KeyObject, mineflayer or prismarineJS are not at fault.

@GustavoWidman
Copy link

GustavoWidman commented Apr 8, 2024

This is due to an incompatibility with the library "jose" and bun's KeyObject, mineflayer or prismarineJS are not at fault.

Although this can be fixed on the prismarine-auth side by adding a compat layer like so:

prismarine-auth/src/TokenManagers/XboxTokenManager.js

change constructor of class XboxTokenManager to this

constructor (ecKey, cache) {
    this.key = ecKey

    importSPKI(ecKey.publicKey.export({ type: 'spki', format: 'pem' }), 'ES256', { extractable: true }).then(pubKey => {
      exportJWK(pubKey).then(jwk => {
        this.jwk = { ...jwk, alg: 'ES256', use: 'sig' }
      })
    })

    this.cache = cache

    this.headers = { 'Cache-Control': 'no-store, must-revalidate, no-cache', 'x-xbl-contract-version': 1 }
  }

and import the "importSPKI" function at the top of the file with the "exportJWK"

const { exportJWK, importSPKI } = require('jose')

@NoNameLmao
Copy link

exact same issue, bun v1.1.8 on Windows 11

Copy link
Contributor

github-actions bot commented Aug 8, 2024

This issue is stale and may be closed due to inactivity. If you're still running into this, please leave a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs repro Needs an example to reproduce node.js Compatibility with Node.js APIs stale
Projects
None yet
Development

No branches or pull requests

4 participants