mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
Provide interface for using not at all supported alternative accounts. (#1026)
* Handle auth potentially being an function * "Simple" example of how in theroy it would work * Add package.json * Fix lint * add type declarations * Remove mcleaks example * Add doc changes * adjust warning * Fix lint from rebase manual edit.
This commit is contained in:
parent
e079e9b0f6
commit
60379eb7d2
6 changed files with 87 additions and 23 deletions
|
@ -93,7 +93,7 @@ Returns a `Client` instance and perform login.
|
||||||
`options` is an object containing the properties :
|
`options` is an object containing the properties :
|
||||||
* username
|
* username
|
||||||
* port : default to 25565
|
* port : default to 25565
|
||||||
* auth : the type of account to use, either `microsoft`, `mojang`, or `offline`. default to 'offline'
|
* auth : the type of account to use, either `microsoft`, `mojang`, `offline` or `function (client, options) => void`. defaults to 'offline'.
|
||||||
* password : can be omitted
|
* password : can be omitted
|
||||||
* (microsoft account) leave this blank to use device code auth. If you provide
|
* (microsoft account) leave this blank to use device code auth. If you provide
|
||||||
a password, we try to do username and password auth, but this does not always work.
|
a password, we try to do username and password auth, but this does not always work.
|
||||||
|
|
25
docs/FAQ.md
25
docs/FAQ.md
|
@ -1,20 +1,29 @@
|
||||||
## FAQ
|
# FAQ
|
||||||
|
|
||||||
This Frequently Asked Question document is meant to help people for the most common things.
|
This Frequently Asked Question document is meant to help people for the most common things.
|
||||||
|
|
||||||
### How to hide errors ?
|
## How to hide errors ?
|
||||||
|
|
||||||
Use `hideErrors: true` in createClient options
|
Use `hideErrors: true` in createClient options
|
||||||
You may also choose to add these listeners :
|
You may also choose to add these listeners :
|
||||||
|
|
||||||
```js
|
```js
|
||||||
client.on('error', () => {})
|
client.on('error', () => {})
|
||||||
client.on('end', () => {})
|
client.on('end', () => {})
|
||||||
```
|
```
|
||||||
|
|
||||||
### How can I make a proxy with this ?
|
## How can I make a proxy with this ?
|
||||||
|
|
||||||
* Check out our WIP proxy lib https://github.com/PrismarineJS/prismarine-proxy
|
* Check out our WIP proxy lib <https://github.com/PrismarineJS/prismarine-proxy>
|
||||||
* See this example https://github.com/PrismarineJS/node-minecraft-protocol/tree/master/examples/proxy
|
* See this example <https://github.com/PrismarineJS/node-minecraft-protocol/tree/master/examples/proxy>
|
||||||
* Read this issue https://github.com/PrismarineJS/node-minecraft-protocol/issues/712
|
* Read this issue <https://github.com/PrismarineJS/node-minecraft-protocol/issues/712>
|
||||||
* check out https://github.com/Heath123/pakkit
|
* check out <https://github.com/Heath123/pakkit>
|
||||||
* Check out this app https://github.com/wvffle/minecraft-packet-debugger
|
* Check out this app <https://github.com/wvffle/minecraft-packet-debugger>
|
||||||
|
|
||||||
|
## Can you support alternative auth methods?
|
||||||
|
|
||||||
|
Supporting alternative authentcation methods has been a long standing issue with Prismarine for awhile. We do add support for using your own custom authentication method by providing a function to the `options.auth` property. In order to keep the legitimacy of the project, and to prevent bad attention from Mojang, we will not be supporting any custom authentication methods in the official repositories.
|
||||||
|
|
||||||
|
It is up to the end user to support and maintain the authentication protocol if this is used as support in many of the official channels will be limited.
|
||||||
|
|
||||||
|
If you still wish to proceed, please make sure to throughly read and attempt to understand all implementations of the authentcation you wish to implement. Using an non-official authentication server can make you vulnerable to all different kinds of attacks which are not limited to insecure and/or malicious code! We will not be held responsible for anything you mess up.
|
||||||
|
|
41
examples/client_custom_auth/client_custom_auth.js
Normal file
41
examples/client_custom_auth/client_custom_auth.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const mc = require('minecraft-protocol')
|
||||||
|
|
||||||
|
const [, , host, port, username, password] = process.argv
|
||||||
|
if (!username || !password) {
|
||||||
|
console.log('Usage : node client_custom_auth.js <host> <port> <username/email> [<password>]')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = mc.createClient({
|
||||||
|
host,
|
||||||
|
port: parseInt(port),
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
sessionServer: '', // URL to your session server proxy that changes the expected result of mojang's seession server to mcleaks expected.
|
||||||
|
// For more information: https://github.com/PrismarineJS/node-yggdrasil/blob/master/src/Server.js#L19
|
||||||
|
auth: async (client, options) => {
|
||||||
|
// handle custom authentication your way.
|
||||||
|
|
||||||
|
// client.username = options.username
|
||||||
|
// options.accessToken =
|
||||||
|
return options.connect(client)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
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 })
|
||||||
|
}
|
||||||
|
})
|
10
examples/client_custom_auth/package.json
Normal file
10
examples/client_custom_auth/package.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "node-minecraft-protocol-example-client-custom-auth",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "A node-minecraft-protocol example",
|
||||||
|
"main": "client_custom_auth.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": ""
|
||||||
|
}
|
|
@ -34,19 +34,23 @@ function createClient (options) {
|
||||||
const client = new Client(false, version.minecraftVersion, options.customPackets, hideErrors)
|
const client = new Client(false, version.minecraftVersion, options.customPackets, hideErrors)
|
||||||
|
|
||||||
tcpDns(client, options)
|
tcpDns(client, options)
|
||||||
switch (options.auth) {
|
if (options.auth instanceof Function) {
|
||||||
case 'mojang':
|
options.auth(client, options)
|
||||||
console.warn('[deprecated] mojang auth servers no longer accept mojang accounts to login. convert your account.\nhttps://help.minecraft.net/hc/en-us/articles/4403181904525-How-to-Migrate-Your-Mojang-Account-to-a-Microsoft-Account')
|
} else {
|
||||||
auth(client, options)
|
switch (options.auth) {
|
||||||
break
|
case 'mojang':
|
||||||
case 'microsoft':
|
console.warn('[deprecated] mojang auth servers no longer accept mojang accounts to login. convert your account.\nhttps://help.minecraft.net/hc/en-us/articles/4403181904525-How-to-Migrate-Your-Mojang-Account-to-a-Microsoft-Account')
|
||||||
microsoftAuth.authenticate(client, options)
|
auth(client, options)
|
||||||
break
|
break
|
||||||
case 'offline':
|
case 'microsoft':
|
||||||
default:
|
microsoftAuth.authenticate(client, options)
|
||||||
client.username = options.username
|
break
|
||||||
options.connect(client)
|
case 'offline':
|
||||||
break
|
default:
|
||||||
|
client.username = options.username
|
||||||
|
options.connect(client)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (options.version === false) autoVersion(client, options)
|
if (options.version === false) autoVersion(client, options)
|
||||||
setProtocol(client, options)
|
setProtocol(client, options)
|
||||||
|
|
2
src/index.d.ts
vendored
2
src/index.d.ts
vendored
|
@ -101,7 +101,7 @@ declare module 'minecraft-protocol' {
|
||||||
export interface ClientOptions {
|
export interface ClientOptions {
|
||||||
username: string
|
username: string
|
||||||
port?: number
|
port?: number
|
||||||
auth?: 'mojang' | 'microsoft' | 'offline'
|
auth?: 'mojang' | 'microsoft' | 'offline' | ((client: Client, options: ClientOptions) => void)
|
||||||
password?: string
|
password?: string
|
||||||
host?: string
|
host?: string
|
||||||
clientToken?: string
|
clientToken?: string
|
||||||
|
|
Loading…
Reference in a new issue