node-minecraft-protocol/examples/client_microsoft_auth/client_msal_auth.js
extremeheat 8f2a027812
Msa device code auth (#806)
* initial msa work

* rm debug code

* Update package.json

* lint, seperate constants, create missing msa cache

* support multiple profiles

* lint

* use shared constants

* fix path issues

* fix token variable

* fix caching msa profile data

* switch clientId to one from microsoft

* store caches in .minecraft, fallback to dev code auth when user+pass fails

* update electron demo, fix error handling, add docs

* fix caching dir

* fix lint

* move to class scope, token fixes

* retry on fail, terminology fixes

* fix promise bug

* cleanup
2021-01-30 01:21:03 +01:00

32 lines
1.1 KiB
JavaScript

'use strict'
const mc = require('minecraft-protocol')
if (process.argv.length < 4 || process.argv.length > 6) {
console.log('Usage : node echo.js <host> <port> <email>')
process.exit(1)
}
const client = mc.createClient({
host: process.argv[2],
port: parseInt(process.argv[3]),
username: process.argv[4], // your microsoft account email
// password: process.argv[5], // your microsoft account password
auth: 'microsoft' // This option must be present and set to 'microsoft' to use Microsoft Account Authentication. Failure to do so will result in yggdrasil throwing invalid account information.
})
client.on('connect', function () {
console.info('connected')
})
client.on('disconnect', function (packet) {
console.log('disconnected: ' + packet.reason)
})
client.on('chat', function (packet) {
const jsonMsg = JSON.parse(packet.message)
if (jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') {
const username = jsonMsg.with[0].text
const msg = jsonMsg.with[1]
if (username === client.username) return
client.write('chat', { message: msg })
}
})