mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
add skipValidation flag for authentication
This commit is contained in:
parent
40102f6158
commit
297d40b17d
3 changed files with 22 additions and 17 deletions
|
@ -84,6 +84,7 @@ Returns a `Client` instance and perform login.
|
||||||
* version : 1.8 or 1.9 or false (to auto-negotiate): default to 1.8
|
* version : 1.8 or 1.9 or false (to auto-negotiate): default to 1.8
|
||||||
* customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example
|
* customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example
|
||||||
* hideErrors : do not display errors, default to false
|
* hideErrors : do not display errors, default to false
|
||||||
|
* skipValidation : do not try to validate given session, defaults to false
|
||||||
|
|
||||||
## mc.Client(isServer,version,[customPackets])
|
## mc.Client(isServer,version,[customPackets])
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ const UUID = require('uuid-1345')
|
||||||
|
|
||||||
module.exports = function (client, options) {
|
module.exports = function (client, options) {
|
||||||
const clientToken = options.clientToken || (options.session && options.session.clientToken) || UUID.v4().toString()
|
const clientToken = options.clientToken || (options.session && options.session.clientToken) || UUID.v4().toString()
|
||||||
|
const skipValidation = false || options.skipValidation
|
||||||
options.accessToken = null
|
options.accessToken = null
|
||||||
options.haveCredentials = options.password != null || (clientToken != null && options.session != null)
|
options.haveCredentials = options.password != null || (clientToken != null && options.session != null)
|
||||||
|
|
||||||
|
@ -21,23 +22,25 @@ module.exports = function (client, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.session) {
|
if (options.session) {
|
||||||
yggdrasil.validate(options.session.accessToken, function (err) {
|
if (!skipValidation) {
|
||||||
if (!err) { cb(null, options.session) } else {
|
yggdrasil.validate(options.session.accessToken, function (err) {
|
||||||
yggdrasil.refresh(options.session.accessToken, options.session.clientToken, function (err, accessToken, data) {
|
if (!err) { cb(null, options.session) } else {
|
||||||
if (!err) {
|
yggdrasil.refresh(options.session.accessToken, options.session.clientToken, function (err, accessToken, data) {
|
||||||
cb(null, data)
|
if (!err) {
|
||||||
} else if (options.username && options.password) {
|
cb(null, data)
|
||||||
yggdrasil.auth({
|
} else if (options.username && options.password) {
|
||||||
user: options.username,
|
yggdrasil.auth({
|
||||||
pass: options.password,
|
user: options.username,
|
||||||
token: clientToken
|
pass: options.password,
|
||||||
}, cb)
|
token: clientToken
|
||||||
} else {
|
}, cb)
|
||||||
cb(err, data)
|
} else {
|
||||||
}
|
cb(err, data)
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
yggdrasil.auth({
|
yggdrasil.auth({
|
||||||
user: options.username,
|
user: options.username,
|
||||||
|
|
1
src/index.d.ts
vendored
1
src/index.d.ts
vendored
|
@ -38,6 +38,7 @@ declare module 'minecraft-protocol' {
|
||||||
port?: number
|
port?: number
|
||||||
username: string
|
username: string
|
||||||
version?: string
|
version?: string
|
||||||
|
skipValidation?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Server extends EventEmitter {
|
export class Server extends EventEmitter {
|
||||||
|
|
Loading…
Reference in a new issue