minecraft-auth
Advanced tools
Comparing version 1.0.34 to 2.0.0
@@ -1,305 +0,7 @@ | ||
/// <reference types="node" /> | ||
import * as http from "http"; | ||
export declare type ListeningHttpServer = http.Server & { | ||
fullClose: any; | ||
}; | ||
export declare type AccountType = "mojang" | "cracked" | "microsoft" | "token"; | ||
export declare module MicrosoftAuth { | ||
let appID: any; | ||
let appSecret: any; | ||
let redirectURL: any; | ||
let scope: string; | ||
function setup(_appID: any, _appSecret: any, _redirectURL: any): void; | ||
function _createServer(port: number): Promise<ListeningHttpServer>; | ||
function _listenForCode(server: ListeningHttpServer, timeout?: number): Promise<string>; | ||
function listenForCode(port: number, timeout?: number): Promise<string>; | ||
function onTokenResponse(): void; | ||
function createUrl(): string; | ||
function getToken(authCode: any): Promise<TokenResponse>; | ||
function getTokenRefresh(refreshToken: any): Promise<TokenResponse>; | ||
function authXBL(accessToken: any): Promise<XBLResponse>; | ||
function authXSTS(xblToken: any): Promise<XSTSResponse>; | ||
function getMinecraftToken(xstsToken: any, uhs: any): Promise<MCTokenResponse>; | ||
function authFlow(authCode: any): Promise<{ | ||
access_token: string; | ||
refresh_token: any; | ||
}>; | ||
function authFlowRefresh(refresh_token: any): Promise<{ | ||
access_token: string; | ||
refresh_token: any; | ||
}>; | ||
function authFlowXBL(token: any, refresh_token: any): Promise<{ | ||
access_token: string; | ||
refresh_token: any; | ||
}>; | ||
type TokenResponse = { | ||
"token_type": string; | ||
"expires_in": number; | ||
"scope": string; | ||
"access_token": string; | ||
"refresh_token": string; | ||
"user_id": string; | ||
"foci": string; | ||
error_description: string; | ||
error: string; | ||
correlation_id: string; | ||
}; | ||
type MCTokenResponse = { | ||
"username": string; | ||
"roles": []; | ||
"access_token": string; | ||
"token_type": string; | ||
"expires_in": 86400; | ||
}; | ||
type XBLResponse = { | ||
"IssueInstant": string; | ||
"NotAfter": string; | ||
"Token": string; | ||
"DisplayClaims": { | ||
"xui": [ | ||
{ | ||
"uhs": string; | ||
} | ||
]; | ||
}; | ||
}; | ||
type XSTSResponse = { | ||
"IssueInstant": string; | ||
"NotAfter": string; | ||
"Token": string; | ||
"DisplayClaims": { | ||
"xui": [ | ||
{ | ||
"uhs": string; | ||
} | ||
]; | ||
}; | ||
"Identity": string; | ||
"XErr": number; | ||
"Message": string; | ||
"Redirect": string; | ||
}; | ||
} | ||
export declare module MojangAuth { | ||
function authenticate(username: any, password: any, clientToken?: any): Promise<MCAuthResponse>; | ||
function refresh(accessToken: any, clientToken: any): Promise<MCAuthResponse>; | ||
function validateToken(token: any, alternativeValidation?: boolean): Promise<boolean>; | ||
function _validateToken(token: any): Promise<boolean>; | ||
function _validateTokenAlternative(token: any): Promise<boolean>; | ||
type MCAuthResponse = { | ||
"user": { | ||
"username": string; | ||
"properties": [ | ||
{ | ||
"name": string; | ||
"value": string; | ||
}, | ||
{ | ||
"name": string; | ||
"value": string; | ||
} | ||
]; | ||
"id": string; | ||
}; | ||
"clientToken": string; | ||
"accessToken": string; | ||
"availableProfiles": [ | ||
{ | ||
"name": string; | ||
"id": string; | ||
} | ||
]; | ||
"selectedProfile": { | ||
"name": string; | ||
"id": string; | ||
}; | ||
"error": string; | ||
"errorMessage": string; | ||
"cause": string; | ||
}; | ||
type MCErrorResponse = { | ||
"error": string; | ||
"errorMessage": string; | ||
"cause": string; | ||
}; | ||
} | ||
export declare module CrackedAuth { | ||
function uuid(username: any): string; | ||
} | ||
export declare module MojangAPI { | ||
function usernameToUUID(username: string): Promise<UsernameToUUIDResponse>; | ||
function nameHistory(uuid: string): Promise<NameHistoryResponse>; | ||
function getProfileByUUID(uuid: string): Promise<ProfileResponseDecoded>; | ||
function getBlockedServers(): Promise<string[]>; | ||
function nameChangeInfo(token: any): Promise<NameChangeInfoResponse>; | ||
function nameAvailability(name: string, token: any): Promise<boolean>; | ||
function changeSkin(url: any, variant: "classic" | "slim", token: any): Promise<void>; | ||
function resetSkin(uuid: any, token: any): Promise<void>; | ||
function checkOwnership(token: any, profileResp?: MCProfileResponse): Promise<boolean>; | ||
function getProfile(token: any): Promise<MCProfileResponse>; | ||
type MCOwnershipResponse = { | ||
"items": [ | ||
{ | ||
"name": string; | ||
"signature": string; | ||
}, | ||
{ | ||
"name": string; | ||
"signature": string; | ||
} | ||
]; | ||
"signature": string; | ||
"keyId": string; | ||
}; | ||
type MCProfileResponse = { | ||
"id": string; | ||
"name": string; | ||
"skins": [ | ||
{ | ||
"id": string; | ||
"state": string; | ||
"url": string; | ||
"variant": string; | ||
"alias": string; | ||
} | ||
]; | ||
"capes": []; | ||
}; | ||
type NameChangeInfoResponse = { | ||
"changedAt": string; | ||
"createdAt": string; | ||
"nameChangeAllowed": boolean; | ||
}; | ||
type NameAvailabilityResponse = { | ||
"status": "DUPLICATE" | "AVAILABLE"; | ||
}; | ||
type StatusResponse = [ | ||
{ | ||
"minecraft.net": StatusType; | ||
}, | ||
{ | ||
"session.minecraft.net": StatusType; | ||
}, | ||
{ | ||
"account.mojang.com": StatusType; | ||
}, | ||
{ | ||
"authserver.mojang.com": StatusType; | ||
}, | ||
{ | ||
"sessionserver.mojang.com": StatusType; | ||
}, | ||
{ | ||
"api.mojang.com": StatusType; | ||
}, | ||
{ | ||
"textures.minecraft.net": StatusType; | ||
}, | ||
{ | ||
"mojang.com": StatusType; | ||
} | ||
]; | ||
type StatusType = "green" | "red" | "yellow"; | ||
type UsernameToUUIDResponse = { | ||
"name": string; | ||
"id": string; | ||
}; | ||
type NameHistoryResponse = NameHistoryEntry[]; | ||
type NameHistoryEntry = { | ||
"name": string; | ||
"changedToAt": number; | ||
}; | ||
type ProfileResponse = { | ||
"id": string; | ||
"name": string; | ||
"properties": [ | ||
{ | ||
"name": string; | ||
"value": string; | ||
} | ||
]; | ||
}; | ||
type ProfileResponseDecoded = { | ||
"id": string; | ||
"name": string; | ||
"properties": [ | ||
{ | ||
"name": string; | ||
"value": DecodedTextures; | ||
} | ||
]; | ||
}; | ||
type DecodedTextures = { | ||
"timestamp": number; | ||
"profileId": string; | ||
"profileName": string; | ||
"signatureRequired": boolean; | ||
"textures": { | ||
"SKIN": { | ||
"url": string; | ||
}; | ||
"CAPE": { | ||
"url": string; | ||
}; | ||
}; | ||
}; | ||
} | ||
export declare class AuthenticationError extends Error { | ||
additionalInfo: string; | ||
constructor(_error: any, _message: any, _additionalInfo: any); | ||
} | ||
export declare class OwnershipError extends Error { | ||
constructor(_error: any); | ||
} | ||
export declare class Account { | ||
accessToken?: string; | ||
ownership: boolean; | ||
uuid: string; | ||
username: string; | ||
type: AccountType; | ||
profile: MojangAPI.MCProfileResponse; | ||
properties: any; | ||
alternativeValidation: boolean; | ||
constructor(token: string, type: AccountType); | ||
checkValidToken(): Promise<boolean>; | ||
checkOwnership(): Promise<boolean>; | ||
getProfile(): any; | ||
changeSkin(url: string, variant: "slim" | "classic"): Promise<boolean>; | ||
checkNameAvailability(name: string): Promise<boolean>; | ||
canChangeName(): Promise<boolean>; | ||
} | ||
export declare class MojangAccount extends Account { | ||
clientToken: string; | ||
login_username: string; | ||
login_password: string; | ||
constructor(); | ||
Login(username?: string, password?: string, saveCredentials?: any): Promise<string>; | ||
refresh(): Promise<string>; | ||
use(): Promise<string>; | ||
} | ||
export declare class MicrosoftAccount extends Account { | ||
refreshToken: string; | ||
authCode: string; | ||
constructor(); | ||
refresh(): Promise<string>; | ||
authFlow(authCode: any): Promise<string>; | ||
use(): Promise<string>; | ||
} | ||
export declare class CrackedAccount extends Account { | ||
constructor(username: any); | ||
setUsername(username: any): void; | ||
} | ||
export declare class AccountsStorage { | ||
accountList: Account[]; | ||
constructor(); | ||
getAccount(index: any): Account; | ||
getAccountByUUID(uuid: any): Account | undefined; | ||
getAccountByName(name: any): Account | undefined; | ||
addAccount(account: Account): void; | ||
deleteAccount(account: Account): void; | ||
serialize(): string; | ||
static deserialize(data: string): AccountsStorage; | ||
} | ||
export declare function HttpGet_BEARER(url: any, token: any, headers?: {}, objectResponse?: boolean): Promise<any>; | ||
export declare function HttpCustom_BEARER(method: any, url: any, token: any, body?: string, headers?: {}, objectResponse?: boolean): Promise<any>; | ||
export declare function HttpPost_BEARER(url: any, data: string, token: any, headers?: {}, objectResponse?: boolean): Promise<any>; | ||
export * as MicrosoftAuth from "./MicrosoftAuth/MicrosoftAuth"; | ||
export * as MojangAuth from "./MojangAuth/MojangAuth"; | ||
export * as CrackedAuth from "./CrackedAuth/CrackedAuth"; | ||
export * as MojangAPI from "./MojangAPI/MojangAPI"; | ||
export { MicrosoftAccount } from "./MicrosoftAuth/MicrosoftAccount"; | ||
export { CrackedAccount } from "./CrackedAuth/CrackedAccount"; | ||
export { MojangAccount } from "./MojangAuth/MojangAccount"; |
1122
dist/index.js
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
exports.HttpPost_BEARER = exports.HttpCustom_BEARER = exports.HttpGet_BEARER = exports.AccountsStorage = exports.CrackedAccount = exports.MicrosoftAccount = exports.MojangAccount = exports.Account = exports.OwnershipError = exports.AuthenticationError = exports.MojangAPI = exports.CrackedAuth = exports.MojangAuth = exports.MicrosoftAuth = void 0; | ||
var crypto_1 = __importDefault(require("crypto")); | ||
var atob_1 = __importDefault(require("atob")); | ||
var http_client_methods_1 = require("http-client-methods"); | ||
var MicrosoftAuth; | ||
(function (MicrosoftAuth) { | ||
MicrosoftAuth.scope = "XboxLive.signin offline_access"; | ||
var compiledID; | ||
var compiledScope; | ||
var compiledUrl; | ||
var compiledSecret; | ||
function setup(_appID, _appSecret, _redirectURL) { | ||
MicrosoftAuth.appID = _appID; | ||
MicrosoftAuth.appSecret = _appSecret; | ||
MicrosoftAuth.redirectURL = _redirectURL; | ||
compiledID = encodeURIComponent(MicrosoftAuth.appID); | ||
compiledScope = encodeURIComponent(MicrosoftAuth.scope); | ||
compiledUrl = encodeURIComponent(MicrosoftAuth.redirectURL); | ||
compiledSecret = encodeURIComponent(MicrosoftAuth.appSecret); | ||
} | ||
MicrosoftAuth.setup = setup; | ||
function _createServer(port) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var http, host, server; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
http = require("http"); | ||
host = 'localhost'; | ||
server = http.createServer(); | ||
return [4 /*yield*/, server.listen(port, host, function () { | ||
console.log("MS Token Server is running on http://".concat(host, ":").concat(port)); | ||
})]; | ||
case 1: | ||
_a.sent(); | ||
server.fullClose = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, server.close()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return [2 /*return*/, server]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth._createServer = _createServer; | ||
function _listenForCode(server, timeout) { | ||
if (timeout === void 0) { timeout = 60 * 1000; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, new Promise(function (r, j) { | ||
server.fullClose = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, server.close()]; | ||
case 1: | ||
_a.sent(); | ||
clearTimeout(_timeout); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
var _timeout = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, server.fullClose()]; | ||
case 1: | ||
_a.sent(); | ||
j(undefined); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }, timeout); | ||
var requestListener = function (req, res) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, error, error_description; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_a = req.url.split("?")[0]; | ||
switch (_a) { | ||
case "/token": return [3 /*break*/, 1]; | ||
case "/url": return [3 /*break*/, 5]; | ||
case "/close": return [3 /*break*/, 8]; | ||
case "/auth": return [3 /*break*/, 10]; | ||
} | ||
return [3 /*break*/, 11]; | ||
case 1: return [4 /*yield*/, res.writeHead(200)]; | ||
case 2: | ||
_b.sent(); | ||
return [4 /*yield*/, res.end()]; | ||
case 3: | ||
_b.sent(); | ||
return [4 /*yield*/, server.fullClose()]; | ||
case 4: | ||
_b.sent(); | ||
if (req.url.includes("?code")) | ||
r(req.url.split("?code=")[1]); | ||
if (req.url.includes("?error")) { | ||
error = req.url.split("?error=")[1].split("&")[0]; | ||
error_description = decodeURIComponent(req.url.split("&error_description=")[1]); | ||
j(new AuthenticationError(error, error_description, "")); | ||
} | ||
return [3 /*break*/, 11]; | ||
case 5: return [4 /*yield*/, res.writeHead(200)]; | ||
case 6: | ||
_b.sent(); | ||
return [4 /*yield*/, res.end(createUrl())]; | ||
case 7: | ||
_b.sent(); | ||
return [3 /*break*/, 11]; | ||
case 8: return [4 /*yield*/, server.fullClose()]; | ||
case 9: | ||
_b.sent(); | ||
j(undefined); | ||
return [3 /*break*/, 11]; | ||
case 10: | ||
res.writeHead(302, { | ||
'Location': createUrl() | ||
}); | ||
res.end(); | ||
return [3 /*break*/, 11]; | ||
case 11: return [4 /*yield*/, res.writeHead(404)]; | ||
case 12: | ||
_b.sent(); | ||
return [4 /*yield*/, res.end()]; | ||
case 13: | ||
_b.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
server.on("request", requestListener); | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth._listenForCode = _listenForCode; | ||
function listenForCode(port, timeout) { | ||
if (timeout === void 0) { timeout = 60 * 1000; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var server; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, _createServer(port)]; | ||
case 1: | ||
server = _a.sent(); | ||
return [2 /*return*/, _listenForCode(server, timeout)]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.listenForCode = listenForCode; | ||
function onTokenResponse() { | ||
} | ||
MicrosoftAuth.onTokenResponse = onTokenResponse; | ||
function createUrl() { | ||
return "https://login.live.com/oauth20_authorize.srf?client_id=".concat(compiledID, "&response_type=code&redirect_uri=").concat(compiledUrl, "&scope=").concat(compiledScope); | ||
} | ||
MicrosoftAuth.createUrl = createUrl; | ||
function getToken(authCode) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://login.live.com/oauth20_token.srf"; | ||
body = "client_id=".concat(compiledID, "&client_secret=").concat(compiledSecret, "&code=").concat(authCode, "&grant_type=authorization_code&redirect_uri=").concat(compiledUrl); | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)(url, body, { "Content-Type": "application/x-www-form-urlencoded" })]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
if (jsonResponse.error) { | ||
throw new AuthenticationError(jsonResponse.error, jsonResponse.error_description, jsonResponse.correlation_id); | ||
} | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.getToken = getToken; | ||
function getTokenRefresh(refreshToken) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://login.live.com/oauth20_token.srf"; | ||
body = "client_id=".concat(compiledID, "&client_secret=").concat(compiledSecret, "&refresh_token=").concat(refreshToken, "&grant_type=refresh_token&redirect_uri=").concat(compiledUrl); | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)(url, body, { "Content-Type": "application/x-www-form-urlencoded" })]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
if (jsonResponse.error) { | ||
throw new AuthenticationError(jsonResponse.error, jsonResponse.error_description, jsonResponse.correlation_id); | ||
} | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.getTokenRefresh = getTokenRefresh; | ||
function authXBL(accessToken) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = { | ||
"Properties": { | ||
"AuthMethod": "RPS", | ||
"SiteName": "user.auth.xboxlive.com", | ||
"RpsTicket": "d=".concat(accessToken) // your access token from step 2 here | ||
}, | ||
"RelyingParty": "http://auth.xboxlive.com", | ||
"TokenType": "JWT" | ||
}; | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)("https://user.auth.xboxlive.com/user/authenticate", JSON.stringify(body), { | ||
"Content-Type": "application/json", | ||
"Accept": "application/json" | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.authXBL = authXBL; | ||
function authXSTS(xblToken) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = { | ||
"Properties": { | ||
"SandboxId": "RETAIL", | ||
"UserTokens": [ | ||
"".concat(xblToken) | ||
] | ||
}, | ||
"RelyingParty": "rp://api.minecraftservices.com/", | ||
"TokenType": "JWT" | ||
}; | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)("https://xsts.auth.xboxlive.com/xsts/authorize", JSON.stringify(body), { | ||
"Content-Type": "application/json", | ||
"Accept": "application/json" | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
if (jsonResponse.XErr) { | ||
throw new AuthenticationError(jsonResponse.XErr, jsonResponse.Message, jsonResponse.Redirect); | ||
} | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.authXSTS = authXSTS; | ||
function getMinecraftToken(xstsToken, uhs) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = { | ||
"identityToken": "XBL3.0 x=".concat(uhs, ";").concat(xstsToken) | ||
}; | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)("https://api.minecraftservices.com/authentication/login_with_xbox", JSON.stringify(body), { | ||
"Content-Type": "application/json", | ||
"Accept": "application/json" | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.getMinecraftToken = getMinecraftToken; | ||
function authFlow(authCode) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tokenRes; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, getToken(authCode)]; | ||
case 1: | ||
tokenRes = _a.sent(); | ||
return [4 /*yield*/, authFlowXBL(tokenRes.access_token, tokenRes.refresh_token)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.authFlow = authFlow; | ||
function authFlowRefresh(refresh_token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tokenRes; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, getTokenRefresh(refresh_token)]; | ||
case 1: | ||
tokenRes = _a.sent(); | ||
return [4 /*yield*/, authFlowXBL(tokenRes.access_token, tokenRes.refresh_token)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.authFlowRefresh = authFlowRefresh; | ||
function authFlowXBL(token, refresh_token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var xblRes, xstsRes, mcToken; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, authXBL(token)]; | ||
case 1: | ||
xblRes = _a.sent(); | ||
return [4 /*yield*/, authXSTS(xblRes.Token)]; | ||
case 2: | ||
xstsRes = _a.sent(); | ||
return [4 /*yield*/, getMinecraftToken(xstsRes.Token, xblRes.DisplayClaims.xui[0].uhs)]; | ||
case 3: | ||
mcToken = _a.sent(); | ||
return [2 /*return*/, { access_token: mcToken.access_token, refresh_token: refresh_token }]; | ||
} | ||
}); | ||
}); | ||
} | ||
MicrosoftAuth.authFlowXBL = authFlowXBL; | ||
})(MicrosoftAuth = exports.MicrosoftAuth || (exports.MicrosoftAuth = {})); | ||
var MojangAuth; | ||
(function (MojangAuth) { | ||
var authUrl = "https://authserver.mojang.com"; | ||
function authenticate(username, password, clientToken) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = authUrl + "/authenticate"; | ||
body = { | ||
"agent": { | ||
"name": "Minecraft", | ||
"version": 1 | ||
}, | ||
"username": "".concat(username), | ||
"password": "".concat(password), | ||
"requestUser": true | ||
}; | ||
if (clientToken) { | ||
body.clientToken = clientToken; | ||
} | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)(url, JSON.stringify(body), { "Content-Type": "application/json" })]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
if (jsonResponse.error) { | ||
throw new AuthenticationError(jsonResponse.error, jsonResponse.errorMessage, jsonResponse.cause); | ||
} | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAuth.authenticate = authenticate; | ||
function refresh(accessToken, clientToken) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = authUrl + "/refresh"; | ||
body = { | ||
"accessToken": "".concat(accessToken), | ||
"clientToken": "".concat(clientToken), | ||
"requestUser": true | ||
}; | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)(url, JSON.stringify(body), { "Content-Type": "application/json" })]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
if (jsonResponse.error) { | ||
throw new AuthenticationError(jsonResponse.error, jsonResponse.errorMessage, jsonResponse.cause); | ||
} | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAuth.refresh = refresh; | ||
function validateToken(token, alternativeValidation) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!!alternativeValidation) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, _validateToken(token)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: return [4 /*yield*/, _validateTokenAlternative(token)]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAuth.validateToken = validateToken; | ||
function _validateToken(token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, body, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = authUrl + "/validate"; | ||
body = { | ||
"accessToken": "".concat(token) | ||
}; | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpPost)(url, JSON.stringify(body), { "Content-Type": "application/json" })]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.length < 1) | ||
return [2 /*return*/, true]; | ||
jsonResponse = JSON.parse(response); | ||
if (jsonResponse.error) { | ||
return [2 /*return*/, false]; | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAuth._validateToken = _validateToken; | ||
function _validateTokenAlternative(token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var res; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, HttpGet_BEARER("https://api.minecraftservices.com/minecraft/profile", token, {}, true)]; | ||
case 1: | ||
res = _a.sent(); | ||
return [2 /*return*/, res.status != 401 && res.status != 403]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAuth._validateTokenAlternative = _validateTokenAlternative; | ||
})(MojangAuth = exports.MojangAuth || (exports.MojangAuth = {})); | ||
var CrackedAuth; | ||
(function (CrackedAuth) { | ||
function uuid(username) { | ||
var md5Bytes = crypto_1["default"].createHash('md5').update(username).digest(); | ||
md5Bytes[6] &= 0x0f; | ||
md5Bytes[6] |= 0x30; | ||
md5Bytes[8] &= 0x3f; | ||
md5Bytes[8] |= 0x80; | ||
return md5Bytes.toString('hex'); | ||
} | ||
CrackedAuth.uuid = uuid; | ||
})(CrackedAuth = exports.CrackedAuth || (exports.CrackedAuth = {})); | ||
var MojangAPI; | ||
(function (MojangAPI) { | ||
function usernameToUUID(username) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://api.mojang.com/users/profiles/minecraft/".concat(username); | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpGet)(url)]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.usernameToUUID = usernameToUUID; | ||
function nameHistory(uuid) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://api.mojang.com/user/profiles/".concat(uuid, "/names"); | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpGet)(url)]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.nameHistory = nameHistory; | ||
function getProfileByUUID(uuid) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response, jsonResponseEncoded, decodedValue, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://sessionserver.mojang.com/session/minecraft/profile/".concat(uuid); | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpGet)(url)]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponseEncoded = JSON.parse(response); | ||
decodedValue = JSON.parse((0, atob_1["default"])(jsonResponseEncoded.properties[0].value)); | ||
jsonResponse = jsonResponseEncoded; | ||
jsonResponse.properties[0].value = decodedValue; | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.getProfileByUUID = getProfileByUUID; | ||
function getBlockedServers() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://sessionserver.mojang.com/blockedservers"; | ||
return [4 /*yield*/, (0, http_client_methods_1.HttpGet)(url)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response.split('\n')]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.getBlockedServers = getBlockedServers; | ||
function nameChangeInfo(token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://api.minecraftservices.com/minecraft/profile/namechange"; | ||
return [4 /*yield*/, HttpGet_BEARER(url, token)]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.nameChangeInfo = nameChangeInfo; | ||
function nameAvailability(name, token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://api.minecraftservices.com/minecraft/profile/name/".concat(name, "/available"); | ||
return [4 /*yield*/, HttpGet_BEARER(url, token)]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
return [2 /*return*/, jsonResponse.status == "AVAILABLE"]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.nameAvailability = nameAvailability; | ||
function changeSkin(url, variant, token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var body, Rurl, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = { | ||
"variant": variant, | ||
"url": url | ||
}; | ||
Rurl = "https://api.minecraftservices.com/minecraft/profile/skins"; | ||
return [4 /*yield*/, HttpPost_BEARER(Rurl, JSON.stringify(body), token, { "Content-Type": "application/json" })]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.length > 0) | ||
throw response; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.changeSkin = changeSkin; | ||
function resetSkin(uuid, token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "https://api.mojang.com/user/profile/".concat(uuid, "/skin"); | ||
return [4 /*yield*/, HttpCustom_BEARER("delete", url, token)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.length > 0) | ||
throw response; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.resetSkin = resetSkin; | ||
function checkOwnership(token, profileResp) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!!profileResp) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, getProfile(token)]; | ||
case 1: | ||
profileResp = _a.sent(); | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, !!profileResp.id]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.checkOwnership = checkOwnership; | ||
function getProfile(token) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, jsonResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, HttpGet_BEARER("https://api.minecraftservices.com/minecraft/profile", token)]; | ||
case 1: | ||
response = _a.sent(); | ||
jsonResponse = JSON.parse(response); | ||
return [2 /*return*/, jsonResponse]; | ||
} | ||
}); | ||
}); | ||
} | ||
MojangAPI.getProfile = getProfile; | ||
})(MojangAPI = exports.MojangAPI || (exports.MojangAPI = {})); | ||
var AuthenticationError = /** @class */ (function (_super) { | ||
__extends(AuthenticationError, _super); | ||
function AuthenticationError(_error, _message, _additionalInfo) { | ||
var _this = _super.call(this, _message) || this; | ||
_this.name = _error; | ||
_this.additionalInfo = _additionalInfo; | ||
return _this; | ||
} | ||
return AuthenticationError; | ||
}(Error)); | ||
exports.AuthenticationError = AuthenticationError; | ||
var OwnershipError = /** @class */ (function (_super) { | ||
__extends(OwnershipError, _super); | ||
function OwnershipError(_error) { | ||
return _super.call(this, _error) || this; | ||
} | ||
return OwnershipError; | ||
}(Error)); | ||
exports.OwnershipError = OwnershipError; | ||
var Account = /** @class */ (function () { | ||
function Account(token, type) { | ||
this.properties = {}; | ||
this.accessToken = token; | ||
this.type = type; | ||
} | ||
Account.prototype.checkValidToken = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.accessToken) | ||
return [2 /*return*/, false]; | ||
return [4 /*yield*/, MojangAuth.validateToken(this.accessToken, this.alternativeValidation)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Account.prototype.checkOwnership = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!this.accessToken) | ||
return [2 /*return*/, false]; | ||
_a = this; | ||
return [4 /*yield*/, MojangAPI.checkOwnership(this.accessToken)]; | ||
case 1: | ||
_a.ownership = _b.sent(); | ||
return [2 /*return*/, this.ownership]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Account.prototype.getProfile = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var profile; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.accessToken) | ||
return [2 /*return*/, undefined]; | ||
if (!!this.ownership) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.checkOwnership()]; | ||
case 1: | ||
_a.sent(); | ||
if (!this.ownership) | ||
throw new OwnershipError("User don't have minecraft on his account!"); | ||
return [2 /*return*/, this.getProfile()]; | ||
case 2: return [4 /*yield*/, MojangAPI.getProfile(this.accessToken)]; | ||
case 3: | ||
profile = _a.sent(); | ||
this.username = profile.name; | ||
this.uuid = profile.id; | ||
this.profile = profile; | ||
return [2 /*return*/, profile]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Account.prototype.changeSkin = function (url, variant) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.accessToken) | ||
return [2 /*return*/]; | ||
return [4 /*yield*/, MojangAPI.changeSkin(url, variant, this.accessToken)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, true]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Account.prototype.checkNameAvailability = function (name) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.accessToken) | ||
return [2 /*return*/, false]; | ||
return [4 /*yield*/, MojangAPI.nameAvailability(name, this.accessToken)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Account.prototype.canChangeName = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.accessToken) | ||
return [2 /*return*/, false]; | ||
return [4 /*yield*/, MojangAPI.nameChangeInfo(this.accessToken)]; | ||
case 1: return [2 /*return*/, (_a.sent()).nameChangeAllowed]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return Account; | ||
}()); | ||
exports.Account = Account; | ||
var MojangAccount = /** @class */ (function (_super) { | ||
__extends(MojangAccount, _super); | ||
function MojangAccount() { | ||
return _super.call(this, undefined, "mojang") || this; | ||
} | ||
MojangAccount.prototype.Login = function (username, password, saveCredentials) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var resp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!username) | ||
username = this.login_username; | ||
if (!password) | ||
password = this.login_password; | ||
if (!username || !password) | ||
throw new AuthenticationError("Username or password not provided", "Username or password not provided", ""); | ||
return [4 /*yield*/, MojangAuth.authenticate(username, password)]; | ||
case 1: | ||
resp = _a.sent(); | ||
this.clientToken = resp.clientToken; | ||
this.accessToken = resp.accessToken; | ||
this.login_username = undefined; | ||
this.login_password = undefined; | ||
if (saveCredentials) { | ||
this.login_username = username; | ||
this.login_password = password; | ||
} | ||
return [2 /*return*/, this.accessToken]; | ||
} | ||
}); | ||
}); | ||
}; | ||
MojangAccount.prototype.refresh = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var resp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, MojangAuth.refresh(this.accessToken, this.clientToken)]; | ||
case 1: | ||
resp = _a.sent(); | ||
this.clientToken = resp.clientToken; | ||
this.accessToken = resp.accessToken; | ||
return [2 /*return*/, this.accessToken]; | ||
} | ||
}); | ||
}); | ||
}; | ||
MojangAccount.prototype.use = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.checkValidToken()]; | ||
case 1: | ||
if (!_a.sent()) return [3 /*break*/, 2]; | ||
return [2 /*return*/, this.accessToken]; | ||
case 2: | ||
if (!(this.login_username && this.login_password)) return [3 /*break*/, 8]; | ||
_a.label = 3; | ||
case 3: | ||
_a.trys.push([3, 5, , 7]); | ||
return [4 /*yield*/, this.refresh()]; | ||
case 4: | ||
_a.sent(); | ||
return [2 /*return*/, this.accessToken]; | ||
case 5: | ||
e_1 = _a.sent(); | ||
return [4 /*yield*/, this.Login()]; | ||
case 6: | ||
_a.sent(); | ||
return [2 /*return*/, this.accessToken]; | ||
case 7: return [3 /*break*/, 10]; | ||
case 8: return [4 /*yield*/, this.refresh()]; | ||
case 9: | ||
_a.sent(); | ||
return [2 /*return*/, this.accessToken]; | ||
case 10: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return MojangAccount; | ||
}(Account)); | ||
exports.MojangAccount = MojangAccount; | ||
var MicrosoftAccount = /** @class */ (function (_super) { | ||
__extends(MicrosoftAccount, _super); | ||
function MicrosoftAccount() { | ||
var _this = _super.call(this, undefined, "microsoft") || this; | ||
_this.alternativeValidation = true; | ||
return _this; | ||
} | ||
MicrosoftAccount.prototype.refresh = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var resp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, MicrosoftAuth.authFlowRefresh(this.refreshToken)]; | ||
case 1: | ||
resp = _a.sent(); | ||
this.refreshToken = resp.refresh_token; | ||
this.accessToken = resp.access_token; | ||
return [2 /*return*/, this.accessToken]; | ||
} | ||
}); | ||
}); | ||
}; | ||
MicrosoftAccount.prototype.authFlow = function (authCode) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var resp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.authCode = authCode; | ||
return [4 /*yield*/, MicrosoftAuth.authFlow(this.authCode)]; | ||
case 1: | ||
resp = _a.sent(); | ||
this.refreshToken = resp.refresh_token; | ||
this.accessToken = resp.access_token; | ||
return [2 /*return*/, this.accessToken]; | ||
} | ||
}); | ||
}); | ||
}; | ||
MicrosoftAccount.prototype.use = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.checkValidToken()]; | ||
case 1: | ||
if (!_a.sent()) return [3 /*break*/, 2]; | ||
return [2 /*return*/, this.accessToken]; | ||
case 2: return [4 /*yield*/, this.refresh()]; | ||
case 3: | ||
_a.sent(); | ||
return [2 /*return*/, this.accessToken]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return MicrosoftAccount; | ||
}(Account)); | ||
exports.MicrosoftAccount = MicrosoftAccount; | ||
var CrackedAccount = /** @class */ (function (_super) { | ||
__extends(CrackedAccount, _super); | ||
function CrackedAccount(username) { | ||
var _this = _super.call(this, undefined, "cracked") || this; | ||
_this.ownership = false; | ||
_this.setUsername(username); | ||
return _this; | ||
} | ||
CrackedAccount.prototype.setUsername = function (username) { | ||
if (!username) | ||
return; | ||
this.username = username; | ||
this.uuid = CrackedAuth.uuid(username); | ||
}; | ||
return CrackedAccount; | ||
}(Account)); | ||
exports.CrackedAccount = CrackedAccount; | ||
var AccountsStorage = /** @class */ (function () { | ||
function AccountsStorage() { | ||
this.accountList = []; | ||
} | ||
AccountsStorage.prototype.getAccount = function (index) { | ||
return this.accountList[index]; | ||
}; | ||
AccountsStorage.prototype.getAccountByUUID = function (uuid) { | ||
var acc = undefined; | ||
this.accountList.forEach(function (el) { | ||
if (el.uuid === uuid) { | ||
acc = el; | ||
} | ||
}); | ||
return acc; | ||
}; | ||
AccountsStorage.prototype.getAccountByName = function (name) { | ||
var acc = undefined; | ||
this.accountList.forEach(function (el) { | ||
if (el.username === name) { | ||
acc = el; | ||
} | ||
}); | ||
return acc; | ||
}; | ||
AccountsStorage.prototype.addAccount = function (account) { | ||
this.accountList.push(account); | ||
}; | ||
AccountsStorage.prototype.deleteAccount = function (account) { | ||
for (var i = 0; i < this.accountList.length; i++) { | ||
if (this.accountList[i] === account) { | ||
this.accountList.splice(i, 1); | ||
i--; | ||
} | ||
} | ||
}; | ||
AccountsStorage.prototype.serialize = function () { | ||
return JSON.stringify(this.accountList); | ||
}; | ||
AccountsStorage.deserialize = function (data) { | ||
var accounts = JSON.parse(data); | ||
var accStorage = new AccountsStorage(); | ||
accounts.forEach(function (account) { | ||
if (account.type == "microsoft") { | ||
accStorage.addAccount(Object.setPrototypeOf(account, MicrosoftAccount.prototype)); | ||
} | ||
else if (account.type == "mojang") { | ||
accStorage.addAccount(Object.setPrototypeOf(account, MojangAccount.prototype)); | ||
} | ||
else if (account.type == "cracked") { | ||
accStorage.addAccount(Object.setPrototypeOf(account, CrackedAccount.prototype)); | ||
} | ||
else { | ||
accStorage.addAccount(Object.setPrototypeOf(account, Account.prototype)); | ||
} | ||
}); | ||
return accStorage; | ||
}; | ||
return AccountsStorage; | ||
}()); | ||
exports.AccountsStorage = AccountsStorage; | ||
function HttpGet_BEARER(url, token, headers, objectResponse) { | ||
if (objectResponse === void 0) { objectResponse = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, HttpCustom_BEARER("get", url, token, undefined, headers, objectResponse)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.HttpGet_BEARER = HttpGet_BEARER; | ||
function HttpCustom_BEARER(method, url, token, body, headers, objectResponse) { | ||
if (objectResponse === void 0) { objectResponse = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (!headers) | ||
headers = {}; | ||
headers["Authorization"] = "Bearer ".concat(token); | ||
return [2 /*return*/, (0, http_client_methods_1.HttpCustom)(method, url, body, headers, objectResponse)]; | ||
}); | ||
}); | ||
} | ||
exports.HttpCustom_BEARER = HttpCustom_BEARER; | ||
function HttpPost_BEARER(url, data, token, headers, objectResponse) { | ||
if (objectResponse === void 0) { objectResponse = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, HttpCustom_BEARER("post", url, token, data, headers, objectResponse)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.HttpPost_BEARER = HttpPost_BEARER; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MojangAccount = exports.CrackedAccount = exports.MicrosoftAccount = exports.MojangAPI = exports.CrackedAuth = exports.MojangAuth = exports.MicrosoftAuth = void 0; | ||
exports.MicrosoftAuth = __importStar(require("./MicrosoftAuth/MicrosoftAuth")); | ||
exports.MojangAuth = __importStar(require("./MojangAuth/MojangAuth")); | ||
exports.CrackedAuth = __importStar(require("./CrackedAuth/CrackedAuth")); | ||
exports.MojangAPI = __importStar(require("./MojangAPI/MojangAPI")); | ||
var MicrosoftAccount_1 = require("./MicrosoftAuth/MicrosoftAccount"); | ||
Object.defineProperty(exports, "MicrosoftAccount", { enumerable: true, get: function () { return MicrosoftAccount_1.MicrosoftAccount; } }); | ||
var CrackedAccount_1 = require("./CrackedAuth/CrackedAccount"); | ||
Object.defineProperty(exports, "CrackedAccount", { enumerable: true, get: function () { return CrackedAccount_1.CrackedAccount; } }); | ||
var MojangAccount_1 = require("./MojangAuth/MojangAccount"); | ||
Object.defineProperty(exports, "MojangAccount", { enumerable: true, get: function () { return MojangAccount_1.MojangAccount; } }); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "minecraft-auth", | ||
"version": "1.0.34", | ||
"version": "2.0.0", | ||
"description": "Package to authenticate with minecraft using traditional yggdrasil, new microsoft authentication and non-premium.", | ||
@@ -38,9 +38,11 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@tsconfig/node16": "^1.0.3", | ||
"@types/atob": "^2.1.2", | ||
"@types/jest": "^27.4.1", | ||
"jest": "^27.5.1", | ||
"jest-mock": "^27.5.1", | ||
"nodemon": "^2.0.15", | ||
"ts-jest": "^27.1.3", | ||
"jest-mock": "^27.5.1", | ||
"typescript": "^4.6.2" | ||
} | ||
} |
@@ -11,3 +11,4 @@ # Minecraft-auth package | ||
* Mojang Authentication - standard mojang authentication using username and password | ||
* Microsoft Authentication - new Microsoft oauth authentication to login to new accounts / migrated to microsoft | ||
* Microsoft Authentication - new Microsoft oauth authentication to login to new accounts / migrated to microsoft. | ||
Read how to setup it [here](https://github.com/dommilosz/minecraft-auth/wiki/How-to-setup-Microsoft-Auth) | ||
* Cracked Authentication - non premium offline mode authentication. Requires only username. | ||
@@ -19,4 +20,6 @@ | ||
### Deprecation Notice: | ||
Usage of lowercase classes like `mojangAccount` should be converted to use uppercase equivalents like `MojangAccount`. Usage of lowercase classes may be removed in the future. Currently, it only shows warning about the deprecation. | ||
### 2.0.0 migration | ||
Version 2.0.0 changes how Microsoft Authentication works. | ||
* Azure application should be registered with `Mobile and desktop applications` type | ||
* parameters in Setup and listenForCode functions changed | ||
@@ -27,8 +30,17 @@ ### Error handling: | ||
### Installation: | ||
```shell | ||
npm i --save minecraft-auth | ||
``` | ||
Importing: | ||
```javascript | ||
import * as minecraftAuth from "./src/index"; | ||
//or | ||
const minecraftAuth = require("./src/index.ts"); | ||
``` | ||
### Authentication Examples: | ||
* Mojang Authentication: | ||
```javascript | ||
var minecraftAuth = require("minecraft-auth") | ||
let account = new minecraftAuth.MojangAccount(); | ||
await account.Login("email","password"); | ||
@@ -39,14 +51,8 @@ ``` | ||
```javascript | ||
var minecraftAuth = require("minecraft-auth") | ||
const MicrosoftAuth = minecraftAuth.MicrosoftAuth; | ||
let account = new minecraftAuth.MicrosoftAccount(); | ||
MicrosoftAuth.setup({appID:"747bf062-ab9c-4690-842d-a77d18d4cf82"}); | ||
let code = await MicrosoftAuth.listenForCode(); | ||
let appID = "app id"; | ||
let appSecret = "app secret"; | ||
let redirectURL = "http://localhost:8080/token"; | ||
minecraftAuth.MicrosoftAuth.setup(appID, appSecret, redirectURL); | ||
console.log(minecraftAuth.MicrosoftAuth.createUrl()); | ||
let code = await MicrosoftAuth.listenForCode(8080); | ||
if(code !== undefined){ | ||
@@ -59,3 +65,2 @@ await account.authFlow(code); | ||
```javascript | ||
var minecraftAuth = require("minecraft-auth") | ||
let account = new minecraftAuth.CrackedAccount("username"); | ||
@@ -66,3 +71,3 @@ ``` | ||
```javascript | ||
await authenticate(); //function from above examples | ||
//any type of authentication eg. from above examples | ||
@@ -69,0 +74,0 @@ console.log(account.accessToken); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
47
91
68671
8
1084
6