minecraft-auth
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -5,3 +5,3 @@ import { Account } from "./Account"; | ||
constructor(); | ||
getAccount(index: number): Account; | ||
getAccount(index: number): Account | undefined; | ||
getAccountByUUID(uuid: string): Account | undefined; | ||
@@ -8,0 +8,0 @@ getAccountByName(name: string): Account | undefined; |
@@ -16,7 +16,4 @@ "use strict"; | ||
getAccountByUUID(uuid) { | ||
let acc = undefined; | ||
this.accountList.forEach((el) => { | ||
if (el.uuid === uuid) { | ||
acc = el; | ||
} | ||
const acc = this.accountList.find((el) => { | ||
return el.uuid === uuid; | ||
}); | ||
@@ -26,7 +23,4 @@ return acc; | ||
getAccountByName(name) { | ||
let acc = undefined; | ||
this.accountList.forEach((el) => { | ||
if (el.username === name) { | ||
acc = el; | ||
} | ||
const acc = this.accountList.find((el) => { | ||
return el.username === name; | ||
}); | ||
@@ -33,0 +27,0 @@ return acc; |
@@ -14,3 +14,3 @@ "use strict"; | ||
appID: "747bf062-ab9c-4690-842d-a77d18d4cf82", | ||
mode: "SPA" | ||
mode: "SPA", | ||
}; | ||
@@ -27,22 +27,40 @@ function setup(_config) { | ||
async function createServer(serverConfig) { | ||
// @ts-ignore | ||
const server = http_1.default.createServer(); | ||
await server.listen(serverConfig.port, serverConfig.host, () => { | ||
console.log(`MS Token Server is running on http://${serverConfig.host}:${serverConfig.port}`); | ||
return await new Promise((r, j) => { | ||
// @ts-ignore | ||
const server = http_1.default.createServer(); | ||
let _success = false; | ||
server.listen(serverConfig.port, serverConfig.host, function () { | ||
if (serverConfig.onstart) { | ||
serverConfig.onstart(serverConfig.host, serverConfig.port); | ||
} | ||
else { | ||
console.log(`MS Token Server is running on http://${serverConfig.host}:${serverConfig.port}`); | ||
} | ||
r(server); | ||
}); | ||
server.on("close", function () { | ||
if (serverConfig.onclose) { | ||
serverConfig.onclose(_success); | ||
} | ||
}); | ||
server.on("error", (err) => { | ||
j(err); | ||
}); | ||
server.fullClose = async function (success) { | ||
_success = success; | ||
if (server.serverTimeout) { | ||
clearTimeout(server.serverTimeout); | ||
server.serverTimeout = undefined; | ||
} | ||
await server.close(); | ||
}; | ||
return server; | ||
}); | ||
server.fullClose = async function () { | ||
await server.close(); | ||
}; | ||
return server; | ||
} | ||
async function _listenForCode(server, serverConfig) { | ||
return await new Promise((r, j) => { | ||
let _timeout = setTimeout(async () => { | ||
await server.fullClose(); | ||
j(undefined); | ||
server.serverTimeout = setTimeout(async () => { | ||
await server.fullClose(false); | ||
j("Timeout error"); | ||
}, serverConfig.timeout); | ||
server.fullClose = async function () { | ||
await server.close(); | ||
clearTimeout(_timeout); | ||
}; | ||
async function requestListener(req, res) { | ||
@@ -59,5 +77,10 @@ if (!req.url) | ||
await res.end(); | ||
await server.fullClose(); | ||
if (req.url.includes('?code')) | ||
r(req.url.split('?code=')[1]); | ||
await server.fullClose(true); | ||
if (req.url.includes('?code')) { | ||
let code = req.url.split('?code=')[1]; | ||
if (serverConfig.oncode) { | ||
serverConfig.oncode(code); | ||
} | ||
r(code); | ||
} | ||
if (req.url.includes('?error')) { | ||
@@ -74,3 +97,3 @@ const error = req.url.split('?error=')[1].split('&')[0]; | ||
case '/close': | ||
await server.fullClose(); | ||
await server.fullClose(false); | ||
j(undefined); | ||
@@ -100,3 +123,3 @@ break; | ||
const server = await createServer(serverConfig); | ||
return _listenForCode(server, serverConfig); | ||
return await _listenForCode(server, serverConfig); | ||
} | ||
@@ -103,0 +126,0 @@ exports.listenForCode = listenForCode; |
@@ -13,2 +13,5 @@ export type MSConfigType = { | ||
timeout: number; | ||
onstart?: (host: string, port: number) => any; | ||
onclose?: (success: boolean) => any; | ||
oncode?: (code: string) => any; | ||
}; | ||
@@ -15,0 +18,0 @@ export type TokenResponse = { |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import http from "http"; | ||
export type ListeningHttpServer = http.Server & { | ||
fullClose: () => any; | ||
fullClose: (success: boolean) => any; | ||
serverTimeout?: NodeJS.Timeout; | ||
}; | ||
@@ -6,0 +8,0 @@ export type AccountType = "mojang" | "cracked" | "microsoft" | "token"; |
{ | ||
"name": "minecraft-auth", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Package to authenticate with minecraft using traditional yggdrasil, new microsoft authentication and non-premium.", | ||
@@ -40,3 +40,3 @@ "main": "dist/index.js", | ||
"@types/jest": "^29.5.5", | ||
"@types/node": "^17.0.45", | ||
"@types/node": "^20.8.3", | ||
"jest": "^29.7.0", | ||
@@ -43,0 +43,0 @@ "jest-mock": "^29.7.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
72294
1135